mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 16:04:46 +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(
|
frappe.get_doc(
|
||||||
{
|
{
|
||||||
"doctype": "Customer",
|
"doctype": "Customer",
|
||||||
"customer_group": "All Customer Groups",
|
"customer_group": "Individual",
|
||||||
"customer_type": "Company",
|
"customer_type": "Company",
|
||||||
"customer_name": "Poore Simon's",
|
"customer_name": "Poore Simon's",
|
||||||
}
|
}
|
||||||
@@ -429,7 +429,7 @@ def add_vouchers(gl_account="_Test Bank - _TC"):
|
|||||||
frappe.get_doc(
|
frappe.get_doc(
|
||||||
{
|
{
|
||||||
"doctype": "Customer",
|
"doctype": "Customer",
|
||||||
"customer_group": "All Customer Groups",
|
"customer_group": "Individual",
|
||||||
"customer_type": "Company",
|
"customer_type": "Company",
|
||||||
"customer_name": "Fayva",
|
"customer_name": "Fayva",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ def make_customer(customer=None):
|
|||||||
{
|
{
|
||||||
"doctype": "Customer",
|
"doctype": "Customer",
|
||||||
"customer_name": customer_name,
|
"customer_name": customer_name,
|
||||||
"customer_group": "All Customer Groups",
|
"customer_group": "Individual",
|
||||||
"customer_type": "Company",
|
"customer_type": "Company",
|
||||||
"territory": "All Territories",
|
"territory": "All Territories",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2043,6 +2043,7 @@ def create_customer(name="_Test Customer 2 USD", currency="USD"):
|
|||||||
customer.customer_name = name
|
customer.customer_name = name
|
||||||
customer.default_currency = currency
|
customer.default_currency = currency
|
||||||
customer.type = "Individual"
|
customer.type = "Individual"
|
||||||
|
customer.customer_group = "Individual"
|
||||||
customer.save()
|
customer.save()
|
||||||
customer = customer.name
|
customer = customer.name
|
||||||
return customer
|
return customer
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ class TestPaymentLedgerEntry(FrappeTestCase):
|
|||||||
customer = frappe.new_doc("Customer")
|
customer = frappe.new_doc("Customer")
|
||||||
customer.customer_name = name
|
customer.customer_name = name
|
||||||
customer.type = "Individual"
|
customer.type = "Individual"
|
||||||
|
customer.customer_group = "Individual"
|
||||||
customer.save()
|
customer.save()
|
||||||
self.customer = customer.name
|
self.customer = customer.name
|
||||||
|
|
||||||
|
|||||||
@@ -2546,6 +2546,7 @@ def make_customer(customer_name, currency=None):
|
|||||||
customer = frappe.new_doc("Customer")
|
customer = frappe.new_doc("Customer")
|
||||||
customer.customer_name = customer_name
|
customer.customer_name = customer_name
|
||||||
customer.type = "Individual"
|
customer.type = "Individual"
|
||||||
|
customer.customer_group = "Individual"
|
||||||
|
|
||||||
if currency:
|
if currency:
|
||||||
customer.default_currency = currency
|
customer.default_currency = currency
|
||||||
|
|||||||
@@ -629,18 +629,21 @@ def create_parties():
|
|||||||
customer.customer_name = "_Test Subscription Customer"
|
customer.customer_name = "_Test Subscription Customer"
|
||||||
customer.default_currency = "USD"
|
customer.default_currency = "USD"
|
||||||
customer.append("accounts", {"company": "_Test Company", "account": "_Test Receivable USD - _TC"})
|
customer.append("accounts", {"company": "_Test Company", "account": "_Test Receivable USD - _TC"})
|
||||||
|
customer.customer_group = "Individual"
|
||||||
customer.insert()
|
customer.insert()
|
||||||
|
|
||||||
if not frappe.db.exists("Customer", "_Test Subscription Customer Multi Currency"):
|
if not frappe.db.exists("Customer", "_Test Subscription Customer Multi Currency"):
|
||||||
customer = frappe.new_doc("Customer")
|
customer = frappe.new_doc("Customer")
|
||||||
customer.customer_name = "Test Subscription Customer Multi Currency"
|
customer.customer_name = "Test Subscription Customer Multi Currency"
|
||||||
customer.default_currency = "USD"
|
customer.default_currency = "USD"
|
||||||
|
customer.customer_group = "Individual"
|
||||||
customer.insert()
|
customer.insert()
|
||||||
|
|
||||||
if not frappe.db.exists("Customer", "_Test Subscription Customer John Doe"):
|
if not frappe.db.exists("Customer", "_Test Subscription Customer John Doe"):
|
||||||
customer = frappe.new_doc("Customer")
|
customer = frappe.new_doc("Customer")
|
||||||
customer.customer_name = "_Test Subscription Customer John Doe"
|
customer.customer_name = "_Test Subscription Customer John Doe"
|
||||||
customer.append("accounts", {"company": "_Test Company", "account": "_Test Receivable - _TC"})
|
customer.append("accounts", {"company": "_Test Company", "account": "_Test Receivable - _TC"})
|
||||||
|
customer.customer_group = "Individual"
|
||||||
customer.insert()
|
customer.insert()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -779,6 +779,7 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
|||||||
"customer_name": "Jane Doe",
|
"customer_name": "Jane Doe",
|
||||||
"type": "Individual",
|
"type": "Individual",
|
||||||
"default_currency": "USD",
|
"default_currency": "USD",
|
||||||
|
"customer_group": "Individual",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.insert()
|
.insert()
|
||||||
@@ -1002,6 +1003,7 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
|||||||
"customer_name": "Jane Doe",
|
"customer_name": "Jane Doe",
|
||||||
"type": "Individual",
|
"type": "Individual",
|
||||||
"default_currency": "USD",
|
"default_currency": "USD",
|
||||||
|
"customer_group": "Individual",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.insert()
|
.insert()
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ class TestGrossProfit(FrappeTestCase):
|
|||||||
customer = frappe.new_doc("Customer")
|
customer = frappe.new_doc("Customer")
|
||||||
customer.customer_name = name
|
customer.customer_name = name
|
||||||
customer.type = "Individual"
|
customer.type = "Individual"
|
||||||
|
customer.customer_group = "Individual"
|
||||||
customer.save()
|
customer.save()
|
||||||
self.customer = customer.name
|
self.customer = customer.name
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class AccountsTestMixin:
|
|||||||
customer = frappe.new_doc("Customer")
|
customer = frappe.new_doc("Customer")
|
||||||
customer.customer_name = customer_name
|
customer.customer_name = customer_name
|
||||||
customer.type = "Individual"
|
customer.type = "Individual"
|
||||||
|
customer.customer_group = "Individual"
|
||||||
|
|
||||||
if currency:
|
if currency:
|
||||||
customer.default_currency = currency
|
customer.default_currency = currency
|
||||||
@@ -36,6 +37,7 @@ class AccountsTestMixin:
|
|||||||
"account": default_account,
|
"account": default_account,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
customer.customer_group = "Individual"
|
||||||
customer.save()
|
customer.save()
|
||||||
self.customer = customer_name
|
self.customer = customer_name
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,8 @@ from erpnext.accounts.party import get_default_price_list
|
|||||||
class PartyTestCase(FrappeTestCase):
|
class PartyTestCase(FrappeTestCase):
|
||||||
def test_get_default_price_list_should_return_none_for_invalid_group(self):
|
def test_get_default_price_list_should_return_none_for_invalid_group(self):
|
||||||
customer = frappe.get_doc(
|
customer = frappe.get_doc(
|
||||||
{
|
{"doctype": "Customer", "customer_name": "test customer", "customer_group": "Individual"}
|
||||||
"doctype": "Customer",
|
|
||||||
"customer_name": "test customer",
|
|
||||||
}
|
|
||||||
).insert(ignore_permissions=True, ignore_mandatory=True)
|
).insert(ignore_permissions=True, ignore_mandatory=True)
|
||||||
customer.customer_group = None
|
|
||||||
customer.save()
|
customer.save()
|
||||||
price_list = get_default_price_list(customer)
|
price_list = get_default_price_list(customer)
|
||||||
assert price_list is None
|
assert price_list is None
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ def make_customer(customer_name, currency=None):
|
|||||||
customer = frappe.new_doc("Customer")
|
customer = frappe.new_doc("Customer")
|
||||||
customer.customer_name = customer_name
|
customer.customer_name = customer_name
|
||||||
customer.customer_type = "Individual"
|
customer.customer_type = "Individual"
|
||||||
|
customer.customer_group = "Individual"
|
||||||
|
|
||||||
if currency:
|
if currency:
|
||||||
customer.default_currency = currency
|
customer.default_currency = currency
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class TestTaxes(unittest.TestCase):
|
|||||||
{
|
{
|
||||||
"doctype": "Customer",
|
"doctype": "Customer",
|
||||||
"customer_name": uuid4(),
|
"customer_name": uuid4(),
|
||||||
"customer_group": "All Customer Groups",
|
"customer_group": "Individual",
|
||||||
}
|
}
|
||||||
).insert()
|
).insert()
|
||||||
self.supplier = frappe.get_doc(
|
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)
|
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'
|
# 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(
|
contact = frappe.get_doc(
|
||||||
{
|
{
|
||||||
"doctype": "Contact",
|
"doctype": "Contact",
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ def create_customer():
|
|||||||
if not doc:
|
if not doc:
|
||||||
doc = frappe.new_doc("Customer")
|
doc = frappe.new_doc("Customer")
|
||||||
doc.customer_name = "_Test NC"
|
doc.customer_name = "_Test NC"
|
||||||
|
doc.customer_group = "Individual"
|
||||||
doc.insert()
|
doc.insert()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ def make_customer():
|
|||||||
"doctype": "Customer",
|
"doctype": "Customer",
|
||||||
"customer_name": "_Test UAE Customer",
|
"customer_name": "_Test UAE Customer",
|
||||||
"customer_type": "Company",
|
"customer_type": "Company",
|
||||||
|
"customer_group": "Individual",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
customer.insert()
|
customer.insert()
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ def make_customer():
|
|||||||
"doctype": "Customer",
|
"doctype": "Customer",
|
||||||
"customer_name": "_Test SA Customer",
|
"customer_name": "_Test SA Customer",
|
||||||
"customer_type": "Company",
|
"customer_type": "Company",
|
||||||
|
"customer_group": "Individual",
|
||||||
}
|
}
|
||||||
).insert()
|
).insert()
|
||||||
|
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ class Customer(TransactionBase):
|
|||||||
def validate(self):
|
def validate(self):
|
||||||
self.flags.is_new_doc = self.is_new()
|
self.flags.is_new_doc = self.is_new()
|
||||||
self.flags.old_lead = self.lead_name
|
self.flags.old_lead = self.lead_name
|
||||||
|
self.validate_customer_group()
|
||||||
validate_party_accounts(self)
|
validate_party_accounts(self)
|
||||||
self.validate_credit_limit_on_change()
|
self.validate_credit_limit_on_change()
|
||||||
self.set_loyalty_program()
|
self.set_loyalty_program()
|
||||||
@@ -324,6 +325,17 @@ class Customer(TransactionBase):
|
|||||||
frappe.NameError,
|
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):
|
def validate_credit_limit_on_change(self):
|
||||||
if self.get("__islocal") or not self.credit_limits:
|
if self.get("__islocal") or not self.credit_limits:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -450,6 +450,7 @@ def make_customer(customer_name):
|
|||||||
customer = frappe.new_doc("Customer")
|
customer = frappe.new_doc("Customer")
|
||||||
customer.customer_name = customer_name
|
customer.customer_name = customer_name
|
||||||
customer.customer_type = "Individual"
|
customer.customer_type = "Individual"
|
||||||
|
customer.customer_group = "Individual"
|
||||||
customer.insert()
|
customer.insert()
|
||||||
return customer.name
|
return customer.name
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ def create_shipment_customer(customer_name):
|
|||||||
customer = frappe.new_doc("Customer")
|
customer = frappe.new_doc("Customer")
|
||||||
customer.customer_name = customer_name
|
customer.customer_name = customer_name
|
||||||
customer.customer_type = "Company"
|
customer.customer_type = "Company"
|
||||||
customer.customer_group = "All Customer Groups"
|
customer.customer_group = "Individual"
|
||||||
customer.territory = "All Territories"
|
customer.territory = "All Territories"
|
||||||
customer.insert()
|
customer.insert()
|
||||||
return customer
|
return customer
|
||||||
|
|||||||
Reference in New Issue
Block a user