feat: provision to set required by from Production Plan (backport #37039) (#37040)

feat: provision to set required by from Production Plan (#37039)

* feat: provision to set the Required By date from production plan

* test: added test case for validate schedule_date

(cherry picked from commit d278b116030df0f272c3c101b75fe3b66a344c04)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot] 2023-09-12 16:29:02 +05:30 committed by GitHub
parent 3c6e527dd1
commit 93af6f6a1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 13 deletions

View File

@ -10,22 +10,25 @@
"warehouse", "warehouse",
"item_name", "item_name",
"material_request_type", "material_request_type",
"actual_qty", "quantity",
"ordered_qty",
"required_bom_qty", "required_bom_qty",
"column_break_4", "column_break_4",
"quantity", "schedule_date",
"uom", "uom",
"conversion_factor", "conversion_factor",
"projected_qty",
"reserved_qty_for_production",
"safety_stock",
"item_details", "item_details",
"description", "description",
"min_order_qty", "min_order_qty",
"section_break_8", "section_break_8",
"sales_order", "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": [ "fields": [
{ {
@ -65,7 +68,7 @@
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
{ {
"columns": 1, "columns": 2,
"fieldname": "quantity", "fieldname": "quantity",
"fieldtype": "Float", "fieldtype": "Float",
"in_list_view": 1, "in_list_view": 1,
@ -80,12 +83,12 @@
"read_only": 1 "read_only": 1
}, },
{ {
"columns": 2, "columns": 1,
"default": "0", "default": "0",
"fieldname": "actual_qty", "fieldname": "actual_qty",
"fieldtype": "Float", "fieldtype": "Float",
"in_list_view": 1, "in_list_view": 1,
"label": "Available Qty", "label": "Qty In Stock",
"no_copy": 1, "no_copy": 1,
"read_only": 1 "read_only": 1
}, },
@ -176,11 +179,27 @@
"fieldtype": "Float", "fieldtype": "Float",
"label": "Conversion Factor", "label": "Conversion Factor",
"read_only": 1 "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, "istable": 1,
"links": [], "links": [],
"modified": "2023-05-03 12:43:29.895754", "modified": "2023-09-12 12:09:08.358326",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Manufacturing", "module": "Manufacturing",
"name": "Material Request Plan Item", "name": "Material Request Plan Item",

View File

@ -726,7 +726,7 @@ class ProductionPlan(Document):
# key for Sales Order:Material Request Type:Customer # key for Sales Order:Material Request Type:Customer
key = "{}:{}:{}".format(item.sales_order, material_request_type, item_doc.customer or "") 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: if not key in material_request_map:
# make a new MR for the combination # make a new MR for the combination

View File

@ -2,7 +2,7 @@
# See license.txt # See license.txt
import frappe import frappe
from frappe.tests.utils import FrappeTestCase 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.controllers.item_variant import create_variant
from erpnext.manufacturing.doctype.production_plan.production_plan import ( from erpnext.manufacturing.doctype.production_plan.production_plan import (
@ -58,6 +58,9 @@ class TestProductionPlan(FrappeTestCase):
pln = create_production_plan(item_code="Test Production Item 1") pln = create_production_plan(item_code="Test Production Item 1")
self.assertTrue(len(pln.mr_items), 2) 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.make_material_request()
pln.reload() pln.reload()
self.assertTrue(pln.status, "Material Requested") self.assertTrue(pln.status, "Material Requested")
@ -71,6 +74,13 @@ class TestProductionPlan(FrappeTestCase):
self.assertTrue(len(material_requests), 2) 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() pln.make_work_order()
work_orders = frappe.get_all( work_orders = frappe.get_all(
"Work Order", fields=["name"], filters={"production_plan": pln.name}, as_list=1 "Work Order", fields=["name"], filters={"production_plan": pln.name}, as_list=1