feat: add procss_loss_qty field in work order

This commit is contained in:
18alantom 2021-08-24 16:11:29 +05:30
parent 7fb08173b5
commit b58853e89d
3 changed files with 42 additions and 13 deletions

View File

@ -746,7 +746,14 @@ class TestWorkOrder(unittest.TestCase):
self.assertEqual(fg_item.qty, actual_fg_qty)
# Testing Work Order values
self.assertEqual(frappe.db.get_value("Work Order", wo.name, "produced_qty"), qty)
self.assertEqual(
frappe.db.get_value("Work Order", wo.name, "produced_qty"),
qty
)
self.assertEqual(
frappe.db.get_value("Work Order", wo.name, "process_loss_qty"),
actual_fg_qty
)
def get_scrap_item_details(bom_no):
scrap_items = {}

View File

@ -19,6 +19,7 @@
"qty",
"material_transferred_for_manufacturing",
"produced_qty",
"process_loss_qty",
"sales_order",
"project",
"serial_no_and_batch_for_finished_good_section",
@ -64,16 +65,12 @@
"description",
"stock_uom",
"column_break2",
"references_section",
"material_request",
"material_request_item",
"sales_order_item",
"column_break_61",
"production_plan",
"production_plan_item",
"production_plan_sub_assembly_item",
"parent_work_order",
"bom_level",
"product_bundle_item",
"amended_from"
],
@ -553,20 +550,29 @@
"read_only": 1
},
{
"fieldname": "production_plan_sub_assembly_item",
"fieldtype": "Data",
"label": "Production Plan Sub-assembly Item",
"no_copy": 1,
"print_hide": 1,
"read_only": 1
}
"fieldname": "production_plan_sub_assembly_item",
"fieldtype": "Data",
"label": "Production Plan Sub-assembly Item",
"no_copy": 1,
"print_hide": 1,
"read_only": 1
},
{
"depends_on": "eval: doc.process_loss_qty",
"fieldname": "process_loss_qty",
"fieldtype": "Float",
"label": "Process Loss Qty",
"no_copy": 1,
"non_negative": 1,
"read_only": 1
}
],
"icon": "fa fa-cogs",
"idx": 1,
"image_field": "image",
"is_submittable": 1,
"links": [],
"modified": "2021-06-28 16:19:14.902699",
"modified": "2021-08-24 15:14:03.844937",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Work Order",

View File

@ -214,6 +214,7 @@ class WorkOrder(Document):
self.meta.get_label(fieldname), qty, completed_qty, self.name), StockOverProductionError)
self.db_set(fieldname, qty)
self.set_process_loss_qty()
from erpnext.selling.doctype.sales_order.sales_order import update_produced_qty_in_so_item
@ -223,6 +224,21 @@ class WorkOrder(Document):
if self.production_plan:
self.update_production_plan_status()
def set_process_loss_qty(self):
process_loss_qty = flt(frappe.db.sql("""
SELECT sum(qty) FROM `tabStock Entry Detail`
WHERE
is_process_loss=1
AND parent IN (
SELECT name FROM `tabStock Entry`
WHERE
work_order=%s
AND docstatus=1
)
""", (self.name, ))[0][0])
if process_loss_qty is not None:
self.db_set('process_loss_qty', process_loss_qty)
def update_production_plan_status(self):
production_plan = frappe.get_doc('Production Plan', self.production_plan)
produced_qty = 0