Skip to content

Commit

Permalink
feat: provision to set required by from Production Plan (#37039)
Browse files Browse the repository at this point in the history
* feat: provision to set the Required By date from production plan

* test: added test case for validate schedule_date

(cherry picked from commit d278b11)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Sep 12, 2023
1 parent 3c6e527 commit 2ec63fb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@
"warehouse",
"item_name",
"material_request_type",
"actual_qty",
"ordered_qty",
"quantity",
"required_bom_qty",
"column_break_4",
"quantity",
"schedule_date",
"uom",
"conversion_factor",
"projected_qty",
"reserved_qty_for_production",
"safety_stock",
"item_details",
"description",
"min_order_qty",
"section_break_8",
"sales_order",
"requested_qty"
"bin_qty_section",
"actual_qty",
"requested_qty",
"reserved_qty_for_production",
"column_break_yhelv",
"ordered_qty",
"projected_qty",
"safety_stock"
],
"fields": [
{
Expand Down Expand Up @@ -65,7 +68,7 @@
"fieldtype": "Column Break"
},
{
"columns": 1,
"columns": 2,
"fieldname": "quantity",
"fieldtype": "Float",
"in_list_view": 1,
Expand All @@ -80,12 +83,12 @@
"read_only": 1
},
{
"columns": 2,
"columns": 1,
"default": "0",
"fieldname": "actual_qty",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Available Qty",
"label": "Qty In Stock",
"no_copy": 1,
"read_only": 1
},
Expand Down Expand Up @@ -176,11 +179,27 @@
"fieldtype": "Float",
"label": "Conversion Factor",
"read_only": 1
},
{
"columns": 1,
"fieldname": "schedule_date",
"fieldtype": "Date",
"in_list_view": 1,
"label": "Required By"
},
{
"fieldname": "bin_qty_section",
"fieldtype": "Section Break",
"label": "BIN Qty"
},
{
"fieldname": "column_break_yhelv",
"fieldtype": "Column Break"
}
],
"istable": 1,
"links": [],
"modified": "2023-05-03 12:43:29.895754",
"modified": "2023-09-12 12:09:08.358326",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Material Request Plan Item",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def make_material_request(self):

# key for Sales Order:Material Request Type:Customer
key = "{}:{}:{}".format(item.sales_order, material_request_type, item_doc.customer or "")
schedule_date = add_days(nowdate(), cint(item_doc.lead_time_days))
schedule_date = item.schedule_date or add_days(nowdate(), cint(item_doc.lead_time_days))

if not key in material_request_map:
# make a new MR for the combination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See license.txt
import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_to_date, flt, now_datetime, nowdate
from frappe.utils import add_to_date, flt, getdate, now_datetime, nowdate

from erpnext.controllers.item_variant import create_variant
from erpnext.manufacturing.doctype.production_plan.production_plan import (
Expand Down Expand Up @@ -58,6 +58,9 @@ def test_production_plan_mr_creation(self):
pln = create_production_plan(item_code="Test Production Item 1")
self.assertTrue(len(pln.mr_items), 2)

for row in pln.mr_items:
row.schedule_date = add_to_date(nowdate(), days=10)

pln.make_material_request()
pln.reload()
self.assertTrue(pln.status, "Material Requested")
Expand All @@ -71,6 +74,13 @@ def test_production_plan_mr_creation(self):

self.assertTrue(len(material_requests), 2)

for row in material_requests:
mr_schedule_date = getdate(frappe.db.get_value("Material Request", row[0], "schedule_date"))

expected_date = getdate(add_to_date(nowdate(), days=10))

self.assertEqual(mr_schedule_date, expected_date)

pln.make_work_order()
work_orders = frappe.get_all(
"Work Order", fields=["name"], filters={"production_plan": pln.name}, as_list=1
Expand Down

0 comments on commit 2ec63fb

Please sign in to comment.