mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-11 19:05:08 +00:00
Merge pull request #53956 from frappe/mergify/bp/version-15-hotfix/pr-53811
fix: prevent selection of group type customer group in customer master (backport #53811)
This commit is contained in:
@@ -398,7 +398,7 @@ def add_vouchers(gl_account="_Test Bank - _TC"):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Customer",
|
||||
"customer_group": "All Customer Groups",
|
||||
"customer_group": "Individual",
|
||||
"customer_type": "Company",
|
||||
"customer_name": "Poore Simon's",
|
||||
}
|
||||
@@ -429,7 +429,7 @@ def add_vouchers(gl_account="_Test Bank - _TC"):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Customer",
|
||||
"customer_group": "All Customer Groups",
|
||||
"customer_group": "Individual",
|
||||
"customer_type": "Company",
|
||||
"customer_name": "Fayva",
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ def make_customer(customer=None):
|
||||
{
|
||||
"doctype": "Customer",
|
||||
"customer_name": customer_name,
|
||||
"customer_group": "All Customer Groups",
|
||||
"customer_group": "Individual",
|
||||
"customer_type": "Company",
|
||||
"territory": "All Territories",
|
||||
}
|
||||
|
||||
@@ -2043,6 +2043,7 @@ def create_customer(name="_Test Customer 2 USD", currency="USD"):
|
||||
customer.customer_name = name
|
||||
customer.default_currency = currency
|
||||
customer.type = "Individual"
|
||||
customer.customer_group = "Individual"
|
||||
customer.save()
|
||||
customer = customer.name
|
||||
return customer
|
||||
|
||||
@@ -80,6 +80,7 @@ class TestPaymentLedgerEntry(FrappeTestCase):
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = name
|
||||
customer.type = "Individual"
|
||||
customer.customer_group = "Individual"
|
||||
customer.save()
|
||||
self.customer = customer.name
|
||||
|
||||
|
||||
@@ -2546,6 +2546,7 @@ def make_customer(customer_name, currency=None):
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = customer_name
|
||||
customer.type = "Individual"
|
||||
customer.customer_group = "Individual"
|
||||
|
||||
if currency:
|
||||
customer.default_currency = currency
|
||||
|
||||
@@ -629,18 +629,21 @@ def create_parties():
|
||||
customer.customer_name = "_Test Subscription Customer"
|
||||
customer.default_currency = "USD"
|
||||
customer.append("accounts", {"company": "_Test Company", "account": "_Test Receivable USD - _TC"})
|
||||
customer.customer_group = "Individual"
|
||||
customer.insert()
|
||||
|
||||
if not frappe.db.exists("Customer", "_Test Subscription Customer Multi Currency"):
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = "Test Subscription Customer Multi Currency"
|
||||
customer.default_currency = "USD"
|
||||
customer.customer_group = "Individual"
|
||||
customer.insert()
|
||||
|
||||
if not frappe.db.exists("Customer", "_Test Subscription Customer John Doe"):
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = "_Test Subscription Customer John Doe"
|
||||
customer.append("accounts", {"company": "_Test Company", "account": "_Test Receivable - _TC"})
|
||||
customer.customer_group = "Individual"
|
||||
customer.insert()
|
||||
|
||||
|
||||
|
||||
@@ -779,6 +779,7 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
||||
"customer_name": "Jane Doe",
|
||||
"type": "Individual",
|
||||
"default_currency": "USD",
|
||||
"customer_group": "Individual",
|
||||
}
|
||||
)
|
||||
.insert()
|
||||
@@ -1002,6 +1003,7 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
||||
"customer_name": "Jane Doe",
|
||||
"type": "Individual",
|
||||
"default_currency": "USD",
|
||||
"customer_group": "Individual",
|
||||
}
|
||||
)
|
||||
.insert()
|
||||
|
||||
@@ -82,6 +82,7 @@ class TestGrossProfit(FrappeTestCase):
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = name
|
||||
customer.type = "Individual"
|
||||
customer.customer_group = "Individual"
|
||||
customer.save()
|
||||
self.customer = customer.name
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ class AccountsTestMixin:
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = customer_name
|
||||
customer.type = "Individual"
|
||||
customer.customer_group = "Individual"
|
||||
|
||||
if currency:
|
||||
customer.default_currency = currency
|
||||
@@ -36,6 +37,7 @@ class AccountsTestMixin:
|
||||
"account": default_account,
|
||||
},
|
||||
)
|
||||
customer.customer_group = "Individual"
|
||||
customer.save()
|
||||
self.customer = customer_name
|
||||
|
||||
|
||||
@@ -7,12 +7,8 @@ from erpnext.accounts.party import get_default_price_list
|
||||
class PartyTestCase(FrappeTestCase):
|
||||
def test_get_default_price_list_should_return_none_for_invalid_group(self):
|
||||
customer = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Customer",
|
||||
"customer_name": "test customer",
|
||||
}
|
||||
{"doctype": "Customer", "customer_name": "test customer", "customer_group": "Individual"}
|
||||
).insert(ignore_permissions=True, ignore_mandatory=True)
|
||||
customer.customer_group = None
|
||||
customer.save()
|
||||
price_list = get_default_price_list(customer)
|
||||
assert price_list is None
|
||||
|
||||
@@ -29,6 +29,7 @@ def make_customer(customer_name, currency=None):
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = customer_name
|
||||
customer.customer_type = "Individual"
|
||||
customer.customer_group = "Individual"
|
||||
|
||||
if currency:
|
||||
customer.default_currency = currency
|
||||
|
||||
@@ -66,7 +66,7 @@ class TestTaxes(unittest.TestCase):
|
||||
{
|
||||
"doctype": "Customer",
|
||||
"customer_name": uuid4(),
|
||||
"customer_group": "All Customer Groups",
|
||||
"customer_group": "Individual",
|
||||
}
|
||||
).insert()
|
||||
self.supplier = frappe.get_doc(
|
||||
|
||||
@@ -35,7 +35,9 @@ class TestOpportunity(unittest.TestCase):
|
||||
self.assertEqual(frappe.db.get_value("Lead", opp_doc.party_name, "email_id"), opp_doc.contact_email)
|
||||
|
||||
# create new customer and create new contact against 'new.opportunity@example.com'
|
||||
customer = make_customer(opp_doc.party_name).insert(ignore_permissions=True)
|
||||
customer = make_customer(opp_doc.party_name)
|
||||
customer.customer_group = "Individual"
|
||||
customer.insert(ignore_permissions=True)
|
||||
contact = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Contact",
|
||||
|
||||
@@ -196,6 +196,7 @@ def create_customer():
|
||||
if not doc:
|
||||
doc = frappe.new_doc("Customer")
|
||||
doc.customer_name = "_Test NC"
|
||||
doc.customer_group = "Individual"
|
||||
doc.insert()
|
||||
|
||||
|
||||
|
||||
@@ -148,6 +148,7 @@ def make_customer():
|
||||
"doctype": "Customer",
|
||||
"customer_name": "_Test UAE Customer",
|
||||
"customer_type": "Company",
|
||||
"customer_group": "Individual",
|
||||
}
|
||||
)
|
||||
customer.insert()
|
||||
|
||||
@@ -115,6 +115,7 @@ def make_customer():
|
||||
"doctype": "Customer",
|
||||
"customer_name": "_Test SA Customer",
|
||||
"customer_type": "Company",
|
||||
"customer_group": "Individual",
|
||||
}
|
||||
).insert()
|
||||
|
||||
|
||||
@@ -145,6 +145,7 @@ class Customer(TransactionBase):
|
||||
def validate(self):
|
||||
self.flags.is_new_doc = self.is_new()
|
||||
self.flags.old_lead = self.lead_name
|
||||
self.validate_customer_group()
|
||||
validate_party_accounts(self)
|
||||
self.validate_credit_limit_on_change()
|
||||
self.set_loyalty_program()
|
||||
@@ -324,6 +325,17 @@ class Customer(TransactionBase):
|
||||
frappe.NameError,
|
||||
)
|
||||
|
||||
def validate_customer_group(self):
|
||||
if not self.customer_group:
|
||||
return
|
||||
|
||||
is_group = frappe.db.get_value("Customer Group", self.customer_group, "is_group")
|
||||
if is_group:
|
||||
frappe.throw(
|
||||
_("Cannot select a Group type Customer Group. Please select a non-group Customer Group."),
|
||||
title=_("Invalid Customer Group"),
|
||||
)
|
||||
|
||||
def validate_credit_limit_on_change(self):
|
||||
if self.get("__islocal") or not self.credit_limits:
|
||||
return
|
||||
|
||||
@@ -450,6 +450,7 @@ def make_customer(customer_name):
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = customer_name
|
||||
customer.customer_type = "Individual"
|
||||
customer.customer_group = "Individual"
|
||||
customer.insert()
|
||||
return customer.name
|
||||
else:
|
||||
|
||||
@@ -177,7 +177,7 @@ def create_shipment_customer(customer_name):
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = customer_name
|
||||
customer.customer_type = "Company"
|
||||
customer.customer_group = "All Customer Groups"
|
||||
customer.customer_group = "Individual"
|
||||
customer.territory = "All Territories"
|
||||
customer.insert()
|
||||
return customer
|
||||
|
||||
Reference in New Issue
Block a user