From 80b6c226b2424e9351aaf3fec74048d7f4f4f05e Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sun, 16 Nov 2025 12:57:49 +0530 Subject: [PATCH] fix: validation to check company in Sales Forecast and MPS --- .../master_production_schedule.js | 10 ++++++++++ .../master_production_schedule.json | 5 ++--- .../master_production_schedule.py | 18 +++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.js b/erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.js index 020f2c6db72..a70267f04ae 100644 --- a/erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.js +++ b/erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.js @@ -6,6 +6,8 @@ frappe.ui.form.on("Master Production Schedule", { frm.trigger("set_query_filters"); frm.set_df_property("items", "cannot_add_rows", true); + frm.set_df_property("material_requests", "cannot_add_rows", true); + frm.set_df_property("sales_orders", "cannot_add_rows", true); frm.fields_dict.items.$wrapper.find("[data-action='duplicate_rows']").css("display", "none"); frm.trigger("set_custom_buttons"); @@ -36,6 +38,14 @@ frappe.ui.form.on("Master Production Schedule", { }, }; }); + + frm.set_query("sales_forecast", (doc) => { + return { + filters: { + company: doc.company, + }, + }; + }); }, get_actual_demand(frm) { diff --git a/erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.json b/erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.json index 3110c44bcfc..39e4bbb16ad 100644 --- a/erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.json +++ b/erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.json @@ -26,8 +26,8 @@ "material_requests", "section_break_xtby", "column_break_yhkr", - "column_break_vvys", "get_actual_demand", + "column_break_vvys", "section_break_cmgo", "items", "forecast_demand_section", @@ -60,7 +60,6 @@ "fieldtype": "Column Break" }, { - "allow_bulk_edit": 1, "fieldname": "items", "fieldtype": "Table", "label": "Items", @@ -189,7 +188,7 @@ "grid_page_length": 50, "index_web_pages_for_search": 1, "links": [], - "modified": "2025-09-02 19:33:28.244544", + "modified": "2025-11-13 19:15:36.090622", "modified_by": "Administrator", "module": "Manufacturing", "name": "Master Production Schedule", diff --git a/erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.py b/erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.py index cecfcfe4af2..bfa0dbc3531 100644 --- a/erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.py +++ b/erpnext/manufacturing/doctype/master_production_schedule/master_production_schedule.py @@ -4,7 +4,7 @@ import math import frappe -from frappe import _ +from frappe import _, bold from frappe.model.document import Document from frappe.model.mapper import get_mapped_doc from frappe.query_builder.functions import Sum @@ -64,6 +64,22 @@ class MasterProductionSchedule(Document): def validate(self): self.set_to_date() + self.validate_company() + + def validate_company(self): + if self.sales_forecast: + sales_forecast_company = frappe.db.get_value("Sales Forecast", self.sales_forecast, "company") + if sales_forecast_company != self.company: + frappe.throw( + _( + "The Company {0} of Sales Forecast {1} does not match with the Company {2} of Master Production Schedule {3}." + ).format( + bold(sales_forecast_company), + bold(self.sales_forecast), + bold(self.company), + bold(self.name), + ) + ) def set_to_date(self): self.to_date = None