Skip to content

Commit

Permalink
fix: min order qty optional in production plan (backport #38956) (#38958
Browse files Browse the repository at this point in the history
)

fix: min order qty optional in production plan (#38956)

* fix: min order qty optional in production plan

* fix: test cases

(cherry picked from commit b09c935)

Co-authored-by: rohitwaghchaure <[email protected]>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Dec 26, 2023
1 parent 0e48ef7 commit ab9fce3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
3 changes: 2 additions & 1 deletion erpnext/manufacturing/doctype/bom/bom.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
"options": "\nWork Order\nJob Card"
},
{
"default": "1",
"fieldname": "conversion_rate",
"fieldtype": "Float",
"label": "Conversion Rate",
Expand Down Expand Up @@ -636,7 +637,7 @@
"image_field": "image",
"is_submittable": 1,
"links": [],
"modified": "2023-08-07 11:38:08.152294",
"modified": "2023-12-26 19:34:08.159312",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "BOM",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ frappe.ui.form.on('Production Plan', {
frappe.throw(__("Select the Warehouse"));
}

frm.set_value("consider_minimum_order_qty", 0);

if (frm.doc.ignore_existing_ordered_qty) {
frm.events.get_items_for_material_requests(frm);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"material_request_planning",
"include_non_stock_items",
"include_subcontracted_items",
"consider_minimum_order_qty",
"include_safety_stock",
"ignore_existing_ordered_qty",
"column_break_25",
Expand Down Expand Up @@ -423,13 +424,19 @@
"fieldtype": "Link",
"label": "Sub Assembly Warehouse",
"options": "Warehouse"
},
{
"default": "0",
"fieldname": "consider_minimum_order_qty",
"fieldtype": "Check",
"label": "Consider Minimum Order Qty"
}
],
"icon": "fa fa-calendar",
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-11-03 14:08:11.928027",
"modified": "2023-12-26 16:31:13.740777",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Production Plan",
Expand Down
19 changes: 17 additions & 2 deletions erpnext/manufacturing/doctype/production_plan/production_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ProductionPlan(Document):
combine_items: DF.Check
combine_sub_items: DF.Check
company: DF.Link
consider_minimum_order_qty: DF.Check
customer: DF.Link | None
for_warehouse: DF.Link | None
from_date: DF.Date | None
Expand Down Expand Up @@ -1211,7 +1212,14 @@ def get_subitems(


def get_material_request_items(
row, sales_order, company, ignore_existing_ordered_qty, include_safety_stock, warehouse, bin_dict
doc,
row,
sales_order,
company,
ignore_existing_ordered_qty,
include_safety_stock,
warehouse,
bin_dict,
):
total_qty = row["qty"]

Expand All @@ -1220,8 +1228,14 @@ def get_material_request_items(
required_qty = total_qty
elif total_qty > bin_dict.get("projected_qty", 0):
required_qty = total_qty - bin_dict.get("projected_qty", 0)
if required_qty > 0 and required_qty < row["min_order_qty"]:

if (
doc.get("consider_minimum_order_qty")
and required_qty > 0
and required_qty < row["min_order_qty"]
):
required_qty = row["min_order_qty"]

item_group_defaults = get_item_group_defaults(row.item_code, company)

if not row["purchase_uom"]:
Expand Down Expand Up @@ -1559,6 +1573,7 @@ def get_items_for_material_requests(doc, warehouses=None, get_parent_warehouse_d

if details.qty > 0:
items = get_material_request_items(
doc,
details,
sales_order,
company,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,29 @@ def test_unreserve_qty_on_closing_of_pp(self):
after_qty = flt(frappe.db.get_value("Bin", bin_name, "reserved_qty_for_production_plan"))
self.assertAlmostEqual(after_qty, before_qty)

def test_min_order_qty_in_pp(self):
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
from erpnext.stock.utils import get_or_make_bin

fg_item = make_item(properties={"is_stock_item": 1}).name
rm_item = make_item(properties={"is_stock_item": 1, "min_order_qty": 1000}).name

rm_warehouse = create_warehouse("RM Warehouse", company="_Test Company")

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

pln = create_production_plan(item_code=fg_item, planned_qty=10, do_not_submit=1)

pln.for_warehouse = rm_warehouse
mr_items = get_items_for_material_requests(pln.as_dict())
for d in mr_items:
self.assertEqual(d.get("quantity"), 10.0)

pln.consider_minimum_order_qty = 1
mr_items = get_items_for_material_requests(pln.as_dict())
for d in mr_items:
self.assertEqual(d.get("quantity"), 1000.0)


def create_production_plan(**args):
"""
Expand Down

0 comments on commit ab9fce3

Please sign in to comment.