mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-17 09:17:15 +00:00
fix: valuation rate for backdated legacy serial/batches (#41788)
(cherry picked from commit 3956354e08)
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -36,6 +36,7 @@ from erpnext.stock.utils import (
|
|||||||
get_incoming_outgoing_rate_for_cancel,
|
get_incoming_outgoing_rate_for_cancel,
|
||||||
get_incoming_rate,
|
get_incoming_rate,
|
||||||
get_or_make_bin,
|
get_or_make_bin,
|
||||||
|
get_serial_nos_data,
|
||||||
get_stock_balance,
|
get_stock_balance,
|
||||||
get_valuation_method,
|
get_valuation_method,
|
||||||
)
|
)
|
||||||
@@ -811,9 +812,10 @@ class update_entries_after:
|
|||||||
self.update_outgoing_rate_on_transaction(sle)
|
self.update_outgoing_rate_on_transaction(sle)
|
||||||
|
|
||||||
def get_serialized_values(self, sle):
|
def get_serialized_values(self, sle):
|
||||||
|
from erpnext.stock.serial_batch_bundle import SerialNoValuation
|
||||||
|
|
||||||
incoming_rate = flt(sle.incoming_rate)
|
incoming_rate = flt(sle.incoming_rate)
|
||||||
actual_qty = flt(sle.actual_qty)
|
actual_qty = flt(sle.actual_qty)
|
||||||
serial_nos = cstr(sle.serial_no).split("\n")
|
|
||||||
|
|
||||||
if incoming_rate < 0:
|
if incoming_rate < 0:
|
||||||
# wrong incoming rate
|
# wrong incoming rate
|
||||||
@@ -826,7 +828,15 @@ class update_entries_after:
|
|||||||
# In case of delivery/stock issue, get average purchase rate
|
# In case of delivery/stock issue, get average purchase rate
|
||||||
# of serial nos of current entry
|
# of serial nos of current entry
|
||||||
if not sle.is_cancelled:
|
if not sle.is_cancelled:
|
||||||
outgoing_value = self.get_incoming_value_for_serial_nos(sle, serial_nos)
|
new_sle = copy.deepcopy(sle)
|
||||||
|
new_sle.qty = new_sle.actual_qty
|
||||||
|
new_sle.serial_nos = get_serial_nos_data(new_sle.get("serial_no"))
|
||||||
|
|
||||||
|
sn_obj = SerialNoValuation(
|
||||||
|
sle=new_sle, warehouse=new_sle.get("warehouse"), item_code=new_sle.get("item_code")
|
||||||
|
)
|
||||||
|
|
||||||
|
outgoing_value = sn_obj.get_incoming_rate()
|
||||||
stock_value_change = -1 * outgoing_value
|
stock_value_change = -1 * outgoing_value
|
||||||
else:
|
else:
|
||||||
stock_value_change = actual_qty * sle.outgoing_rate
|
stock_value_change = actual_qty * sle.outgoing_rate
|
||||||
@@ -1272,6 +1282,8 @@ class update_entries_after:
|
|||||||
self.wh_data.valuation_rate = self.wh_data.stock_value / self.wh_data.qty_after_transaction
|
self.wh_data.valuation_rate = self.wh_data.stock_value / self.wh_data.qty_after_transaction
|
||||||
|
|
||||||
def update_batched_values(self, sle):
|
def update_batched_values(self, sle):
|
||||||
|
from erpnext.stock.serial_batch_bundle import BatchNoValuation
|
||||||
|
|
||||||
incoming_rate = flt(sle.incoming_rate)
|
incoming_rate = flt(sle.incoming_rate)
|
||||||
actual_qty = flt(sle.actual_qty)
|
actual_qty = flt(sle.actual_qty)
|
||||||
|
|
||||||
@@ -1282,15 +1294,18 @@ class update_entries_after:
|
|||||||
if actual_qty > 0:
|
if actual_qty > 0:
|
||||||
stock_value_difference = incoming_rate * actual_qty
|
stock_value_difference = incoming_rate * actual_qty
|
||||||
else:
|
else:
|
||||||
outgoing_rate = get_batch_incoming_rate(
|
new_sle = copy.deepcopy(sle)
|
||||||
item_code=sle.item_code,
|
|
||||||
warehouse=sle.warehouse,
|
new_sle.qty = new_sle.actual_qty
|
||||||
batch_no=sle.batch_no,
|
new_sle.batch_nos = frappe._dict({new_sle.batch_no: new_sle})
|
||||||
posting_date=sle.posting_date,
|
batch_obj = BatchNoValuation(
|
||||||
posting_time=sle.posting_time,
|
sle=new_sle,
|
||||||
creation=sle.creation,
|
warehouse=new_sle.get("warehouse"),
|
||||||
|
item_code=new_sle.get("item_code"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
outgoing_rate = batch_obj.get_incoming_rate()
|
||||||
|
|
||||||
if outgoing_rate is None:
|
if outgoing_rate is None:
|
||||||
# This can *only* happen if qty available for the batch is zero.
|
# This can *only* happen if qty available for the batch is zero.
|
||||||
# in such case fall back various other rates.
|
# in such case fall back various other rates.
|
||||||
|
|||||||
Reference in New Issue
Block a user