From 22bcad9dc75d57381a21dbbf3317c906b0a666fb Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Fri, 16 Oct 2020 15:28:12 +0530 Subject: [PATCH] fix: Cleanup code --- erpnext/accounts/custom/address.py | 34 +++++++++++------------------- erpnext/hooks.py | 4 ++-- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/erpnext/accounts/custom/address.py b/erpnext/accounts/custom/address.py index 2a98df2e26..4894c64a1f 100644 --- a/erpnext/accounts/custom/address.py +++ b/erpnext/accounts/custom/address.py @@ -1,37 +1,27 @@ import frappe from frappe import _ from frappe.contacts.doctype.address.address import Address -from frappe.contacts.address_and_contact import set_link_title -from frappe.core.doctype.dynamic_link.dynamic_link import deduplicate_dynamic_links from frappe.contacts.doctype.address.address import get_address_templates -class CustomAddress(Address): +class ERPNextAddress(Address): def validate(self): - self.link_address() self.validate_reference() - super(CustomAddress, self).validate_preferred_address() - set_link_title(self) - deduplicate_dynamic_links(self) + super(ERPNextAddress, self).validate() def link_address(self): """Link address based on owner""" - if not self.links and not self.is_your_company_address: - contact_name = frappe.db.get_value("Contact", {"email_id": self.owner}) - if contact_name: - contact = frappe.get_cached_doc('Contact', contact_name) - print('here', str(contact)) - for link in contact.links: - self.append('links', dict(link_doctype=link.link_doctype, link_name=link.link_name)) - return True - return False + if not self.is_your_company_address: + return + + return super(ERPNextAddress, self).link_address() def validate_reference(self): - if self.is_your_company_address: - print('here') - if not [row for row in self.links if row.link_doctype == "Company"]: - frappe.throw(_("Address needs to be linked to a Company. Please add a row for Company in the Links table below."), - title =_("Company not Linked")) - + if self.is_your_company_address and not [ + row for row in self.links if row.link_doctype == "Company" + ]: + frappe.throw(_("Address needs to be linked to a Company. Please add a row for Company in the Links table."), + title=_("Company Not Linked")) + @frappe.whitelist() def get_shipping_address(company, address = None): filters = [ diff --git a/erpnext/hooks.py b/erpnext/hooks.py index fb93df8b03..9bd31050c4 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -28,7 +28,7 @@ doctype_js = { } override_doctype_class = { - 'Address': 'erpnext.accounts.custom.address.CustomAddress' + 'Address': 'erpnext.accounts.custom.address.ERPNextAddress' } welcome_email = "erpnext.setup.utils.welcome_email" @@ -566,4 +566,4 @@ global_search_doctypes = { {'doctype': 'Hotel Room Package', 'index': 3}, {'doctype': 'Hotel Room Type', 'index': 4} ] -} \ No newline at end of file +}