fix: validation to check company in Sales Forecast and MPS (#50545)

This commit is contained in:
rohitwaghchaure
2025-11-16 15:08:31 +05:30
committed by GitHub
3 changed files with 29 additions and 4 deletions

View File

@@ -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) {

View File

@@ -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",

View File

@@ -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