Merge pull request #50319 from mihir-kandoi/misc-sci-fixes

fix: minor issues in subcontracting inward
This commit is contained in:
Mihir Kandoi
2025-11-03 18:14:47 +05:30
committed by GitHub
5 changed files with 12 additions and 13 deletions

View File

@@ -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(

View File

@@ -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))

View File

@@ -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",
{

View File

@@ -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

View File

@@ -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",