refactor: remove old subcontracting flow (#54717)

This commit is contained in:
Mihir Kandoi
2026-05-04 14:06:59 +05:30
committed by GitHub
parent 19234cafbe
commit a68769565b
40 changed files with 107 additions and 759 deletions

View File

@@ -4171,11 +4171,7 @@ def update_child_qty_rate(
if flt(child_item.get("qty")) != flt(d.get("qty")):
any_qty_changed = True
if (
parent.doctype in ["Sales Order", "Purchase Order"]
and parent.is_subcontracted
and not parent.get("is_old_subcontracting_flow")
):
if parent.doctype in ["Sales Order", "Purchase Order"] and parent.is_subcontracted:
validate_fg_item_for_subcontracting(d, new_child_flag)
child_item.fg_item_qty = flt(d["fg_item_qty"])
@@ -4246,18 +4242,12 @@ def update_child_qty_rate(
parent.update_receiving_percentage()
if parent.is_subcontracted:
if parent.is_old_subcontracting_flow:
if should_update_supplied_items(parent):
parent.update_reserved_qty_for_subcontract()
parent.create_raw_materials_supplied()
parent.save()
else:
if not parent.can_update_items():
frappe.throw(
_(
"Items cannot be updated as Subcontracting Order is created against the Purchase Order {0}."
).format(frappe.bold(parent.name))
)
if not parent.can_update_items():
frappe.throw(
_(
"Items cannot be updated as Subcontracting Order is created against the Purchase Order {0}."
).format(frappe.bold(parent.name))
)
elif parent_doctype == "Sales Order": # Sales Order
if parent.is_subcontracted and not parent.can_update_items():
frappe.throw(

View File

@@ -59,11 +59,6 @@ class BuyingController(SubcontractingController):
self.validate_rejected_warehouse()
self.validate_accepted_rejected_qty()
validate_for_items(self)
# sub-contracting
self.validate_for_subcontracting()
if self.get("is_old_subcontracting_flow"):
self.create_raw_materials_supplied()
self.set_landed_cost_voucher_amount()
if self.doctype in ("Purchase Receipt", "Purchase Invoice"):
@@ -488,21 +483,12 @@ class BuyingController(SubcontractingController):
if not qty_in_stock_uom and item.get("rejected_qty"):
qty_in_stock_uom = flt(item.rejected_qty * item.conversion_factor)
if self.get("is_old_subcontracting_flow"):
item.rm_supp_cost = self.get_supplied_items_cost(item.name, reset_outgoing_rate)
item.valuation_rate = (
net_rate
+ item.item_tax_amount
+ item.rm_supp_cost
+ flt(item.landed_cost_voucher_amount)
) / qty_in_stock_uom
else:
item.valuation_rate = (
net_rate
+ item.item_tax_amount
+ flt(item.landed_cost_voucher_amount)
+ flt(item.get("amount_difference_with_purchase_invoice"))
) / qty_in_stock_uom
item.valuation_rate = (
net_rate
+ item.item_tax_amount
+ flt(item.landed_cost_voucher_amount)
+ flt(item.get("amount_difference_with_purchase_invoice"))
) / qty_in_stock_uom
else:
item.valuation_rate = 0.0
@@ -642,36 +628,6 @@ class BuyingController(SubcontractingController):
* (d.conversion_factor or 1)
)
def validate_for_subcontracting(self):
if self.is_subcontracted and self.get("is_old_subcontracting_flow"):
if self.doctype in ["Purchase Receipt", "Purchase Invoice"] and not self.supplier_warehouse:
frappe.throw(
_("{field_label} is mandatory for sub-contracted {doctype}.").format(
field_label=_(self.meta.get_label("supplier_warehouse")), doctype=_(self.doctype)
)
)
for item in self.get("items"):
if item in self.sub_contracted_items and not item.bom:
frappe.throw(
_("Please select BOM in BOM field for Item {item_code}.").format(
item_code=frappe.bold(item.item_code)
)
)
if self.doctype != "Purchase Order":
return
for row in self.get("supplied_items"):
if not row.reserve_warehouse:
frappe.throw(
_(
"Reserved Warehouse is mandatory for the Item {item_code} in Raw Materials supplied."
).format(item_code=frappe.bold(row.rm_item_code))
)
else:
for item in self.get("items"):
if item.get("bom"):
item.bom = None
def set_qty_as_per_stock_uom(self):
allow_to_edit_stock_qty = frappe.get_single_value(
"Stock Settings", "allow_to_edit_stock_uom_qty_for_purchase"
@@ -885,9 +841,6 @@ class BuyingController(SubcontractingController):
)
)
if self.get("is_old_subcontracting_flow"):
self.make_sl_entries_for_supplier_warehouse(sl_entries)
self.make_sl_entries(
sl_entries,
allow_negative_stock=allow_negative_stock,
@@ -943,8 +896,6 @@ class BuyingController(SubcontractingController):
)
po_obj.update_ordered_qty(po_item_rows)
if self.get("is_old_subcontracting_flow"):
po_obj.update_reserved_qty_for_subcontract()
def on_submit(self):
if self.get("is_return"):
@@ -1213,10 +1164,7 @@ class BuyingController(SubcontractingController):
if self.doctype == "Material Request":
return
if self.get("is_old_subcontracting_flow"):
validate_item_type(self, "is_sub_contracted_item", "subcontracted")
else:
validate_item_type(self, "is_purchase_item", "purchase")
validate_item_type(self, "is_purchase_item", "purchase")
def get_asset_item_details(asset_items):

View File

@@ -26,17 +26,7 @@ from erpnext.stock.utils import get_incoming_rate
class SubcontractingController(StockController):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.get("is_old_subcontracting_flow"):
self.subcontract_data = frappe._dict(
{
"order_doctype": "Purchase Order",
"order_field": "purchase_order",
"rm_detail_field": "po_detail",
"receipt_supplied_items_field": "Purchase Receipt Item Supplied",
"order_supplied_items_field": "Purchase Order Item Supplied",
}
)
elif self.doctype == "Subcontracting Inward Order":
if self.doctype == "Subcontracting Inward Order":
self.subcontract_data = frappe._dict(
{
"order_doctype": "Subcontracting Inward Order",
@@ -541,11 +531,7 @@ class SubcontractingController(StockController):
self.__set_alternative_item_details(row)
self.__transferred_items = copy.deepcopy(self.available_materials)
if self.get("is_old_subcontracting_flow"):
for doctype in ["Purchase Receipt", "Purchase Invoice"]:
self.__update_consumed_materials(doctype)
else:
self.__update_consumed_materials("Subcontracting Receipt")
self.__update_consumed_materials("Subcontracting Receipt")
def __remove_changed_rows(self):
if not self.__changed_name:
@@ -1136,24 +1122,17 @@ class SubcontractingController(StockController):
def set_consumed_qty_in_subcontract_order(self):
# Update consumed qty back in the subcontract order
if self.doctype in ["Subcontracting Order", "Subcontracting Receipt"] or self.get(
"is_old_subcontracting_flow"
):
if self.doctype in ["Subcontracting Order", "Subcontracting Receipt"]:
self.__get_subcontract_orders()
itemwise_consumed_qty = defaultdict(float)
if self.get("is_old_subcontracting_flow"):
doctypes = ["Purchase Receipt", "Purchase Invoice"]
else:
doctypes = ["Subcontracting Receipt"]
for doctype in doctypes:
consumed_items, receipt_items = self.__update_consumed_materials(
doctype, return_consumed_items=True
)
consumed_items, receipt_items = self.__update_consumed_materials(
"Subcontracting Receipt", return_consumed_items=True
)
for row in consumed_items:
key = (row.rm_item_code, row.main_item_code, receipt_items.get(row.reference_name))
itemwise_consumed_qty[key] += row.consumed_qty
for row in consumed_items:
key = (row.rm_item_code, row.main_item_code, receipt_items.get(row.reference_name))
itemwise_consumed_qty[key] += row.consumed_qty
self.__update_consumed_qty_in_subcontract_order(itemwise_consumed_qty)
@@ -1236,32 +1215,10 @@ class SubcontractingController(StockController):
via_landed_cost_voucher=via_landed_cost_voucher,
)
def get_supplied_items_cost(self, item_row_id, reset_outgoing_rate=True):
def get_supplied_items_cost(self, item_row_id):
supplied_items_cost = 0.0
for item in self.get("supplied_items"):
if item.reference_name == item_row_id:
if (
self.get("is_old_subcontracting_flow")
and reset_outgoing_rate
and frappe.get_cached_value("Item", item.rm_item_code, "is_stock_item")
):
rate = get_incoming_rate(
{
"item_code": item.rm_item_code,
"warehouse": self.supplier_warehouse,
"posting_date": self.posting_date,
"posting_time": self.posting_time,
"qty": -1 * item.consumed_qty,
"voucher_detail_no": item.name,
"serial_and_batch_bundle": item.get("serial_and_batch_bundle"),
"serial_no": item.get("serial_no"),
"batch_no": item.get("batch_no"),
}
)
if rate > 0:
item.rate = rate
item.amount = flt(flt(item.consumed_qty) * flt(item.rate), item.precision("amount"))
supplied_items_cost += item.amount