Merge pull request #35935 from s-aga-r/FIX-35898
feat: allow the partial return of components against SCO
This commit is contained in:
commit
fe4161e4d7
@ -173,50 +173,52 @@ class SubcontractingController(StockController):
|
|||||||
self.qty_to_be_received[(row.item_code, row.parent)] += row.qty
|
self.qty_to_be_received[(row.item_code, row.parent)] += row.qty
|
||||||
|
|
||||||
def __get_transferred_items(self):
|
def __get_transferred_items(self):
|
||||||
fields = [
|
se = frappe.qb.DocType("Stock Entry")
|
||||||
f"`tabStock Entry`.`{self.subcontract_data.order_field}`",
|
se_detail = frappe.qb.DocType("Stock Entry Detail")
|
||||||
"`tabStock Entry`.`name` as voucher_no",
|
|
||||||
]
|
|
||||||
|
|
||||||
alias_dict = {
|
query = (
|
||||||
"item_code": "rm_item_code",
|
frappe.qb.from_(se)
|
||||||
"subcontracted_item": "main_item_code",
|
.inner_join(se_detail)
|
||||||
"basic_rate": "rate",
|
.on(se.name == se_detail.parent)
|
||||||
}
|
.select(
|
||||||
|
se[self.subcontract_data.order_field],
|
||||||
child_table_fields = [
|
se.name.as_("voucher_no"),
|
||||||
"item_code",
|
se_detail.item_code.as_("rm_item_code"),
|
||||||
"item_name",
|
se_detail.item_name,
|
||||||
"description",
|
se_detail.description,
|
||||||
"qty",
|
(
|
||||||
"basic_rate",
|
frappe.qb.terms.Case()
|
||||||
"amount",
|
.when(((se.purpose == "Material Transfer") & (se.is_return == 1)), -1 * se_detail.qty)
|
||||||
"serial_no",
|
.else_(se_detail.qty)
|
||||||
"serial_and_batch_bundle",
|
).as_("qty"),
|
||||||
"uom",
|
se_detail.basic_rate.as_("rate"),
|
||||||
"subcontracted_item",
|
se_detail.amount,
|
||||||
"stock_uom",
|
se_detail.serial_no,
|
||||||
"batch_no",
|
se_detail.serial_and_batch_bundle,
|
||||||
"conversion_factor",
|
se_detail.uom,
|
||||||
"s_warehouse",
|
se_detail.subcontracted_item.as_("main_item_code"),
|
||||||
"t_warehouse",
|
se_detail.stock_uom,
|
||||||
"item_group",
|
se_detail.batch_no,
|
||||||
self.subcontract_data.rm_detail_field,
|
se_detail.conversion_factor,
|
||||||
]
|
se_detail.s_warehouse,
|
||||||
|
se_detail.t_warehouse,
|
||||||
|
se_detail.item_group,
|
||||||
|
se_detail[self.subcontract_data.rm_detail_field],
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
(se.docstatus == 1)
|
||||||
|
& (se[self.subcontract_data.order_field].isin(self.subcontract_orders))
|
||||||
|
& (
|
||||||
|
(se.purpose == "Send to Subcontractor")
|
||||||
|
| ((se.purpose == "Material Transfer") & (se.is_return == 1))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if self.backflush_based_on == "BOM":
|
if self.backflush_based_on == "BOM":
|
||||||
child_table_fields.append("original_item")
|
query = query.select(se_detail.original_item)
|
||||||
|
|
||||||
for field in child_table_fields:
|
return query.run(as_dict=True)
|
||||||
fields.append(f"`tabStock Entry Detail`.`{field}` As {alias_dict.get(field, field)}")
|
|
||||||
|
|
||||||
filters = [
|
|
||||||
["Stock Entry", "docstatus", "=", 1],
|
|
||||||
["Stock Entry", "purpose", "=", "Send to Subcontractor"],
|
|
||||||
["Stock Entry", self.subcontract_data.order_field, "in", self.subcontract_orders],
|
|
||||||
]
|
|
||||||
|
|
||||||
return frappe.get_all("Stock Entry", fields=fields, filters=filters)
|
|
||||||
|
|
||||||
def __set_alternative_item_details(self, row):
|
def __set_alternative_item_details(self, row):
|
||||||
if row.get("original_item"):
|
if row.get("original_item"):
|
||||||
|
@ -163,9 +163,10 @@ class SubcontractingOrder(SubcontractingController):
|
|||||||
elif self.per_received > 0 and self.per_received < 100:
|
elif self.per_received > 0 and self.per_received < 100:
|
||||||
status = "Partially Received"
|
status = "Partially Received"
|
||||||
for item in self.supplied_items:
|
for item in self.supplied_items:
|
||||||
if item.returned_qty:
|
if not item.returned_qty or (item.supplied_qty - item.consumed_qty - item.returned_qty) > 0:
|
||||||
status = "Closed"
|
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
status = "Closed"
|
||||||
else:
|
else:
|
||||||
total_required_qty = total_supplied_qty = 0
|
total_required_qty = total_supplied_qty = 0
|
||||||
for item in self.supplied_items:
|
for item in self.supplied_items:
|
||||||
|
Loading…
Reference in New Issue
Block a user