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 <deepeshgarg6@gmail.com>
This commit is contained in:
parent
c9dfb909a5
commit
2c899dd13a
@ -218,6 +218,7 @@ def make_customer(customer=None):
|
|||||||
"territory": "All Territories",
|
"territory": "All Territories",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if not frappe.db.exists("Customer", customer_name):
|
if not frappe.db.exists("Customer", customer_name):
|
||||||
customer.insert(ignore_permissions=True)
|
customer.insert(ignore_permissions=True)
|
||||||
return customer.name
|
return customer.name
|
||||||
|
@ -1916,6 +1916,32 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
|||||||
pi.load_from_db()
|
pi.load_from_db()
|
||||||
self.assertFalse(pi.repost_required)
|
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):
|
def set_advance_flag(company, flag, default_account):
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
|
@ -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.accounts_controller import update_invoice_status
|
||||||
from erpnext.controllers.taxes_and_totals import get_itemised_tax_breakup_data
|
from erpnext.controllers.taxes_and_totals import get_itemised_tax_breakup_data
|
||||||
from erpnext.exceptions import InvalidAccountCurrency, InvalidCurrency
|
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.delivery_note.delivery_note import make_sales_invoice
|
||||||
from erpnext.stock.doctype.item.test_item import create_item
|
from erpnext.stock.doctype.item.test_item import create_item
|
||||||
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
|
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="")
|
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})
|
@change_settings("Selling Settings", {"allow_negative_rates_for_items": 0})
|
||||||
def test_sales_return_negative_rate(self):
|
def test_sales_return_negative_rate(self):
|
||||||
si = create_sales_invoice(is_return=1, qty=-2, rate=-10, do_not_save=True)
|
si = create_sales_invoice(is_return=1, qty=-2, rate=-10, do_not_save=True)
|
||||||
|
@ -167,8 +167,7 @@
|
|||||||
"label": "Supplier Group",
|
"label": "Supplier Group",
|
||||||
"oldfieldname": "supplier_type",
|
"oldfieldname": "supplier_type",
|
||||||
"oldfieldtype": "Link",
|
"oldfieldtype": "Link",
|
||||||
"options": "Supplier Group",
|
"options": "Supplier Group"
|
||||||
"reqd": 1
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "Company",
|
"default": "Company",
|
||||||
@ -486,7 +485,7 @@
|
|||||||
"link_fieldname": "party"
|
"link_fieldname": "party"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2023-09-21 12:24:20.398889",
|
"modified": "2023-09-25 12:48:21.869563",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Supplier",
|
"name": "Supplier",
|
||||||
|
@ -207,11 +207,14 @@ def create_supplier(**args):
|
|||||||
"doctype": "Supplier",
|
"doctype": "Supplier",
|
||||||
"supplier_name": args.supplier_name,
|
"supplier_name": args.supplier_name,
|
||||||
"default_currency": args.default_currency,
|
"default_currency": args.default_currency,
|
||||||
"supplier_group": args.supplier_group or "Services",
|
|
||||||
"supplier_type": args.supplier_type or "Company",
|
"supplier_type": args.supplier_type or "Company",
|
||||||
"tax_withholding_category": args.tax_withholding_category,
|
"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
|
return doc
|
||||||
|
|
||||||
|
@ -181,7 +181,6 @@
|
|||||||
"oldfieldname": "customer_group",
|
"oldfieldname": "customer_group",
|
||||||
"oldfieldtype": "Link",
|
"oldfieldtype": "Link",
|
||||||
"options": "Customer Group",
|
"options": "Customer Group",
|
||||||
"reqd": 1,
|
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -193,8 +192,7 @@
|
|||||||
"oldfieldname": "territory",
|
"oldfieldname": "territory",
|
||||||
"oldfieldtype": "Link",
|
"oldfieldtype": "Link",
|
||||||
"options": "Territory",
|
"options": "Territory",
|
||||||
"print_hide": 1,
|
"print_hide": 1
|
||||||
"reqd": 1
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "tax_id",
|
"fieldname": "tax_id",
|
||||||
|
@ -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.naming import set_name_by_naming_series, set_name_from_naming_options
|
||||||
from frappe.model.utils.rename_doc import update_linked_doctypes
|
from frappe.model.utils.rename_doc import update_linked_doctypes
|
||||||
from frappe.utils import cint, cstr, flt, get_formatted_email, today
|
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 frappe.utils.user import get_users_with_role
|
||||||
|
|
||||||
from erpnext.accounts.party import ( # noqa
|
from erpnext.accounts.party import get_dashboard_info, validate_party_accounts # noqa
|
||||||
get_dashboard_info,
|
|
||||||
get_timeline_data,
|
|
||||||
validate_party_accounts,
|
|
||||||
)
|
|
||||||
from erpnext.controllers.website_list_for_contact import add_role_for_portal_user
|
from erpnext.controllers.website_list_for_contact import add_role_for_portal_user
|
||||||
from erpnext.utilities.transaction_base import TransactionBase
|
from erpnext.utilities.transaction_base import TransactionBase
|
||||||
|
|
||||||
@ -81,7 +76,6 @@ class Customer(TransactionBase):
|
|||||||
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()
|
||||||
self.set_territory_and_group()
|
|
||||||
self.check_customer_group_change()
|
self.check_customer_group_change()
|
||||||
self.validate_default_bank_account()
|
self.validate_default_bank_account()
|
||||||
self.validate_internal_customer()
|
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))
|
_("{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):
|
def validate_internal_customer(self):
|
||||||
if not self.is_internal_customer:
|
if not self.is_internal_customer:
|
||||||
self.represents_company = ""
|
self.represents_company = ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user