mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-15 18:01:41 +00:00
fix: block disabled/frozen customers on Opportunity
Opportunity inherits TransactionBase instead of AccountsController, so
it never ran validate_party_frozen_disabled like Quotation, Sales Order
and Sales Invoice do. A disabled Customer could be saved as an
Opportunity's party and only get caught later at Quotation stage.
Also fixes the party_name Link query on the client: it referenced
erpnext.queries.customer, which was never defined, so disabled
customers showed up in the picker.
(cherry picked from commit 90937ce6d9)
# Conflicts:
# erpnext/crm/doctype/opportunity/test_opportunity.py
This commit is contained in:
@@ -13,6 +13,7 @@ from frappe.query_builder import DocType, Interval
|
|||||||
from frappe.query_builder.functions import Now
|
from frappe.query_builder.functions import Now
|
||||||
from frappe.utils import flt, get_fullname
|
from frappe.utils import flt, get_fullname
|
||||||
|
|
||||||
|
from erpnext.accounts.party import validate_party_frozen_disabled
|
||||||
from erpnext.crm.utils import (
|
from erpnext.crm.utils import (
|
||||||
CRMNote,
|
CRMNote,
|
||||||
copy_comments,
|
copy_comments,
|
||||||
@@ -131,6 +132,7 @@ class Opportunity(TransactionBase, CRMNote):
|
|||||||
self.validate_item_details()
|
self.validate_item_details()
|
||||||
self.validate_uom_is_integer("uom", "qty")
|
self.validate_uom_is_integer("uom", "qty")
|
||||||
self.validate_cust_name()
|
self.validate_cust_name()
|
||||||
|
self.validate_party()
|
||||||
self.map_fields()
|
self.map_fields()
|
||||||
self.validate_qty()
|
self.validate_qty()
|
||||||
self.set_exchange_rate()
|
self.set_exchange_rate()
|
||||||
@@ -346,6 +348,9 @@ class Opportunity(TransactionBase, CRMNote):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def validate_party(self) -> None:
|
||||||
|
validate_party_frozen_disabled(self.company, self.opportunity_from, self.party_name)
|
||||||
|
|
||||||
def validate_cust_name(self):
|
def validate_cust_name(self):
|
||||||
if self.party_name:
|
if self.party_name:
|
||||||
if self.opportunity_from == "Customer":
|
if self.opportunity_from == "Customer":
|
||||||
|
|||||||
@@ -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.lead.test_lead import make_lead
|
||||||
from erpnext.crm.doctype.opportunity.opportunity import make_quotation
|
from erpnext.crm.doctype.opportunity.opportunity import make_quotation
|
||||||
from erpnext.crm.utils import get_linked_communication_list
|
from erpnext.crm.utils import get_linked_communication_list
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
test_records = frappe.get_test_records("Opportunity")
|
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):
|
class TestOpportunity(unittest.TestCase):
|
||||||
@@ -52,6 +57,14 @@ class TestOpportunity(unittest.TestCase):
|
|||||||
opportunity_doc = make_opportunity(with_items=1, rate=1100, qty=2)
|
opportunity_doc = make_opportunity(with_items=1, rate=1100, qty=2)
|
||||||
self.assertEqual(opportunity_doc.total, 2200)
|
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):
|
def test_carry_forward_of_email_and_comments(self):
|
||||||
frappe.db.set_single_value("CRM Settings", "carry_forward_communication_and_comments", 1)
|
frappe.db.set_single_value("CRM Settings", "carry_forward_communication_and_comments", 1)
|
||||||
lead_doc = make_lead()
|
lead_doc = make_lead()
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ $.extend(erpnext.queries, {
|
|||||||
return { query: "erpnext.controllers.queries.lead_query" };
|
return { query: "erpnext.controllers.queries.lead_query" };
|
||||||
},
|
},
|
||||||
|
|
||||||
|
customer: function () {
|
||||||
|
return { filters: { disabled: 0 } };
|
||||||
|
},
|
||||||
|
|
||||||
item: function (filters) {
|
item: function (filters) {
|
||||||
var args = { query: "erpnext.controllers.queries.item_query" };
|
var args = { query: "erpnext.controllers.queries.item_query" };
|
||||||
if (filters) args["filters"] = filters;
|
if (filters) args["filters"] = filters;
|
||||||
|
|||||||
Reference in New Issue
Block a user