fix: incorrect stock valuation for repack entry (#21736)
This commit is contained in:
parent
779fc898b1
commit
8e3fc5ee6e
@ -363,6 +363,9 @@ class StockEntry(StockController):
|
||||
+ self.work_order + ":" + ", ".join(other_ste), DuplicateEntryForWorkOrderError)
|
||||
|
||||
def set_incoming_rate(self):
|
||||
if self.purpose == "Repack":
|
||||
self.set_basic_rate_for_finished_goods()
|
||||
|
||||
for d in self.items:
|
||||
if d.s_warehouse:
|
||||
args = self.get_args_for_incoming_rate(d)
|
||||
@ -475,20 +478,31 @@ class StockEntry(StockController):
|
||||
"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"]:
|
||||
for d in self.get("items"):
|
||||
if (d.transfer_qty and (d.bom_no or d.t_warehouse)
|
||||
and (getattr(self, "pro_doc", frappe._dict()).scrap_warehouse != d.t_warehouse)):
|
||||
|
||||
if self.work_order \
|
||||
and frappe.db.get_single_value("Manufacturing Settings", "material_consumption"):
|
||||
if (self.work_order and self.purpose == "Manufacture"
|
||||
and frappe.db.get_single_value("Manufacturing Settings", "material_consumption")):
|
||||
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()])
|
||||
|
||||
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_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):
|
||||
if self.purpose == "Material Issue":
|
||||
|
Loading…
x
Reference in New Issue
Block a user