From cc872cfdad5b2c42fdee15e9aad07ba6fe5020ee Mon Sep 17 00:00:00 2001 From: Claude Agent Date: Mon, 16 Mar 2026 19:14:48 +0000 Subject: [PATCH] fix(sync): customer_name reflects invoice partner (company or shipping person) When billing is on a company, customer_name now uses billing.company_name instead of shipping person name. This aligns SQLite customer_name with the partner created in ROA by import_service, making order-invoice correlation possible in the dashboard. Co-Authored-By: Claude Opus 4.6 (1M context) --- api/app/services/sync_service.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/api/app/services/sync_service.py b/api/app/services/sync_service.py index 1c52892..c9ad4ca 100644 --- a/api/app/services/sync_service.py +++ b/api/app/services/sync_service.py @@ -78,14 +78,21 @@ async def prepare_sync(id_pol: int = None, id_sectie: int = None) -> dict: def _derive_customer_info(order): - """Extract shipping/billing names and customer from an order.""" + """Extract shipping/billing names and customer from an order. + customer = who appears on the invoice (partner in ROA): + - company name if billing is on a company + - shipping person name otherwise (consistent with import_service partner logic) + """ shipping_name = "" if order.shipping: shipping_name = f"{getattr(order.shipping, 'firstname', '') or ''} {getattr(order.shipping, 'lastname', '') or ''}".strip() billing_name = f"{getattr(order.billing, 'firstname', '') or ''} {getattr(order.billing, 'lastname', '') or ''}".strip() if not shipping_name: shipping_name = billing_name - customer = shipping_name or order.billing.company_name or billing_name + if order.billing.is_company and order.billing.company_name: + customer = order.billing.company_name + else: + customer = shipping_name or billing_name payment_method = getattr(order, 'payment_name', None) or None delivery_method = getattr(order, 'delivery_name', None) or None return shipping_name, billing_name, customer, payment_method, delivery_method @@ -251,8 +258,13 @@ async def run_sync(id_pol: int = None, id_sectie: int = None, run_id: str = None # Step 2c: Build SKU context from skipped orders sku_context = {} for order, missing_skus_list in skipped: - customer = order.billing.company_name or \ - f"{order.billing.firstname} {order.billing.lastname}" + if order.billing.is_company and order.billing.company_name: + customer = order.billing.company_name + else: + ship_name = "" + if order.shipping: + ship_name = f"{order.shipping.firstname} {order.shipping.lastname}".strip() + customer = ship_name or f"{order.billing.firstname} {order.billing.lastname}" for sku in missing_skus_list: if sku not in sku_context: sku_context[sku] = {"orders": [], "customers": []}