Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: customer group and territory not mandatory #37050

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,32 @@ def test_repost_accounting_entries(self):
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(
Expand Down
19 changes: 19 additions & 0 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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
Expand Down Expand Up @@ -3400,6 +3401,24 @@ def test_advance_entries_as_liability(self):

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)
Expand Down
5 changes: 2 additions & 3 deletions erpnext/buying/doctype/supplier/supplier.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@
"label": "Supplier Group",
"oldfieldname": "supplier_type",
"oldfieldtype": "Link",
"options": "Supplier Group",
"reqd": 1
"options": "Supplier Group"
},
{
"default": "Company",
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions erpnext/buying/doctype/supplier/test_supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions erpnext/selling/doctype/customer/customer.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@
"oldfieldname": "customer_group",
"oldfieldtype": "Link",
"options": "Customer Group",
"reqd": 1,
"search_index": 1
},
{
Expand All @@ -193,8 +192,7 @@
"oldfieldname": "territory",
"oldfieldtype": "Link",
"options": "Territory",
"print_hide": 1,
"reqd": 1
"print_hide": 1
},
{
"fieldname": "tax_id",
Expand Down
14 changes: 1 addition & 13 deletions erpnext/selling/doctype/customer/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@
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

Expand Down Expand Up @@ -81,7 +76,6 @@ def validate(self):
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()
Expand Down Expand Up @@ -140,12 +134,6 @@ def validate_default_bank_account(self):
_("{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 = ""
Expand Down