feat: allow scrap items when backflush based on is Material Transfer

This commit is contained in:
s-aga-r 2023-08-26 11:38:45 +05:30
parent 08bc33689c
commit ed4f498704

View File

@ -149,41 +149,37 @@ class SubcontractingReceipt(SubcontractingController):
@frappe.whitelist() @frappe.whitelist()
def get_scrap_items(self, recalculate_rate=False): def get_scrap_items(self, recalculate_rate=False):
if ( self.remove_scrap_items()
frappe.db.get_single_value("Buying Settings", "backflush_raw_materials_of_subcontract_based_on")
== "BOM"
):
self.remove_scrap_items()
for item in list(self.items): for item in list(self.items):
if item.bom: 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.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",
{ {
"is_scrap_item": 1, "is_scrap_item": 1,
"reference_name": item.name, "reference_name": item.name,
"item_code": scrap_item.item_code, "item_code": scrap_item.item_code,
"item_name": scrap_item.item_name, "item_name": scrap_item.item_name,
"qty": qty, "qty": qty,
"stock_uom": scrap_item.stock_uom, "stock_uom": scrap_item.stock_uom,
"recalculate_rate": 0, "recalculate_rate": 0,
"rate": scrap_item.rate, "rate": scrap_item.rate,
"rm_cost_per_qty": 0, "rm_cost_per_qty": 0,
"service_cost_per_qty": 0, "service_cost_per_qty": 0,
"additional_cost_per_qty": 0, "additional_cost_per_qty": 0,
"scrap_cost_per_qty": 0, "scrap_cost_per_qty": 0,
"amount": qty * scrap_item.rate, "amount": qty * scrap_item.rate,
"warehouse": self.set_warehouse, "warehouse": self.set_warehouse,
"rejected_warehouse": self.rejected_warehouse, "rejected_warehouse": self.rejected_warehouse,
}, },
) )
if recalculate_rate: if recalculate_rate:
self.calculate_additional_costs() self.calculate_additional_costs()
self.calculate_items_qty_and_amount() self.calculate_items_qty_and_amount()
def remove_scrap_items(self, recalculate_rate=False): def remove_scrap_items(self, recalculate_rate=False):
for item in list(self.items): for item in list(self.items):