Spaces:
Running
Running
Update updated_word.py
Browse files- updated_word.py +55 -45
updated_word.py
CHANGED
|
@@ -599,7 +599,7 @@ def fix_management_summary_details_column(table, flat_json):
|
|
| 599 |
return replacements_made
|
| 600 |
|
| 601 |
def fix_operator_declaration_empty_values(table, flat_json):
|
| 602 |
-
"""Fix Operator Declaration table when values are empty"""
|
| 603 |
replacements_made = 0
|
| 604 |
|
| 605 |
print(f" π― FIX: Operator Declaration empty values processing")
|
|
@@ -638,67 +638,77 @@ def fix_operator_declaration_empty_values(table, flat_json):
|
|
| 638 |
|
| 639 |
print(f" π Current values: Name='{name_text}', Position='{position_text}'")
|
| 640 |
|
| 641 |
-
#
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
if
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
|
|
|
| 662 |
if has_red_text(name_cell):
|
| 663 |
cell_replacements = replace_red_text_in_cell(name_cell, name_replacement)
|
| 664 |
else:
|
|
|
|
| 665 |
name_cell.text = name_replacement
|
| 666 |
cell_replacements = 1
|
| 667 |
|
| 668 |
replacements_made += cell_replacements
|
| 669 |
-
print(f" β
|
|
|
|
|
|
|
|
|
|
| 670 |
break
|
| 671 |
|
| 672 |
-
#
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
|
|
|
| 687 |
if has_red_text(position_cell):
|
| 688 |
cell_replacements = replace_red_text_in_cell(position_cell, position_replacement)
|
| 689 |
else:
|
|
|
|
| 690 |
position_cell.text = position_replacement
|
| 691 |
cell_replacements = 1
|
| 692 |
|
| 693 |
replacements_made += cell_replacements
|
| 694 |
-
print(f" β
|
|
|
|
|
|
|
|
|
|
| 695 |
break
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
break
|
| 703 |
|
| 704 |
return replacements_made
|
|
|
|
| 599 |
return replacements_made
|
| 600 |
|
| 601 |
def fix_operator_declaration_empty_values(table, flat_json):
|
| 602 |
+
"""Fix Operator Declaration table when values are empty or need updating"""
|
| 603 |
replacements_made = 0
|
| 604 |
|
| 605 |
print(f" π― FIX: Operator Declaration empty values processing")
|
|
|
|
| 638 |
|
| 639 |
print(f" π Current values: Name='{name_text}', Position='{position_text}'")
|
| 640 |
|
| 641 |
+
# ALWAYS update Print Name with new data - check for red text OR existing data
|
| 642 |
+
print(f" π§ Updating Print Name")
|
| 643 |
+
|
| 644 |
+
# Try multiple sources for operator name
|
| 645 |
+
name_sources = [
|
| 646 |
+
"Operator Declaration.Print Name",
|
| 647 |
+
"Print Name",
|
| 648 |
+
"Operator name (Legal entity)",
|
| 649 |
+
"(print accreditation name)"
|
| 650 |
+
]
|
| 651 |
+
|
| 652 |
+
for source in name_sources:
|
| 653 |
+
name_value = find_matching_json_value(source, flat_json)
|
| 654 |
+
if name_value is not None:
|
| 655 |
+
name_replacement = get_value_as_string(name_value)
|
| 656 |
+
if name_replacement.strip():
|
| 657 |
+
# Extract just the name if it's a company name
|
| 658 |
+
if "Pty Ltd" in name_replacement or "Company" in name_replacement:
|
| 659 |
+
continue
|
| 660 |
+
|
| 661 |
+
# Check if we need to update (different from current)
|
| 662 |
+
if name_replacement.strip() != name_text:
|
| 663 |
if has_red_text(name_cell):
|
| 664 |
cell_replacements = replace_red_text_in_cell(name_cell, name_replacement)
|
| 665 |
else:
|
| 666 |
+
# Replace existing text
|
| 667 |
name_cell.text = name_replacement
|
| 668 |
cell_replacements = 1
|
| 669 |
|
| 670 |
replacements_made += cell_replacements
|
| 671 |
+
print(f" β
Updated Print Name: '{name_text}' -> '{name_replacement}' (from {source})")
|
| 672 |
+
break
|
| 673 |
+
else:
|
| 674 |
+
print(f" βΉοΈ Print Name already correct: '{name_replacement}'")
|
| 675 |
break
|
| 676 |
|
| 677 |
+
# ALWAYS update Position Title with new data
|
| 678 |
+
print(f" π§ Updating Position Title")
|
| 679 |
+
|
| 680 |
+
position_sources = [
|
| 681 |
+
"Operator Declaration.Position Title",
|
| 682 |
+
"Position Title"
|
| 683 |
+
]
|
| 684 |
+
|
| 685 |
+
for source in position_sources:
|
| 686 |
+
position_value = find_matching_json_value(source, flat_json)
|
| 687 |
+
if position_value is not None:
|
| 688 |
+
position_replacement = get_value_as_string(position_value)
|
| 689 |
+
if position_replacement.strip():
|
| 690 |
+
|
| 691 |
+
# Check if we need to update (different from current)
|
| 692 |
+
if position_replacement.strip() != position_text:
|
| 693 |
if has_red_text(position_cell):
|
| 694 |
cell_replacements = replace_red_text_in_cell(position_cell, position_replacement)
|
| 695 |
else:
|
| 696 |
+
# Replace existing text
|
| 697 |
position_cell.text = position_replacement
|
| 698 |
cell_replacements = 1
|
| 699 |
|
| 700 |
replacements_made += cell_replacements
|
| 701 |
+
print(f" β
Updated Position Title: '{position_text}' -> '{position_replacement}' (from {source})")
|
| 702 |
+
break
|
| 703 |
+
else:
|
| 704 |
+
print(f" βΉοΈ Position Title already correct: '{position_replacement}'")
|
| 705 |
break
|
| 706 |
+
|
| 707 |
+
# Fallback: use "Manager" if nothing found and cell is empty
|
| 708 |
+
if not position_text and not has_red_text(position_cell):
|
| 709 |
+
position_cell.text = "Manager"
|
| 710 |
+
replacements_made += 1
|
| 711 |
+
print(f" β
Used fallback Position Title: 'Manager'")
|
| 712 |
break
|
| 713 |
|
| 714 |
return replacements_made
|