fix: reduce scrap cost from FG total cost
This commit is contained in:
parent
794edbb334
commit
a6b2cf3acd
@ -150,11 +150,13 @@ class SubcontractingReceipt(SubcontractingController):
|
|||||||
frappe.db.get_single_value("Buying Settings", "backflush_raw_materials_of_subcontract_based_on")
|
frappe.db.get_single_value("Buying Settings", "backflush_raw_materials_of_subcontract_based_on")
|
||||||
== "BOM"
|
== "BOM"
|
||||||
):
|
):
|
||||||
|
self.remove_scrap_items()
|
||||||
|
|
||||||
for item in list(self.items):
|
for item in list(self.items):
|
||||||
if item.bom and not item.is_scrap_item:
|
if item.bom:
|
||||||
bom = frappe.get_doc("BOM", item.bom)
|
bom = frappe.get_doc("BOM", item.bom)
|
||||||
for scrap_item in bom.scrap_items:
|
for scrap_item in bom.scrap_items:
|
||||||
qty = flt(item.received_qty) * (flt(scrap_item.stock_qty) / flt(bom.quantity))
|
qty = flt(item.qty) * (flt(scrap_item.stock_qty) / flt(bom.quantity))
|
||||||
self.append(
|
self.append(
|
||||||
"items",
|
"items",
|
||||||
{
|
{
|
||||||
@ -168,9 +170,15 @@ class SubcontractingReceipt(SubcontractingController):
|
|||||||
"warehouse": self.set_warehouse,
|
"warehouse": self.set_warehouse,
|
||||||
"rejected_warehouse": self.rejected_warehouse,
|
"rejected_warehouse": self.rejected_warehouse,
|
||||||
"service_cost_per_qty": 0,
|
"service_cost_per_qty": 0,
|
||||||
|
"reference_name": item.name,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def remove_scrap_items(self):
|
||||||
|
for item in list(self.items):
|
||||||
|
if item.is_scrap_item:
|
||||||
|
self.remove(item)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def set_missing_values(self):
|
def set_missing_values(self):
|
||||||
self.calculate_additional_costs()
|
self.calculate_additional_costs()
|
||||||
@ -214,27 +222,44 @@ class SubcontractingReceipt(SubcontractingController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def calculate_items_qty_and_amount(self):
|
def calculate_items_qty_and_amount(self):
|
||||||
rm_supp_cost = {}
|
rm_cost_map = {}
|
||||||
for item in self.get("supplied_items") or []:
|
for item in self.get("supplied_items") or []:
|
||||||
if item.reference_name in rm_supp_cost:
|
if item.reference_name in rm_cost_map:
|
||||||
rm_supp_cost[item.reference_name] += item.amount
|
rm_cost_map[item.reference_name] += item.amount
|
||||||
else:
|
else:
|
||||||
rm_supp_cost[item.reference_name] = item.amount
|
rm_cost_map[item.reference_name] = item.amount
|
||||||
|
|
||||||
|
scrap_cost_map = {}
|
||||||
|
for item in self.get("items") or []:
|
||||||
|
if item.is_scrap_item:
|
||||||
|
if item.reference_name in scrap_cost_map:
|
||||||
|
scrap_cost_map[item.reference_name] += item.amount
|
||||||
|
else:
|
||||||
|
scrap_cost_map[item.reference_name] = item.amount
|
||||||
|
|
||||||
total_qty = total_amount = 0
|
total_qty = total_amount = 0
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
if item.qty and item.name in rm_supp_cost:
|
if item.qty and not item.is_scrap_item:
|
||||||
item.rm_supp_cost = rm_supp_cost[item.name]
|
if item.name in rm_cost_map:
|
||||||
item.rm_cost_per_qty = item.rm_supp_cost / item.qty
|
item.rm_supp_cost = rm_cost_map[item.name]
|
||||||
rm_supp_cost.pop(item.name)
|
item.rm_cost_per_qty = item.rm_supp_cost / item.qty
|
||||||
|
rm_cost_map.pop(item.name)
|
||||||
|
|
||||||
|
if item.name in scrap_cost_map:
|
||||||
|
item.scrap_cost_per_qty = scrap_cost_map[item.name] / item.qty
|
||||||
|
scrap_cost_map.pop(item.name)
|
||||||
|
|
||||||
if item.recalculate_rate:
|
if item.recalculate_rate:
|
||||||
item.rate = (
|
item.rate = (
|
||||||
flt(item.rm_cost_per_qty) + flt(item.service_cost_per_qty) + flt(item.additional_cost_per_qty)
|
flt(item.rm_cost_per_qty)
|
||||||
|
+ flt(item.service_cost_per_qty)
|
||||||
|
+ flt(item.additional_cost_per_qty)
|
||||||
|
- flt(item.scrap_cost_per_qty)
|
||||||
)
|
)
|
||||||
|
|
||||||
item.received_qty = flt(item.qty) + flt(item.rejected_qty)
|
item.received_qty = flt(item.qty) + flt(item.rejected_qty)
|
||||||
item.amount = flt(item.qty) * flt(item.rate)
|
item.amount = flt(item.qty) * flt(item.rate)
|
||||||
|
|
||||||
total_qty += flt(item.qty)
|
total_qty += flt(item.qty)
|
||||||
total_amount += item.amount
|
total_amount += item.amount
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user