fix: correct sorting while updating bin
This commit is contained in:
parent
d2882ea436
commit
b24920c0e9
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.query_builder import Case
|
from frappe.query_builder import Case, Order
|
||||||
from frappe.query_builder.functions import Coalesce, Sum
|
from frappe.query_builder.functions import Coalesce, CombineDatetime, Sum
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt
|
||||||
|
|
||||||
|
|
||||||
@ -121,24 +121,23 @@ def update_qty(bin_name, args):
|
|||||||
|
|
||||||
bin_details = get_bin_details(bin_name)
|
bin_details = get_bin_details(bin_name)
|
||||||
# actual qty is already updated by processing current voucher
|
# actual qty is already updated by processing current voucher
|
||||||
actual_qty = bin_details.actual_qty
|
actual_qty = bin_details.actual_qty or 0.0
|
||||||
|
sle = frappe.qb.DocType("Stock Ledger Entry")
|
||||||
|
|
||||||
# actual qty is not up to date in case of backdated transaction
|
# actual qty is not up to date in case of backdated transaction
|
||||||
if future_sle_exists(args):
|
if future_sle_exists(args):
|
||||||
actual_qty = (
|
last_sle_qty = (
|
||||||
frappe.db.get_value(
|
frappe.qb.from_(sle)
|
||||||
"Stock Ledger Entry",
|
.select(sle.qty_after_transaction)
|
||||||
filters={
|
.where((sle.item_code == args.get("item_code")) & (sle.warehouse == args.get("warehouse")))
|
||||||
"item_code": args.get("item_code"),
|
.orderby(CombineDatetime(sle.posting_date, sle.posting_time), order=Order.desc)
|
||||||
"warehouse": args.get("warehouse"),
|
.orderby(sle.creation, order=Order.desc)
|
||||||
"is_cancelled": 0,
|
.run()
|
||||||
},
|
|
||||||
fieldname="qty_after_transaction",
|
|
||||||
order_by="posting_date desc, posting_time desc, creation desc",
|
|
||||||
)
|
|
||||||
or 0.0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if last_sle_qty:
|
||||||
|
actual_qty = last_sle_qty[0][0]
|
||||||
|
|
||||||
ordered_qty = flt(bin_details.ordered_qty) + flt(args.get("ordered_qty"))
|
ordered_qty = flt(bin_details.ordered_qty) + flt(args.get("ordered_qty"))
|
||||||
reserved_qty = flt(bin_details.reserved_qty) + flt(args.get("reserved_qty"))
|
reserved_qty = flt(bin_details.reserved_qty) + flt(args.get("reserved_qty"))
|
||||||
indented_qty = flt(bin_details.indented_qty) + flt(args.get("indented_qty"))
|
indented_qty = flt(bin_details.indented_qty) + flt(args.get("indented_qty"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user