From 553ec40d4ab78bc3a8bc10ce17077409f874c5c5 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Mon, 3 Nov 2025 17:50:59 +0530 Subject: [PATCH] fix: minor issues in subcontracting inward --- .../doctype/sales_invoice/sales_invoice.py | 15 +++++++-------- .../subcontracting_inward_controller.py | 1 - .../selling/doctype/sales_order/sales_order.py | 4 ++-- .../subcontracting_inward_order.py | 2 +- ...subcontracting_inward_order_received_item.json | 3 ++- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 5f6fe525fa8..4a137da1230 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -847,9 +847,10 @@ class SalesInvoice(SellingController): timesheet.db_update_all() def update_billed_qty_in_scio(self): - table = frappe.qb.DocType("Subcontracting Inward Order Received Item") - fieldname = table.returned_qty if self.is_return else table.billed_qty + if self.is_return: + return + table = frappe.qb.DocType("Subcontracting Inward Order Received Item") data = frappe._dict( { item.scio_detail: item.stock_qty if self._action == "submit" else -item.stock_qty @@ -861,8 +862,8 @@ class SalesInvoice(SellingController): if data: case_expr = Case() for name, qty in data.items(): - case_expr = case_expr.when(table.name == name, fieldname + qty) - frappe.qb.update(table).set(fieldname, case_expr).where( + case_expr = case_expr.when(table.name == name, table.billed_qty + qty) + frappe.qb.update(table).set(table.billed_qty, case_expr).where( (table.name.isin(list(data.keys()))) & (table.docstatus == 1) ).run() @@ -1281,16 +1282,14 @@ class SalesInvoice(SellingController): table = frappe.qb.DocType("Subcontracting Inward Order Received Item") query = ( frappe.qb.from_(table) - .select( - table.required_qty, table.consumed_qty, table.billed_qty, table.returned_qty, table.name - ) + .select(table.required_qty, table.consumed_qty, table.billed_qty, table.name) .where((table.docstatus == 1) & (table.name.isin([item.scio_detail for item in self_rms]))) ) result = query.run(as_dict=True) data = {item.name: item for item in result} for item in self_rms: row = data.get(item.scio_detail) - max_qty = max(row.required_qty, row.consumed_qty) - row.billed_qty - row.returned_qty + max_qty = max(row.required_qty, row.consumed_qty) - row.billed_qty if item.stock_qty > max_qty: frappe.throw( _("Row #{0}: Stock quantity {1} ({2}) for item {3} cannot exceed {4}").format( diff --git a/erpnext/controllers/subcontracting_inward_controller.py b/erpnext/controllers/subcontracting_inward_controller.py index f604fef5720..eaa30a97cd4 100644 --- a/erpnext/controllers/subcontracting_inward_controller.py +++ b/erpnext/controllers/subcontracting_inward_controller.py @@ -510,7 +510,6 @@ class SubcontractingInwardController: ) .else_(table.qty) - table.delivered_qty - - table.returned_qty ).as_("max_allowed_qty") ) .where((table.name == item.scio_detail) & (table.docstatus == 1)) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 95eaa788cab..f7c4fef5ebb 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -1361,7 +1361,7 @@ def make_sales_invoice(source_name, target_doc=None, ignore_permissions=False, a .select( child.required_qty, child.consumed_qty, - (child.billed_qty - child.returned_qty).as_("qty"), + child.billed_qty, child.rm_item_code, child.stock_uom, child.name, @@ -1377,7 +1377,7 @@ def make_sales_invoice(source_name, target_doc=None, ignore_permissions=False, a if result: idx = len(doclist.items) + 1 for item in result: - if (qty := max(item.required_qty, item.consumed_qty) - item.qty) > 0: + if (qty := max(item.required_qty, item.consumed_qty) - item.billed_qty) > 0: doclist.append( "items", { diff --git a/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py b/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py index ca3abb8bde9..f79ee9f8b37 100644 --- a/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py +++ b/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py @@ -451,7 +451,7 @@ class SubcontractingInwardOrder(SubcontractingController): qty = ( fg_item.produced_qty if allow_over - else min(fg_item.qty, fg_item.produced_qty) - fg_item.delivered_qty - fg_item.returned_qty + else min(fg_item.qty, fg_item.produced_qty) - fg_item.delivered_qty ) if qty < 0: continue diff --git a/erpnext/subcontracting/doctype/subcontracting_inward_order_received_item/subcontracting_inward_order_received_item.json b/erpnext/subcontracting/doctype/subcontracting_inward_order_received_item/subcontracting_inward_order_received_item.json index 02e138e89d5..82ff107e17e 100644 --- a/erpnext/subcontracting/doctype/subcontracting_inward_order_received_item/subcontracting_inward_order_received_item.json +++ b/erpnext/subcontracting/doctype/subcontracting_inward_order_received_item/subcontracting_inward_order_received_item.json @@ -120,6 +120,7 @@ }, { "default": "0", + "depends_on": "eval:doc.is_customer_provided_item", "fieldname": "returned_qty", "fieldtype": "Float", "label": "Returned Qty", @@ -196,7 +197,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2025-10-21 23:44:18.302327", + "modified": "2025-11-03 17:46:49.905804", "modified_by": "Administrator", "module": "Subcontracting", "name": "Subcontracting Inward Order Received Item",