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