From ed4f498704486664d9810193c5bc01bbfcf4b23e Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Sat, 26 Aug 2023 11:38:45 +0530 Subject: [PATCH] feat: allow scrap items when backflush based on is Material Transfer --- .../subcontracting_receipt.py | 62 +++++++++---------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.py b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.py index b28292f0a4..4ab0c666c7 100644 --- a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.py +++ b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.py @@ -149,41 +149,37 @@ class SubcontractingReceipt(SubcontractingController): @frappe.whitelist() def get_scrap_items(self, recalculate_rate=False): - if ( - frappe.db.get_single_value("Buying Settings", "backflush_raw_materials_of_subcontract_based_on") - == "BOM" - ): - self.remove_scrap_items() + self.remove_scrap_items() - for item in list(self.items): - if item.bom: - bom = frappe.get_doc("BOM", item.bom) - for scrap_item in bom.scrap_items: - qty = flt(item.qty) * (flt(scrap_item.stock_qty) / flt(bom.quantity)) - self.append( - "items", - { - "is_scrap_item": 1, - "reference_name": item.name, - "item_code": scrap_item.item_code, - "item_name": scrap_item.item_name, - "qty": qty, - "stock_uom": scrap_item.stock_uom, - "recalculate_rate": 0, - "rate": scrap_item.rate, - "rm_cost_per_qty": 0, - "service_cost_per_qty": 0, - "additional_cost_per_qty": 0, - "scrap_cost_per_qty": 0, - "amount": qty * scrap_item.rate, - "warehouse": self.set_warehouse, - "rejected_warehouse": self.rejected_warehouse, - }, - ) + for item in list(self.items): + if item.bom: + bom = frappe.get_doc("BOM", item.bom) + for scrap_item in bom.scrap_items: + qty = flt(item.qty) * (flt(scrap_item.stock_qty) / flt(bom.quantity)) + self.append( + "items", + { + "is_scrap_item": 1, + "reference_name": item.name, + "item_code": scrap_item.item_code, + "item_name": scrap_item.item_name, + "qty": qty, + "stock_uom": scrap_item.stock_uom, + "recalculate_rate": 0, + "rate": scrap_item.rate, + "rm_cost_per_qty": 0, + "service_cost_per_qty": 0, + "additional_cost_per_qty": 0, + "scrap_cost_per_qty": 0, + "amount": qty * scrap_item.rate, + "warehouse": self.set_warehouse, + "rejected_warehouse": self.rejected_warehouse, + }, + ) - if recalculate_rate: - self.calculate_additional_costs() - self.calculate_items_qty_and_amount() + if recalculate_rate: + self.calculate_additional_costs() + self.calculate_items_qty_and_amount() def remove_scrap_items(self, recalculate_rate=False): for item in list(self.items):