fix: valuation rate in stock ledger (#18744)
* fix: valuation rate in stock ledger * test: allow zero valuation rate for items
This commit is contained in:
parent
d5e5e22adb
commit
0df513434e
@ -701,6 +701,7 @@ def create_delivery_note(**args):
|
||||
"qty": args.qty or 1,
|
||||
"rate": args.rate or 100,
|
||||
"conversion_factor": 1.0,
|
||||
"allow_zero_valuation_rate": args.allow_zero_valuation_rate or 1,
|
||||
"expense_account": "Cost of Goods Sold - _TC",
|
||||
"cost_center": args.cost_center or "_Test Cost Center - _TC",
|
||||
"serial_no": args.serial_no,
|
||||
|
@ -464,16 +464,22 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no,
|
||||
|
||||
last_valuation_rate = frappe.db.sql("""select valuation_rate
|
||||
from `tabStock Ledger Entry`
|
||||
where item_code = %s and warehouse = %s
|
||||
and valuation_rate >= 0
|
||||
order by posting_date desc, posting_time desc, creation desc limit 1""", (item_code, warehouse))
|
||||
where
|
||||
item_code = %s
|
||||
AND warehouse = %s
|
||||
AND valuation_rate >= 0
|
||||
AND NOT (voucher_no = %s AND voucher_type = %s)
|
||||
order by posting_date desc, posting_time desc, name desc limit 1""", (item_code, warehouse, voucher_no, voucher_type))
|
||||
|
||||
if not last_valuation_rate:
|
||||
# Get valuation rate from last sle for the item against any warehouse
|
||||
last_valuation_rate = frappe.db.sql("""select valuation_rate
|
||||
from `tabStock Ledger Entry`
|
||||
where item_code = %s and valuation_rate > 0
|
||||
order by posting_date desc, posting_time desc, creation desc limit 1""", item_code)
|
||||
where
|
||||
item_code = %s
|
||||
AND valuation_rate > 0
|
||||
AND NOT(voucher_no = %s AND voucher_type = %s)
|
||||
order by posting_date desc, posting_time desc, name desc limit 1""", (item_code, voucher_no, voucher_type))
|
||||
|
||||
if last_valuation_rate:
|
||||
return flt(last_valuation_rate[0][0]) # as there is previous records, it might come with zero rate
|
||||
|
Loading…
x
Reference in New Issue
Block a user