From 18d7c77bad25c04fe6ada296f2dad2a788fd1948 Mon Sep 17 00:00:00 2001 From: Sagar Sharma Date: Mon, 14 Mar 2022 12:05:34 +0530 Subject: [PATCH 1/2] fix: max_qty validation condition (cherry picked from commit d198c488a4071d13d0891d87f790562febd44b3e) --- erpnext/manufacturing/doctype/work_order/work_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index 47fe3296cf1..0bfa7a286b5 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -635,12 +635,12 @@ class WorkOrder(Document): if self.production_plan and self.production_plan_item: qty_dict = frappe.db.get_value("Production Plan Item", self.production_plan_item, ["planned_qty", "ordered_qty"], as_dict=1) - allowance_qty =flt(frappe.db.get_single_value("Manufacturing Settings", + allowance_qty = flt(frappe.db.get_single_value("Manufacturing Settings", "overproduction_percentage_for_work_order"))/100 * qty_dict.get("planned_qty", 0) max_qty = qty_dict.get("planned_qty", 0) + allowance_qty - qty_dict.get("ordered_qty", 0) - if max_qty < 1: + if not max_qty > 0: frappe.throw(_("Cannot produce more item for {0}") .format(self.production_item), OverProductionError) elif self.qty > max_qty: From 46f9503a5cd57af6b6d7d68495b725a81dc9f95d Mon Sep 17 00:00:00 2001 From: Sagar Sharma Date: Mon, 14 Mar 2022 16:28:23 +0530 Subject: [PATCH 2/2] test: add test for planned_qty (cherry picked from commit b22bdc5ff762d41242c742bb3f6fda64eb98fd2e) --- .../doctype/production_plan/test_production_plan.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py index 2359815813d..f8067052565 100644 --- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py @@ -605,6 +605,17 @@ class TestProductionPlan(ERPNextTestCase): ] self.assertFalse(pp.all_items_completed()) + def test_production_plan_planned_qty(self): + pln = create_production_plan(item_code="_Test FG Item", planned_qty=0.55) + pln.make_work_order() + work_order = frappe.db.get_value('Work Order', {'production_plan': pln.name}, 'name') + wo_doc = frappe.get_doc('Work Order', work_order) + wo_doc.update({ + 'wip_warehouse': 'Work In Progress - _TC', + 'fg_warehouse': 'Finished Goods - _TC' + }) + wo_doc.submit() + self.assertEqual(wo_doc.qty, 0.55) def create_production_plan(**args): """