diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index c5963b9f114..3011fd68c76 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -192,6 +192,15 @@ def get_party_account_currency(party_type, party, company): return frappe.local_cache("party_account_currency", (party_type, party, company), generator) +def validate_party_accounts(doc): + companies = [] + + for account in doc.get("accounts"): + if account.company in companies: + frappe.throw(_("There can only be 1 Account per Company in {0} {1}").format(doc.doctype, doc.name)) + else: + companies.append(account.company) + @frappe.whitelist() def get_due_date(posting_date, party_type, party, company): """Set Due Date = Posting Date + Credit Days""" diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index e3a5541bbea..6ae0a2ea511 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -8,6 +8,7 @@ from frappe import msgprint, _ from frappe.model.naming import make_autoname from erpnext.utilities.address_and_contact import load_address_and_contact from erpnext.utilities.transaction_base import TransactionBase +from erpnext.accounts.party import validate_party_accounts class Supplier(TransactionBase): def get_feed(self): @@ -45,6 +46,8 @@ class Supplier(TransactionBase): if not self.naming_series: msgprint(_("Series is mandatory"), raise_exception=1) + validate_party_accounts(self) + def get_contacts(self,nm): if nm: contact_details =frappe.db.convert_to_lists(frappe.db.sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = %s", nm)) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index bb15a3ec673..9e5e7bdc7ed 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -7,10 +7,10 @@ from frappe.model.naming import make_autoname from frappe import _, msgprint, throw import frappe.defaults from frappe.utils import flt - +from frappe.desk.reportview import build_match_conditions from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.address_and_contact import load_address_and_contact -from frappe.desk.reportview import build_match_conditions +from erpnext.accounts.party import validate_party_accounts class Customer(TransactionBase): def get_feed(self): @@ -32,6 +32,7 @@ class Customer(TransactionBase): def validate(self): self.flags.is_new_doc = self.is_new() + validate_party_accounts(self) def update_lead_status(self): if self.lead_name: