diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index aa8d75e1826..a7675e533ab 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -13,6 +13,7 @@ from frappe.query_builder import DocType, Interval from frappe.query_builder.functions import Now from frappe.utils import flt, get_fullname +from erpnext.accounts.party import validate_party_frozen_disabled from erpnext.crm.utils import ( CRMNote, copy_comments, @@ -131,6 +132,7 @@ class Opportunity(TransactionBase, CRMNote): self.validate_item_details() self.validate_uom_is_integer("uom", "qty") self.validate_cust_name() + self.validate_party() self.map_fields() self.validate_qty() self.set_exchange_rate() @@ -346,6 +348,9 @@ class Opportunity(TransactionBase, CRMNote): return False return True + def validate_party(self) -> None: + validate_party_frozen_disabled(self.company, self.opportunity_from, self.party_name) + def validate_cust_name(self): if self.party_name: if self.opportunity_from == "Customer": diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py index f346946568e..34eaec7a6e2 100644 --- a/erpnext/crm/doctype/opportunity/test_opportunity.py +++ b/erpnext/crm/doctype/opportunity/test_opportunity.py @@ -10,8 +10,13 @@ from erpnext.crm.doctype.lead.lead import make_customer from erpnext.crm.doctype.lead.test_lead import make_lead from erpnext.crm.doctype.opportunity.opportunity import make_quotation from erpnext.crm.utils import get_linked_communication_list +<<<<<<< HEAD test_records = frappe.get_test_records("Opportunity") +======= +from erpnext.exceptions import PartyDisabled +from erpnext.tests.utils import ERPNextTestSuite +>>>>>>> 90937ce6d9 (fix: block disabled/frozen customers on Opportunity) class TestOpportunity(unittest.TestCase): @@ -52,6 +57,14 @@ class TestOpportunity(unittest.TestCase): opportunity_doc = make_opportunity(with_items=1, rate=1100, qty=2) self.assertEqual(opportunity_doc.total, 2200) + def test_disabled_customer_not_allowed(self): + frappe.db.set_value("Customer", "_Test Customer", "disabled", 1) + + self.assertRaises(PartyDisabled, make_opportunity, with_items=0) + + frappe.db.set_value("Customer", "_Test Customer", "disabled", 0) + make_opportunity(with_items=0) + def test_carry_forward_of_email_and_comments(self): frappe.db.set_single_value("CRM Settings", "carry_forward_communication_and_comments", 1) lead_doc = make_lead() diff --git a/erpnext/public/js/queries.js b/erpnext/public/js/queries.js index 8b174da244f..32a4e0958c9 100644 --- a/erpnext/public/js/queries.js +++ b/erpnext/public/js/queries.js @@ -12,6 +12,10 @@ $.extend(erpnext.queries, { return { query: "erpnext.controllers.queries.lead_query" }; }, + customer: function () { + return { filters: { disabled: 0 } }; + }, + item: function (filters) { var args = { query: "erpnext.controllers.queries.item_query" }; if (filters) args["filters"] = filters;