mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-20 13:39:18 +00:00
fix: incorrect stock valuation for repack entry (#21737)
This commit is contained in:
@@ -360,6 +360,9 @@ class StockEntry(StockController):
|
|||||||
+ self.work_order + ":" + ", ".join(other_ste), DuplicateEntryForWorkOrderError)
|
+ self.work_order + ":" + ", ".join(other_ste), DuplicateEntryForWorkOrderError)
|
||||||
|
|
||||||
def set_incoming_rate(self):
|
def set_incoming_rate(self):
|
||||||
|
if self.purpose == "Repack":
|
||||||
|
self.set_basic_rate_for_finished_goods()
|
||||||
|
|
||||||
for d in self.items:
|
for d in self.items:
|
||||||
if d.s_warehouse:
|
if d.s_warehouse:
|
||||||
args = self.get_args_for_incoming_rate(d)
|
args = self.get_args_for_incoming_rate(d)
|
||||||
@@ -472,20 +475,31 @@ class StockEntry(StockController):
|
|||||||
"allow_zero_valuation": item.allow_zero_valuation_rate,
|
"allow_zero_valuation": item.allow_zero_valuation_rate,
|
||||||
})
|
})
|
||||||
|
|
||||||
def set_basic_rate_for_finished_goods(self, raw_material_cost, scrap_material_cost):
|
def set_basic_rate_for_finished_goods(self, raw_material_cost=0, scrap_material_cost=0):
|
||||||
|
total_fg_qty = 0
|
||||||
|
if not raw_material_cost and self.get("items"):
|
||||||
|
raw_material_cost = sum([flt(row.basic_amount) for row in self.items
|
||||||
|
if row.s_warehouse and not row.t_warehouse])
|
||||||
|
|
||||||
|
total_fg_qty = sum([flt(row.qty) for row in self.items
|
||||||
|
if row.t_warehouse and not row.s_warehouse])
|
||||||
|
|
||||||
if self.purpose in ["Manufacture", "Repack"]:
|
if self.purpose in ["Manufacture", "Repack"]:
|
||||||
for d in self.get("items"):
|
for d in self.get("items"):
|
||||||
if (d.transfer_qty and (d.bom_no or d.t_warehouse)
|
if (d.transfer_qty and (d.bom_no or d.t_warehouse)
|
||||||
and (getattr(self, "pro_doc", frappe._dict()).scrap_warehouse != d.t_warehouse)):
|
and (getattr(self, "pro_doc", frappe._dict()).scrap_warehouse != d.t_warehouse)):
|
||||||
|
|
||||||
if self.work_order \
|
if (self.work_order and self.purpose == "Manufacture"
|
||||||
and frappe.db.get_single_value("Manufacturing Settings", "material_consumption"):
|
and frappe.db.get_single_value("Manufacturing Settings", "material_consumption")):
|
||||||
bom_items = self.get_bom_raw_materials(d.transfer_qty)
|
bom_items = self.get_bom_raw_materials(d.transfer_qty)
|
||||||
raw_material_cost = sum([flt(row.qty)*flt(row.rate) for row in bom_items.values()])
|
raw_material_cost = sum([flt(row.qty)*flt(row.rate) for row in bom_items.values()])
|
||||||
|
|
||||||
if raw_material_cost:
|
if raw_material_cost and self.purpose == "Manufacture":
|
||||||
d.basic_rate = flt((raw_material_cost - scrap_material_cost) / flt(d.transfer_qty), d.precision("basic_rate"))
|
d.basic_rate = flt((raw_material_cost - scrap_material_cost) / flt(d.transfer_qty), d.precision("basic_rate"))
|
||||||
d.basic_amount = flt((raw_material_cost - scrap_material_cost), d.precision("basic_amount"))
|
d.basic_amount = flt((raw_material_cost - scrap_material_cost), d.precision("basic_amount"))
|
||||||
|
elif self.purpose == "Repack" and total_fg_qty:
|
||||||
|
d.basic_rate = flt(raw_material_cost) / flt(total_fg_qty)
|
||||||
|
d.basic_amount = d.basic_rate * d.qty
|
||||||
|
|
||||||
def distribute_additional_costs(self):
|
def distribute_additional_costs(self):
|
||||||
if self.purpose == "Material Issue":
|
if self.purpose == "Material Issue":
|
||||||
|
|||||||
Reference in New Issue
Block a user