Shami96 commited on
Commit
e95e088
Β·
verified Β·
1 Parent(s): c0e794c

Update updated_word.py

Browse files
Files changed (1) hide show
  1. 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
- # Fix Print Name if empty or has red text
642
- if not name_text or has_red_text(name_cell):
643
- print(f" πŸ”§ Fixing empty/red Print Name")
644
-
645
- # Try multiple sources for operator name
646
- name_sources = [
647
- "Operator Declaration.Print Name",
648
- "Print Name",
649
- "Operator name (Legal entity)",
650
- "(print accreditation name)"
651
- ]
652
-
653
- for source in name_sources:
654
- name_value = find_matching_json_value(source, flat_json)
655
- if name_value is not None:
656
- name_replacement = get_value_as_string(name_value)
657
- if name_replacement.strip():
658
- # Extract just the name if it's a company name
659
- if "Pty Ltd" in name_replacement or "Company" in name_replacement:
660
- continue
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" βœ… Fixed Print Name with: '{name_replacement}' (from {source})")
 
 
 
670
  break
671
 
672
- # Fix Position Title if empty or has red text
673
- if not position_text or has_red_text(position_cell):
674
- print(f" πŸ”§ Fixing empty/red Position Title")
675
-
676
- position_sources = [
677
- "Operator Declaration.Position Title",
678
- "Position Title"
679
- ]
680
-
681
- for source in position_sources:
682
- position_value = find_matching_json_value(source, flat_json)
683
- if position_value is not None:
684
- position_replacement = get_value_as_string(position_value)
685
- if position_replacement.strip():
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" βœ… Fixed Position Title with: '{position_replacement}' (from {source})")
 
 
 
695
  break
696
-
697
- # Fallback: use "Manager" if nothing found
698
- if not position_text and not has_red_text(position_cell):
699
- position_cell.text = "Manager"
700
- replacements_made += 1
701
- print(f" βœ… Used fallback Position Title: 'Manager'")
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