mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 19:59:12 +00:00
fix: correct incoming rate for batched items
This commit is contained in:
committed by
Ankush Menat
parent
342d09a671
commit
ab926521bd
@@ -749,7 +749,7 @@ class update_entries_after(object):
|
|||||||
stock_value_difference = incoming_rate * actual_qty
|
stock_value_difference = incoming_rate * actual_qty
|
||||||
self.wh_data.stock_value += stock_value_difference
|
self.wh_data.stock_value += stock_value_difference
|
||||||
else:
|
else:
|
||||||
outgoing_rate = _get_batch_outgoing_rate(item_code=sle.item_code, warehouse=sle.warehouse, batch_no=sle.batch_no, posting_date=sle.posting_date, posting_time=sle.posting_time, creation=sle.creation)
|
outgoing_rate = get_batch_incoming_rate(item_code=sle.item_code, warehouse=sle.warehouse, batch_no=sle.batch_no, posting_date=sle.posting_date, posting_time=sle.posting_time, creation=sle.creation)
|
||||||
stock_value_difference = outgoing_rate * actual_qty
|
stock_value_difference = outgoing_rate * actual_qty
|
||||||
self.wh_data.stock_value += stock_value_difference
|
self.wh_data.stock_value += stock_value_difference
|
||||||
|
|
||||||
@@ -915,7 +915,7 @@ def get_sle_by_voucher_detail_no(voucher_detail_no, excluded_sle=None):
|
|||||||
['item_code', 'warehouse', 'posting_date', 'posting_time', 'timestamp(posting_date, posting_time) as timestamp'],
|
['item_code', 'warehouse', 'posting_date', 'posting_time', 'timestamp(posting_date, posting_time) as timestamp'],
|
||||||
as_dict=1)
|
as_dict=1)
|
||||||
|
|
||||||
def _get_batch_outgoing_rate(item_code, warehouse, batch_no, posting_date, posting_time, creation):
|
def get_batch_incoming_rate(item_code, warehouse, batch_no, posting_date, posting_time, creation=None):
|
||||||
|
|
||||||
batch_details = frappe.db.sql("""
|
batch_details = frappe.db.sql("""
|
||||||
select sum(stock_value_difference) as batch_value, sum(actual_qty) as batch_qty
|
select sum(stock_value_difference) as batch_value, sum(actual_qty) as batch_qty
|
||||||
@@ -948,7 +948,6 @@ def _get_batch_outgoing_rate(item_code, warehouse, batch_no, posting_date, posti
|
|||||||
return batch_details[0].batch_value / batch_details[0].batch_qty
|
return batch_details[0].batch_value / batch_details[0].batch_qty
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no,
|
def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no,
|
||||||
allow_zero_rate=False, currency=None, company=None, raise_error_if_no_rate=True, batch_no=None):
|
allow_zero_rate=False, currency=None, company=None, raise_error_if_no_rate=True, batch_no=None):
|
||||||
|
|
||||||
|
|||||||
@@ -209,13 +209,28 @@ def _create_bin(item_code, warehouse):
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_incoming_rate(args, raise_error_if_no_rate=True):
|
def get_incoming_rate(args, raise_error_if_no_rate=True):
|
||||||
"""Get Incoming Rate based on valuation method"""
|
"""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):
|
if isinstance(args, str):
|
||||||
args = json.loads(args)
|
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():
|
if (args.get("serial_no") or "").strip():
|
||||||
in_rate = get_avg_purchase_rate(args.get("serial_no"))
|
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:
|
else:
|
||||||
valuation_method = get_valuation_method(args.get("item_code"))
|
valuation_method = get_valuation_method(args.get("item_code"))
|
||||||
previous_sle = get_previous_sle(args)
|
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':
|
elif valuation_method == 'Moving Average':
|
||||||
in_rate = previous_sle.get('valuation_rate') or 0
|
in_rate = previous_sle.get('valuation_rate') or 0
|
||||||
|
|
||||||
if not in_rate:
|
if in_rate is None:
|
||||||
voucher_no = args.get('voucher_no') or args.get('name')
|
|
||||||
in_rate = get_valuation_rate(args.get('item_code'), args.get('warehouse'),
|
in_rate = get_valuation_rate(args.get('item_code'), args.get('warehouse'),
|
||||||
args.get('voucher_type'), voucher_no, args.get('allow_zero_valuation'),
|
args.get('voucher_type'), voucher_no, args.get('allow_zero_valuation'),
|
||||||
currency=erpnext.get_company_currency(args.get('company')), company=args.get('company'),
|
currency=erpnext.get_company_currency(args.get('company')), company=args.get('company'),
|
||||||
|
|||||||
Reference in New Issue
Block a user