Skip to content

Commit 34e13ee

Browse files
Merge pull request #50318 from rohitwaghchaure/fixed-mrp-issues
fix: multiple MRP issues
2 parents 807d344 + f43444d commit 34e13ee

File tree

7 files changed

+47
-73
lines changed

7 files changed

+47
-73
lines changed

erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,6 @@ def add_mps_data(self, data):
284284
row = data[key]
285285
row.cumulative_lead_time = math.ceil(row.cumulative_lead_time)
286286
row.order_release_date = add_days(row.delivery_date, -row.cumulative_lead_time)
287-
if getdate(row.order_release_date) < getdate(today()):
288-
continue
289-
290287
row.planned_qty = row.qty
291288
row.uom = row.stock_uom
292289
row.warehouse = row.warehouse or self.parent_warehouse

erpnext/manufacturing/doctype/sales_forecast/sales_forecast.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def generate_manual_demand(self):
8484
)
8585

8686
for index in range(self.demand_number):
87-
if self.horizon_type == "Monthly":
87+
if self.frequency == "Monthly":
8888
delivery_date = add_to_date(self.from_date, months=index + 1)
8989
else:
9090
delivery_date = add_to_date(self.from_date, weeks=index + 1)
@@ -95,15 +95,13 @@ def generate_manual_demand(self):
9595
"delivery_date": delivery_date,
9696
"item_name": item_details.item_name,
9797
"uom": item_details.uom,
98-
"demand_qty": 0.0,
98+
"demand_qty": 1.0,
9999
}
100100
)
101101

102102
for demand in forecast_demand:
103103
self.append("items", demand)
104104

105-
self.save()
106-
107105
@frappe.whitelist()
108106
def generate_demand(self):
109107
from statsmodels.tsa.holtwinters import ExponentialSmoothing
@@ -124,7 +122,7 @@ def generate_demand(self):
124122
seasonal_periods = self.get_seasonal_periods(data)
125123
pd_sales_data = pd.DataFrame({"item": data.item, "date": data.date, "qty": data.qty})
126124

127-
resample_val = "M" if self.horizon_type == "Monthly" else "W"
125+
resample_val = "M" if self.frequency == "Monthly" else "W"
128126
_sales_data = pd_sales_data.set_index("date").resample(resample_val).sum()["qty"]
129127

130128
model = ExponentialSmoothing(
@@ -164,7 +162,7 @@ def add_sales_forecast_item(self, item_code, forecast_data):
164162

165163
def get_seasonal_periods(self, data):
166164
days = date_diff(data["end_date"], data["start_date"])
167-
if self.horizon_type == "Monthly":
165+
if self.frequency == "Monthly":
168166
months = (days / 365) * 12
169167
seasonal_periods = cint(months / 2)
170168
if seasonal_periods > 12:

erpnext/manufacturing/report/material_requirements_planning_report/material_requirements_planning_report.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ frappe.query_reports["Material Requirements Planning Report"] = {
7777
default: "All",
7878
options: "\nFinished Goods\nRaw Materials\nAll",
7979
},
80-
{
81-
fieldname: "safety_stock_check_frequency",
82-
label: __("Safety Stock Check Frequency"),
83-
fieldtype: "Select",
84-
default: "Weekly",
85-
options: "\nDaily\nWeekly\nMonthly",
86-
},
8780
{
8881
fieldname: "add_safety_stock",
8982
label: __("Add Safety Stock"),

erpnext/manufacturing/report/material_requirements_planning_report/material_requirements_planning_report.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ def generate_mrp(self):
4141
self.rm_items = []
4242
self.dates = self.get_dates()
4343
self.mps_data = self.get_mps_data()
44-
4544
items = self.get_items_from_mps(self.mps_data)
45+
self.update_sales_forecast_data()
46+
4647
self.item_rm_details = self.get_raw_materials_data(items)
4748

4849
self._bin_details = self.get_item_wise_bin_details()
@@ -52,7 +53,6 @@ def generate_mrp(self):
5253
self._po_details = self.get_purchase_order_data()
5354
self._so_details = self.get_sales_order_data()
5455

55-
self.update_sales_forecast_data()
5656
data, chart = self.get_mrp_data()
5757

5858
return data, chart
@@ -850,6 +850,23 @@ def get_items_from_mps(self, mps_data):
850850
if row.item_code not in items:
851851
items.append(row.item_code)
852852

853+
if self.filters.mps:
854+
sales_forecasts = frappe.get_all(
855+
"Master Production Schedule",
856+
filters={"name": self.filters.mps},
857+
pluck="sales_forecast",
858+
)
859+
860+
if sales_forecasts:
861+
sales_forecast_items = frappe.get_all(
862+
"Sales Forecast Item",
863+
filters={"parent": ("in", sales_forecasts)},
864+
pluck="item_code",
865+
)
866+
867+
if sales_forecast_items:
868+
items.extend(sales_forecast_items)
869+
853870
return items
854871

855872
def get_raw_materials_data(self, items):
@@ -1139,7 +1156,12 @@ def get_sales_forecast_data(self):
11391156
query = query.where(doctype.delivery_date <= self.filters.to_date)
11401157

11411158
if self.filters.warehouse:
1142-
query = query.where(doctype.warehouse == self.filters.warehouse)
1159+
warehouses = [self.filters.get("warehouse")]
1160+
if frappe.db.get_value("Warehouse", self.filters.get("warehouse"), "is_group"):
1161+
warehouses = get_descendants_of("Warehouse", self.filters.get("warehouse"))
1162+
warehouses.append(self.filters.get("warehouse"))
1163+
1164+
query = query.where(forecast_doc.parent_warehouse.isin(warehouses))
11431165

11441166
if self.filters.item_code:
11451167
query = query.where(doctype.item_code == self.filters.item_code)

erpnext/manufacturing/workspace/manufacturing/manufacturing.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@
347347
"hidden": 0,
348348
"is_query_report": 0,
349349
"label": "Production",
350-
"link_count": 7,
350+
"link_count": 8,
351351
"link_type": "DocType",
352352
"onboard": 0,
353353
"type": "Card Break"
@@ -386,22 +386,32 @@
386386
"type": "Link"
387387
},
388388
{
389+
"dependencies": "",
389390
"hidden": 0,
390391
"is_query_report": 0,
391-
"label": "Master Production Schedule",
392+
"label": "Job Card",
392393
"link_count": 0,
393-
"link_to": "Master Production Schedule",
394+
"link_to": "Job Card",
394395
"link_type": "DocType",
395396
"onboard": 0,
396397
"type": "Link"
397398
},
398399
{
399-
"dependencies": "",
400400
"hidden": 0,
401401
"is_query_report": 0,
402-
"label": "Job Card",
402+
"label": "Item Lead Time",
403403
"link_count": 0,
404-
"link_to": "Job Card",
404+
"link_to": "Item Lead Time",
405+
"link_type": "DocType",
406+
"onboard": 0,
407+
"type": "Link"
408+
},
409+
{
410+
"hidden": 0,
411+
"is_query_report": 0,
412+
"label": "Master Production Schedule",
413+
"link_count": 0,
414+
"link_to": "Master Production Schedule",
405415
"link_type": "DocType",
406416
"onboard": 0,
407417
"type": "Link"
@@ -428,7 +438,7 @@
428438
"type": "Link"
429439
}
430440
],
431-
"modified": "2025-10-30 11:49:35.589944",
441+
"modified": "2025-11-03 17:02:26.882516",
432442
"modified_by": "Administrator",
433443
"module": "Manufacturing",
434444
"name": "Manufacturing",

