Fix Jasmin customer key and amount mapping
This commit is contained in:
@@ -221,7 +221,21 @@ def _looks_like_company_name(value: Any) -> bool:
|
||||
|
||||
def _external_customer_key(record: Dict[str, Any], *, source_system: str) -> str:
|
||||
if source_system == "jasmin":
|
||||
return _clean(_first(record, "partyKey", "customerPartyKey", "naturalKey", "key", "id"))
|
||||
# A document naturalKey identifies the commercial document
|
||||
# (for example ORC.ORC2026.136), not the customer. Prefer the
|
||||
# customer party code exposed by Jasmin and never fall back to the
|
||||
# document naturalKey when seeding/updating a fiscal customer.
|
||||
return _clean(
|
||||
_first(
|
||||
record,
|
||||
"partyKey",
|
||||
"customerPartyKey",
|
||||
"buyerCustomerParty",
|
||||
"accountingParty",
|
||||
"buyerCustomerPartyKey",
|
||||
"accountingPartyKey",
|
||||
)
|
||||
)
|
||||
if source_system == "odoo":
|
||||
return _clean(_first(record, "partner_external_id", "id"))
|
||||
return _clean(_first(record, "id", "key", "externalId"))
|
||||
@@ -355,7 +369,36 @@ def _jasmin_external_type(record: Dict[str, Any], default_type: str) -> str:
|
||||
|
||||
|
||||
def _jasmin_amount(record: Dict[str, Any]) -> Optional[str]:
|
||||
return _decimal_or_none(_first(record, "payableAmount", "totalAmount", "total", "grossAmount", "amount"))
|
||||
# Recent Jasmin payloads expose both flattened numeric fields and nested
|
||||
# money objects. Prefer the payable total including tax.
|
||||
direct = _first(
|
||||
record,
|
||||
"payableAmountAmount",
|
||||
"totalAmount",
|
||||
"grossValueAmount",
|
||||
"taxExclusiveAmountAmount",
|
||||
"total",
|
||||
"grossAmount",
|
||||
"amount",
|
||||
)
|
||||
if direct not in (None, ""):
|
||||
parsed = _decimal_or_none(direct)
|
||||
if parsed is not None:
|
||||
return parsed
|
||||
|
||||
for key in ("payableAmount", "grossValue", "taxExclusiveAmount"):
|
||||
money = record.get(key)
|
||||
if isinstance(money, dict):
|
||||
parsed = _decimal_or_none(
|
||||
_first(money, "amount", "baseAmount", "reportingAmount")
|
||||
)
|
||||
if parsed is not None:
|
||||
return parsed
|
||||
elif money not in (None, ""):
|
||||
parsed = _decimal_or_none(money)
|
||||
if parsed is not None:
|
||||
return parsed
|
||||
return None
|
||||
|
||||
|
||||
def _jasmin_candidate_from_record(record: Dict[str, Any], *, default_type: str) -> Optional[Dict[str, Any]]:
|
||||
|
||||
Reference in New Issue
Block a user