From 2c899dd13aaee1c6e63f9e2512e0e75aa737fc5c Mon Sep 17 00:00:00 2001 From: RitvikSardana <65544983+RitvikSardana@users.noreply.github.com> Date: Mon, 9 Oct 2023 20:21:25 +0530 Subject: [PATCH] fix: customer group and territory not mandatory (#37050) * fix: customer group and territory not mandatory * fix: supplier group not required * test: added test case for customer and supplier without group * test: Customer without customer group and territory * chore: remove unwanted changes * test: Supplier without supplier group * test: code cleanup --------- Co-authored-by: Deepesh Garg --- .../test_opening_invoice_creation_tool.py | 1 + .../purchase_invoice/test_purchase_invoice.py | 26 +++++++++++++++++++ .../sales_invoice/test_sales_invoice.py | 19 ++++++++++++++ erpnext/buying/doctype/supplier/supplier.json | 5 ++-- .../buying/doctype/supplier/test_supplier.py | 7 +++-- .../selling/doctype/customer/customer.json | 4 +-- erpnext/selling/doctype/customer/customer.py | 14 +--------- 7 files changed, 55 insertions(+), 21 deletions(-) diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py b/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py index 1e22c64c8f..02c2c6704a 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py @@ -218,6 +218,7 @@ def make_customer(customer=None): "territory": "All Territories", } ) + if not frappe.db.exists("Customer", customer_name): customer.insert(ignore_permissions=True) return customer.name diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 0aaea060b5..aa3d1b3c15 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -1916,6 +1916,32 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin): pi.load_from_db() self.assertFalse(pi.repost_required) + @change_settings("Buying Settings", {"supplier_group": None}) + def test_purchase_invoice_without_supplier_group(self): + # Create a Supplier + test_supplier_name = "_Test Supplier Without Supplier Group" + if not frappe.db.exists("Supplier", test_supplier_name): + supplier = frappe.get_doc( + { + "doctype": "Supplier", + "supplier_name": test_supplier_name, + } + ).insert(ignore_permissions=True) + + self.assertEqual(supplier.supplier_group, None) + + po = create_purchase_order( + supplier=test_supplier_name, + rate=3000, + item="_Test Non Stock Item", + posting_date="2021-09-15", + ) + + pi = make_purchase_invoice(supplier=test_supplier_name) + + self.assertEqual(po.docstatus, 1) + self.assertEqual(pi.docstatus, 1) + def set_advance_flag(company, flag, default_account): frappe.db.set_value( diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 84b0149942..8aa1f4c103 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -26,6 +26,7 @@ from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_sched from erpnext.controllers.accounts_controller import update_invoice_status from erpnext.controllers.taxes_and_totals import get_itemised_tax_breakup_data from erpnext.exceptions import InvalidAccountCurrency, InvalidCurrency +from erpnext.selling.doctype.customer.test_customer import get_customer_dict from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt @@ -3400,6 +3401,24 @@ class TestSalesInvoice(unittest.TestCase): set_advance_flag(company="_Test Company", flag=0, default_account="") + @change_settings("Selling Settings", {"customer_group": None, "territory": None}) + def test_sales_invoice_without_customer_group_and_territory(self): + # create a customer + if not frappe.db.exists("Customer", "_Test Simple Customer"): + customer_dict = get_customer_dict("_Test Simple Customer") + customer_dict.pop("customer_group") + customer_dict.pop("territory") + customer = frappe.get_doc(customer_dict).insert(ignore_permissions=True) + + self.assertEqual(customer.customer_group, None) + self.assertEqual(customer.territory, None) + + # create a sales invoice + si = create_sales_invoice(customer="_Test Simple Customer") + self.assertEqual(si.docstatus, 1) + self.assertEqual(si.customer_group, None) + self.assertEqual(si.territory, None) + @change_settings("Selling Settings", {"allow_negative_rates_for_items": 0}) def test_sales_return_negative_rate(self): si = create_sales_invoice(is_return=1, qty=-2, rate=-10, do_not_save=True) diff --git a/erpnext/buying/doctype/supplier/supplier.json b/erpnext/buying/doctype/supplier/supplier.json index 19972ca1fa..f37db5f115 100644 --- a/erpnext/buying/doctype/supplier/supplier.json +++ b/erpnext/buying/doctype/supplier/supplier.json @@ -167,8 +167,7 @@ "label": "Supplier Group", "oldfieldname": "supplier_type", "oldfieldtype": "Link", - "options": "Supplier Group", - "reqd": 1 + "options": "Supplier Group" }, { "default": "Company", @@ -486,7 +485,7 @@ "link_fieldname": "party" } ], - "modified": "2023-09-21 12:24:20.398889", + "modified": "2023-09-25 12:48:21.869563", "modified_by": "Administrator", "module": "Buying", "name": "Supplier", diff --git a/erpnext/buying/doctype/supplier/test_supplier.py b/erpnext/buying/doctype/supplier/test_supplier.py index ee2ada3b65..350a25f26e 100644 --- a/erpnext/buying/doctype/supplier/test_supplier.py +++ b/erpnext/buying/doctype/supplier/test_supplier.py @@ -207,11 +207,14 @@ def create_supplier(**args): "doctype": "Supplier", "supplier_name": args.supplier_name, "default_currency": args.default_currency, - "supplier_group": args.supplier_group or "Services", "supplier_type": args.supplier_type or "Company", "tax_withholding_category": args.tax_withholding_category, } - ).insert() + ) + if not args.without_supplier_group: + doc.supplier_group = args.supplier_group or "Services" + + doc.insert() return doc diff --git a/erpnext/selling/doctype/customer/customer.json b/erpnext/selling/doctype/customer/customer.json index 0f42def0bd..40cab9f330 100644 --- a/erpnext/selling/doctype/customer/customer.json +++ b/erpnext/selling/doctype/customer/customer.json @@ -181,7 +181,6 @@ "oldfieldname": "customer_group", "oldfieldtype": "Link", "options": "Customer Group", - "reqd": 1, "search_index": 1 }, { @@ -193,8 +192,7 @@ "oldfieldname": "territory", "oldfieldtype": "Link", "options": "Territory", - "print_hide": 1, - "reqd": 1 + "print_hide": 1 }, { "fieldname": "tax_id", diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index d351c3cc5b..a7a1aa2659 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -15,14 +15,9 @@ from frappe.model.mapper import get_mapped_doc from frappe.model.naming import set_name_by_naming_series, set_name_from_naming_options from frappe.model.utils.rename_doc import update_linked_doctypes from frappe.utils import cint, cstr, flt, get_formatted_email, today -from frappe.utils.nestedset import get_root_of from frappe.utils.user import get_users_with_role -from erpnext.accounts.party import ( # noqa - get_dashboard_info, - get_timeline_data, - validate_party_accounts, -) +from erpnext.accounts.party import get_dashboard_info, validate_party_accounts # noqa from erpnext.controllers.website_list_for_contact import add_role_for_portal_user from erpnext.utilities.transaction_base import TransactionBase @@ -81,7 +76,6 @@ class Customer(TransactionBase): validate_party_accounts(self) self.validate_credit_limit_on_change() self.set_loyalty_program() - self.set_territory_and_group() self.check_customer_group_change() self.validate_default_bank_account() self.validate_internal_customer() @@ -140,12 +134,6 @@ class Customer(TransactionBase): _("{0} is not a company bank account").format(frappe.bold(self.default_bank_account)) ) - def set_territory_and_group(self): - if not self.territory: - self.territory = get_root_of("Territory") - if not self.customer_group: - self.customer_group = get_root_of("Customer Group") - def validate_internal_customer(self): if not self.is_internal_customer: self.represents_company = ""