Skip to content

Commit

Permalink
fix: add UOM validation for planned-qty
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Jun 22, 2022
1 parent ce1b4e4 commit 00807ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from erpnext.manufacturing.doctype.bom.bom import validate_bom_no
from erpnext.manufacturing.doctype.work_order.work_order import get_item_details
from erpnext.setup.doctype.item_group.item_group import get_item_group_defaults
from erpnext.utilities.transaction_base import validate_uom_is_integer


class ProductionPlan(Document):
Expand All @@ -33,6 +34,7 @@ def validate(self):
self.calculate_total_planned_qty()
self.set_status()
self._rename_temporary_references()
validate_uom_is_integer(self, "stock_uom", "planned_qty")

def set_pending_qty_in_row_without_reference(self):
"Set Pending Qty in independent rows (not from SO or MR)."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,15 +679,23 @@ def test_qty_based_status(self):
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"}
# Case 1: When Planned Qty is non-integer and UOM is integer.
from erpnext.utilities.transaction_base import UOMMustBeIntegerError

self.assertRaises(
UOMMustBeIntegerError, create_production_plan, item_code="_Test FG Item", planned_qty=0.55
)
wo_doc.submit()
self.assertEqual(wo_doc.qty, 0.55)

# Case 2: When Planned Qty is non-integer and UOM is also non-integer.
from erpnext.stock.doctype.item.test_item import make_item

fg_item = make_item(properties={"is_stock_item": 1, "stock_uom": "_Test UOM 1"}).name
bom_item = make_item().name

make_bom(item=fg_item, raw_materials=[bom_item], source_warehouse="_Test Warehouse - _TC")

pln = create_production_plan(item_code=fg_item, planned_qty=0.55, stock_uom="_Test UOM 1")
self.assertEqual(pln.po_items[0].planned_qty, 0.55)

def test_temporary_name_relinking(self):

Expand Down Expand Up @@ -751,6 +759,7 @@ def create_production_plan(**args):
"bom_no": frappe.db.get_value("Item", args.item_code, "default_bom"),
"planned_qty": args.planned_qty or 1,
"planned_start_date": args.planned_start_date or now_datetime(),
"stock_uom": args.stock_uom or "Nos",
},
)

Expand Down

0 comments on commit 00807ab

Please sign in to comment.