erpnext/stock/doctype/item/item.json

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,6 @@
119119
"default_item_manufacturer",
120120
"default_manufacturer_part_no",
121121
"total_projected_qty",
122-
"lead_time_in_days_section",
123-
"procurement_time",
124-
"manufacturing_time",
125-
"column_break_whvr",
126-
"planning_buffer",
127-
"cumulative_time",
128122
"capacity_in_days_section",
129123
"production_capacity"
130124
],
@@ -894,36 +888,6 @@
894888
"fieldtype": "Section Break",
895889
"label": "Deferred Accounting"
896890
},
897-
{
898-
"fieldname": "lead_time_in_days_section",
899-
"fieldtype": "Section Break",
900-
"label": "Lead Time (In Days)"
901-
},
902-
{
903-
"fieldname": "procurement_time",
904-
"fieldtype": "Int",
905-
"label": "Procurement Time"
906-
},
907-
{
908-
"fieldname": "planning_buffer",
909-
"fieldtype": "Int",
910-
"label": "Planning Buffer"
911-
},
912-
{
913-
"fieldname": "column_break_whvr",
914-
"fieldtype": "Column Break"
915-
},
916-
{
917-
"fieldname": "manufacturing_time",
918-
"fieldtype": "Int",
919-
"label": "Manufacturing Time"
920-
},
921-
{
922-
"fieldname": "cumulative_time",
923-
"fieldtype": "Int",
924-
"label": "Cumulative Time",
925-
"read_only": 1
926-
},
927891
{
928892
"fieldname": "capacity_in_days_section",
929893
"fieldtype": "Section Break",
@@ -953,7 +917,7 @@
953917
"image_field": "image",
954918
"links": [],
955919
"make_attachments_public": 1,
956-
"modified": "2025-10-13 16:58:40.946604",
920+
"modified": "2025-11-03 17:01:24.555003",
957921
"modified_by": "Administrator",
958922
"module": "Stock",
959923
"name": "Item",

erpnext/stock/doctype/item/item.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ class Item(Document):
8181
brand: DF.Link | None
8282
country_of_origin: DF.Link | None
8383
create_new_batch: DF.Check
84-
cumulative_time: DF.Int
8584
customer: DF.Link | None
8685
customer_code: DF.SmallText | None
8786
customer_items: DF.Table[ItemCustomerDetail]
@@ -120,7 +119,6 @@ class Item(Document):
120119
item_name: DF.Data | None
121120
last_purchase_rate: DF.Float
122121
lead_time_days: DF.Int
123-
manufacturing_time: DF.Int
124122
max_discount: DF.Float
125123
min_order_qty: DF.Float
126124
naming_series: DF.Literal["STO-ITEM-.YYYY.-"]
@@ -129,8 +127,6 @@ class Item(Document):
129127
opening_stock: DF.Float
130128
over_billing_allowance: DF.Float
131129
over_delivery_receipt_allowance: DF.Float
132-
planning_buffer: DF.Int
133-
procurement_time: DF.Int
134130
production_capacity: DF.Int
135131
purchase_uom: DF.Link | None
136132
quality_inspection_template: DF.Link | None
@@ -221,16 +217,10 @@ def validate(self):
221217
self.validate_auto_reorder_enabled_in_stock_settings()
222218
self.cant_change()
223219
self.validate_item_tax_net_rate_range()
224-
self.set_cumulative_time()
225220

226221
if not self.is_new():
227222
self.old_item_group = frappe.db.get_value(self.doctype, self.name, "item_group")
228223

229-
def set_cumulative_time(self):
230-
self.cumulative_time = (
231-
cint(self.procurement_time) + cint(self.manufacturing_time) + cint(self.planning_buffer)
232-
)
233-
234224
def on_update(self):
235225
self.update_variants()
236226
self.update_item_price()

0 commit comments

Comments
 (0)