fix(partners): prevent duplicate PF partners on firstname/lastname swap

Customers often swap firstname/lastname in GoMag forms, causing duplicate
partner creation in Oracle. Fix with two layers:

- Python: sort PF name words alphabetically before Oracle lookup
- PL/SQL: add Step 2b permutation search (2-3 word names, PF only)
- Normalize name order to lastname+firstname across all Python files
- Add diagnostic SQL for finding existing reversed-name duplicates
- Add Oracle integration test for reverse-name matching

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-04-06 12:06:55 +00:00
parent 0992744490
commit fc1013bff6
6 changed files with 213 additions and 10 deletions

View File

@@ -244,14 +244,16 @@ def import_single_order(order, id_pol: int = None, id_sectie: int = None, app_se
is_pj = 1
else:
# Use shipping person for partner name (person on shipping label)
# Sort words alphabetically to normalize firstname/lastname swap
if order.shipping and (order.shipping.lastname or order.shipping.firstname):
denumire = clean_web_text(
raw_name = clean_web_text(
f"{order.shipping.lastname} {order.shipping.firstname}"
).upper()
else:
denumire = clean_web_text(
raw_name = clean_web_text(
f"{order.billing.lastname} {order.billing.firstname}"
).upper()
denumire = " ".join(sorted(raw_name.split()))
cod_fiscal = None
registru = None
is_pj = 0