mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-11 13:41:47 +00:00
fix(postgres): get_item_price picks undated price on Postgres
Both Item Price lookups order by valid_from desc and take the first valid row. MariaDB sorts NULL valid_from last; Postgres first, so the undated base price was winning over a dated one. Order by (valid_from IS NULL) asc, valid_from desc (the get_all is converted to qb since its order_by won't take such an expression). MariaDB output is unchanged.
This commit is contained in:
@@ -1121,17 +1121,20 @@ def insert_item_price(ctx: ItemDetailsCtx):
|
||||
or getdate()
|
||||
)
|
||||
|
||||
item_prices = frappe.get_all(
|
||||
"Item Price",
|
||||
filters={
|
||||
"item_code": ctx.item_code,
|
||||
"price_list": ctx.price_list,
|
||||
"currency": ctx.currency,
|
||||
"uom": ctx.stock_uom,
|
||||
},
|
||||
fields=["name", "price_list_rate", "valid_from", "valid_upto"],
|
||||
order_by="valid_from desc, creation desc",
|
||||
)
|
||||
ip = frappe.qb.DocType("Item Price")
|
||||
item_prices = (
|
||||
frappe.qb.from_(ip)
|
||||
.select(ip.name, ip.price_list_rate, ip.valid_from, ip.valid_upto)
|
||||
.where(
|
||||
(ip.item_code == ctx.item_code)
|
||||
& (ip.price_list == ctx.price_list)
|
||||
& (ip.currency == ctx.currency)
|
||||
& (ip.uom == ctx.stock_uom)
|
||||
)
|
||||
.orderby(ip.valid_from.isnull(), order=frappe.qb.asc)
|
||||
.orderby(ip.valid_from, order=frappe.qb.desc)
|
||||
.orderby(ip.creation, order=frappe.qb.desc)
|
||||
).run(as_dict=True)
|
||||
item_price = next(
|
||||
(
|
||||
row
|
||||
@@ -1233,6 +1236,7 @@ def get_item_price(
|
||||
& (ip.price_list == pctx.price_list)
|
||||
& (IfNull(ip.uom, "").isin(["", pctx.uom]))
|
||||
)
|
||||
.orderby(ip.valid_from.isnull(), order=frappe.qb.asc)
|
||||
.orderby(ip.valid_from, order=frappe.qb.desc)
|
||||
.orderby(IfNull(ip.batch_no, ""), order=frappe.qb.desc)
|
||||
.orderby(ip.uom, order=frappe.qb.desc)
|
||||
|
||||
Reference in New Issue
Block a user