feat: add procss_loss_qty field in work order

This commit is contained in:
18alantom
2021-08-24 16:11:29 +05:30
parent f8a47525e1
commit a14b93d0d8
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) self.assertEqual(fg_item.qty, actual_fg_qty)
# Testing Work Order values # 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): def get_scrap_item_details(bom_no):
scrap_items = {} scrap_items = {}

View File

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

View File

@@ -214,6 +214,7 @@ class WorkOrder(Document):
self.meta.get_label(fieldname), qty, completed_qty, self.name), StockOverProductionError) self.meta.get_label(fieldname), qty, completed_qty, self.name), StockOverProductionError)
self.db_set(fieldname, qty) 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 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: if self.production_plan:
self.update_production_plan_status() 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): def update_production_plan_status(self):
production_plan = frappe.get_doc('Production Plan', self.production_plan) production_plan = frappe.get_doc('Production Plan', self.production_plan)
produced_qty = 0 produced_qty = 0