mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 03:39:11 +00:00
fix: correct incoming rate for batched items
This commit is contained in:
committed by
Ankush Menat
parent
342d09a671
commit
ab926521bd
@@ -209,13 +209,28 @@ def _create_bin(item_code, warehouse):
|
||||
@frappe.whitelist()
|
||||
def get_incoming_rate(args, raise_error_if_no_rate=True):
|
||||
"""Get Incoming Rate based on valuation method"""
|
||||
from erpnext.stock.stock_ledger import get_previous_sle, get_valuation_rate
|
||||
from erpnext.stock.stock_ledger import (
|
||||
get_batch_incoming_rate,
|
||||
get_previous_sle,
|
||||
get_valuation_rate,
|
||||
)
|
||||
if isinstance(args, str):
|
||||
args = json.loads(args)
|
||||
|
||||
in_rate = 0
|
||||
voucher_no = args.get('voucher_no') or args.get('name')
|
||||
|
||||
in_rate = None
|
||||
if (args.get("serial_no") or "").strip():
|
||||
in_rate = get_avg_purchase_rate(args.get("serial_no"))
|
||||
elif args.get("batch_no") and \
|
||||
frappe.db.get_value("Batch", args.get("batch_no"), "use_batchwise_valuation", cache=True):
|
||||
in_rate = get_batch_incoming_rate(
|
||||
item_code=args.get('item_code'),
|
||||
warehouse=args.get('warehouse'),
|
||||
batch_no=args.get("batch_no"),
|
||||
posting_date=args.get("posting_date"),
|
||||
posting_time=args.get("posting_time"),
|
||||
)
|
||||
else:
|
||||
valuation_method = get_valuation_method(args.get("item_code"))
|
||||
previous_sle = get_previous_sle(args)
|
||||
@@ -226,8 +241,7 @@ def get_incoming_rate(args, raise_error_if_no_rate=True):
|
||||
elif valuation_method == 'Moving Average':
|
||||
in_rate = previous_sle.get('valuation_rate') or 0
|
||||
|
||||
if not in_rate:
|
||||
voucher_no = args.get('voucher_no') or args.get('name')
|
||||
if in_rate is None:
|
||||
in_rate = get_valuation_rate(args.get('item_code'), args.get('warehouse'),
|
||||
args.get('voucher_type'), voucher_no, args.get('allow_zero_valuation'),
|
||||
currency=erpnext.get_company_currency(args.get('company')), company=args.get('company'),
|
||||
|
||||
Reference in New Issue
Block a user