fix(postgres): POS item price ignores NULL valid_from ordering on Postgres

get_items orders Item Price by valid_from and picks the first match. MariaDB sorts
NULL valid_from last under DESC (so a dated price wins); Postgres sorts it first,
so the undated base price wins and POS shows the wrong rate. Order by
(valid_from IS NULL) asc, valid_from desc so NULLs sort last on both backends
regardless of any real date value (MariaDB unchanged).
This commit is contained in:
Mihir Kandoi
2026-06-25 14:39:05 +05:30
parent da8ac36b92
commit b10cf2fb65

View File

@@ -231,6 +231,7 @@ def get_items(
.where(ItemPrice.selling == 1)
.where((ItemPrice.valid_from <= current_date) | (ItemPrice.valid_from.isnull()))
.where((ItemPrice.valid_upto >= current_date) | (ItemPrice.valid_upto.isnull()))
.orderby(ItemPrice.valid_from.isnull(), order=Order.asc)
.orderby(ItemPrice.valid_from, order=Order.desc)
).run(as_dict=True)