From 2a3ef03388c4581550a247e2dbe99d8ca496883c Mon Sep 17 00:00:00 2001 From: marination Date: Fri, 27 Aug 2021 18:06:51 +0530 Subject: [PATCH] fix: Popup stale build and data consistency - Include `supplier_quick_entry.js` in erpnext.bundle.js - Create primary supplier address on update - Set newly created address (quick entry) in Supplier and Customer - Clear address set in supplier and customer on delete (dependency) --- erpnext/buying/doctype/supplier/supplier.json | 3 +-- erpnext/buying/doctype/supplier/supplier.py | 14 +++++++++++-- erpnext/public/js/erpnext.bundle.js | 1 + .../public/js/utils/supplier_quick_entry.js | 3 ++- erpnext/selling/doctype/customer/customer.py | 20 +++++++++++++++---- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/erpnext/buying/doctype/supplier/supplier.json b/erpnext/buying/doctype/supplier/supplier.json index 22e689c1017..c7a5db59941 100644 --- a/erpnext/buying/doctype/supplier/supplier.json +++ b/erpnext/buying/doctype/supplier/supplier.json @@ -399,7 +399,6 @@ "options": "Contact" }, { - "depends_on": "mobile_no", "fetch_from": "supplier_primary_contact.mobile_no", "fieldname": "mobile_no", "fieldtype": "Read Only", @@ -439,7 +438,7 @@ "link_fieldname": "supplier" } ], - "modified": "2021-08-27 13:46:18.212802", + "modified": "2021-08-27 18:02:44.314077", "modified_by": "Administrator", "module": "Buying", "name": "Supplier", diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index 8252b40566a..207485e1bca 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -43,8 +43,11 @@ class Supplier(TransactionBase): self.naming_series = '' self.create_primary_contact() + self.create_primary_address() def validate(self): + self.flags.is_new_doc = self.is_new() + # validation for Naming Series mandatory field... if frappe.defaults.get_global_default('supp_master_name') == 'Naming Series': if not self.naming_series: @@ -90,9 +93,14 @@ class Supplier(TransactionBase): def create_primary_address(self): from erpnext.selling.doctype.customer.customer import make_address + from frappe.contacts.doctype.address.address import get_address_display if self.flags.is_new_doc and self.get('address_line1'): - make_address(self) + address = make_address(self) + address_display = get_address_display(address.name) + + self.db_set("supplier_primary_address", address.name) + self.db_set("primary_address", address_display) def on_trash(self): if self.supplier_primary_contact: @@ -100,8 +108,10 @@ class Supplier(TransactionBase): UPDATE `tabSupplier` SET supplier_primary_contact=null, + supplier_primary_address=null, mobile_no=null, - email_id=null + email_id=null, + primary_address=null WHERE name='{self.name}'""") delete_contact_and_address('Supplier', self.name) diff --git a/erpnext/public/js/erpnext.bundle.js b/erpnext/public/js/erpnext.bundle.js index 9f7f29ad72b..febdb24da34 100644 --- a/erpnext/public/js/erpnext.bundle.js +++ b/erpnext/public/js/erpnext.bundle.js @@ -15,6 +15,7 @@ import "./agriculture/ternary_plot"; import "./templates/item_quick_entry.html"; import "./utils/item_quick_entry"; import "./utils/customer_quick_entry"; +import "./utils/supplier_quick_entry"; import "./education/student_button.html"; import "./education/assessment_result_tool.html"; import "./hub/hub_factory"; diff --git a/erpnext/public/js/utils/supplier_quick_entry.js b/erpnext/public/js/utils/supplier_quick_entry.js index f650d1f1011..e4a3812cf48 100644 --- a/erpnext/public/js/utils/supplier_quick_entry.js +++ b/erpnext/public/js/utils/supplier_quick_entry.js @@ -12,7 +12,8 @@ frappe.ui.form.SupplierQuickEntryForm = class SupplierQuickEntryForm extends fra } get_variant_fields() { - var variant_fields = [{ + var variant_fields = [ + { fieldtype: "Section Break", label: __("Primary Contact Details"), collapsible: 1 diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index abf146c43f4..05cabcbbe23 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -150,8 +150,14 @@ class Customer(TransactionBase): self.db_set('email_id', self.email_id) def create_primary_address(self): + from frappe.contacts.doctype.address.address import get_address_display + if self.flags.is_new_doc and self.get('address_line1'): - make_address(self) + address = make_address(self) + address_display = get_address_display(address.name) + + self.db_set("customer_primary_address", address.name) + self.db_set("primary_address", address_display) def update_lead_status(self): '''If Customer created from Lead, update lead status to "Converted" @@ -246,9 +252,15 @@ class Customer(TransactionBase): def on_trash(self): if self.customer_primary_contact: - frappe.db.sql("""update `tabCustomer` - set customer_primary_contact=null, mobile_no=null, email_id=null - where name=%s""", self.name) + frappe.db.sql(f""" + UPDATE `tabCustomer` + SET + customer_primary_contact=null, + customer_primary_address=null, + mobile_no=null, + email_id=null, + primary_address=null + WHERE name='{self.name}'""") delete_contact_and_address('Customer', self.name) if self.lead_name: