feat: Disassembly Order (backport #42655) (#42957)

* feat: Disassembly Order (#42655)

(cherry picked from commit 663a08e4cd)

# Conflicts:
#	erpnext/stock/doctype/stock_entry_type/stock_entry_type.json

* chore: fix conflicts

---------

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot]
2024-08-27 23:07:37 +05:30
committed by GitHub
parent 3a5f19853a
commit 8d8dd0cd2b
11 changed files with 212 additions and 20 deletions

View File

@@ -127,7 +127,7 @@
"label": "Purpose",
"oldfieldname": "purpose",
"oldfieldtype": "Select",
"options": "Material Issue\nMaterial Receipt\nMaterial Transfer\nMaterial Transfer for Manufacture\nMaterial Consumption for Manufacture\nManufacture\nRepack\nSend to Subcontractor",
"options": "Material Issue\nMaterial Receipt\nMaterial Transfer\nMaterial Transfer for Manufacture\nMaterial Consumption for Manufacture\nManufacture\nRepack\nSend to Subcontractor\nDisassemble",
"read_only": 1,
"search_index": 1
},
@@ -143,7 +143,7 @@
"reqd": 1
},
{
"depends_on": "eval:in_list([\"Material Transfer for Manufacture\", \"Manufacture\", \"Material Consumption for Manufacture\"], doc.purpose)",
"depends_on": "eval:in_list([\"Material Transfer for Manufacture\", \"Manufacture\", \"Material Consumption for Manufacture\", \"Disassemble\"], doc.purpose)",
"fieldname": "work_order",
"fieldtype": "Link",
"label": "Work Order",
@@ -242,7 +242,7 @@
},
{
"default": "0",
"depends_on": "eval:in_list([\"Material Issue\", \"Material Transfer\", \"Manufacture\", \"Repack\", \"Send to Subcontractor\", \"Material Transfer for Manufacture\", \"Material Consumption for Manufacture\"], doc.purpose)",
"depends_on": "eval:in_list([\"Material Issue\", \"Material Transfer\", \"Manufacture\", \"Repack\", \"Send to Subcontractor\", \"Material Transfer for Manufacture\", \"Material Consumption for Manufacture\", \"Disassemble\"], doc.purpose)",
"fieldname": "from_bom",
"fieldtype": "Check",
"label": "From BOM",
@@ -697,7 +697,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-08-13 19:02:42.386955",
"modified": "2024-08-13 19:05:42.386955",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Entry",

View File

@@ -132,6 +132,7 @@ class StockEntry(StockController):
"Manufacture",
"Repack",
"Send to Subcontractor",
"Disassemble",
]
remarks: DF.Text | None
sales_invoice_no: DF.Link | None
@@ -337,6 +338,7 @@ class StockEntry(StockController):
"Repack",
"Send to Subcontractor",
"Material Consumption for Manufacture",
"Disassemble",
]
if self.purpose not in valid_purposes:
@@ -616,6 +618,7 @@ class StockEntry(StockController):
"Manufacture",
"Material Transfer for Manufacture",
"Material Consumption for Manufacture",
"Disassemble",
):
# check if work order is entered
@@ -1703,11 +1706,63 @@ class StockEntry(StockController):
},
)
def get_items_for_disassembly(self):
"""Get items for Disassembly Order"""
if not self.work_order:
frappe.throw(_("The Work Order is mandatory for Disassembly Order"))
items = self.get_items_from_manufacture_entry()
s_warehouse = ""
if self.work_order:
s_warehouse = frappe.db.get_value("Work Order", self.work_order, "fg_warehouse")
for row in items:
child_row = self.append("items", {})
for field, value in row.items():
if value is not None:
child_row.set(field, value)
child_row.s_warehouse = (self.from_warehouse or s_warehouse) if row.is_finished_item else ""
child_row.t_warehouse = self.to_warehouse if not row.is_finished_item else ""
child_row.is_finished_item = 0 if row.is_finished_item else 1
def get_items_from_manufacture_entry(self):
return frappe.get_all(
"Stock Entry",
fields=[
"`tabStock Entry Detail`.`item_code`",
"`tabStock Entry Detail`.`item_name`",
"`tabStock Entry Detail`.`description`",
"`tabStock Entry Detail`.`qty`",
"`tabStock Entry Detail`.`transfer_qty`",
"`tabStock Entry Detail`.`stock_uom`",
"`tabStock Entry Detail`.`uom`",
"`tabStock Entry Detail`.`basic_rate`",
"`tabStock Entry Detail`.`conversion_factor`",
"`tabStock Entry Detail`.`is_finished_item`",
"`tabStock Entry Detail`.`batch_no`",
"`tabStock Entry Detail`.`serial_no`",
"`tabStock Entry Detail`.`use_serial_batch_fields`",
],
filters=[
["Stock Entry", "purpose", "=", "Manufacture"],
["Stock Entry", "work_order", "=", self.work_order],
["Stock Entry", "docstatus", "=", 1],
["Stock Entry Detail", "docstatus", "=", 1],
],
order_by="`tabStock Entry Detail`.`idx` desc, `tabStock Entry Detail`.`is_finished_item` desc",
)
@frappe.whitelist()
def get_items(self):
self.set("items", [])
self.validate_work_order()
if self.purpose == "Disassemble":
return self.get_items_for_disassembly()
if not self.posting_date or not self.posting_time:
frappe.throw(_("Posting date and posting time is mandatory"))

View File

@@ -17,7 +17,7 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Purpose",
"options": "\nMaterial Issue\nMaterial Receipt\nMaterial Transfer\nMaterial Transfer for Manufacture\nMaterial Consumption for Manufacture\nManufacture\nRepack\nSend to Subcontractor",
"options": "\nMaterial Issue\nMaterial Receipt\nMaterial Transfer\nMaterial Transfer for Manufacture\nMaterial Consumption for Manufacture\nManufacture\nRepack\nSend to Subcontractor\nDisassemble",
"reqd": 1,
"set_only_once": 1
},
@@ -37,10 +37,11 @@
}
],
"links": [],
"modified": "2024-08-20 15:35:45.696958",
"modified": "2024-08-24 16:00:22.696958",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Entry Type",
"naming_rule": "Set by user",
"owner": "Administrator",
"permissions": [
{

View File

@@ -27,6 +27,7 @@ class StockEntryType(Document):
"Manufacture",
"Repack",
"Send to Subcontractor",
"Disassemble",
]
# end: auto-generated types
@@ -45,5 +46,6 @@ class StockEntryType(Document):
"Manufacture",
"Repack",
"Send to Subcontractor",
"Disassemble",
]:
frappe.throw(f"Stock Entry Type {self.name} cannot be set as standard")