fix(regional): deterministic IRS-1099 payer-address pick across engines

get_payer_address_html picks one company address with ORDER BY (Postal DESC, Billing DESC)
LIMIT 1 and no column tie-break. When a company has two addresses of the same address_type
the two CASE keys tie, so the LIMIT-1 row is implementation-defined and MariaDB and PostgreSQL
can return a different address.name — i.e. a different payer address on the rendered IRS-1099
form for identical data.

Add a final .orderby(address.name), mirroring the sibling get_street_address_html in the same
file (which already carries the "deterministic LIMIT-1 tie-break across engines" order). The
pick is now the lexicographically-smallest name on both engines.
This commit is contained in:
Mihir Kandoi
2026-06-22 23:13:29 +05:30
parent f026d1dac8
commit fadad2d1c4

View File

@@ -131,6 +131,7 @@ def get_payer_address_html(company):
.where(address.is_your_company_address == 1)
.orderby(Case().when(address.address_type == "Postal", 1).else_(0), order=frappe.qb.desc)
.orderby(Case().when(address.address_type == "Billing", 1).else_(0), order=frappe.qb.desc)
.orderby(address.name) # deterministic LIMIT-1 tie-break across engines
.limit(1)
.run(as_dict=True)
)