fix(selling): tie-break POS customer contact pick for cross-engine parity

The contact lookup orders only by is_primary_contact desc then takes contacts[0]; contacts commonly
tie (the no-primary case), so MariaDB and Postgres could pick a different contact. Add a parent
(contact name) tiebreaker.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Mihir Kandoi
2026-07-01 09:10:19 +05:30
parent 7a798dcba9
commit 8f3eb6cb31

View File

@@ -464,6 +464,9 @@ def set_customer_info(fieldname: str, customer: str, value: str = ""):
& (DynamicLink.link_doctype == "Customer")
)
.orderby(Contact.is_primary_contact, order=Order.desc)
# tiebreaker: contacts tie on is_primary_contact (the common no-primary case) ->
# pick the same one on MariaDB and Postgres
.orderby(DynamicLink.parent, order=Order.asc)
)
contacts = query.run(pluck=DynamicLink.parent)