Skip to content

Commit

Permalink
fix: Popup stale build and data consistency
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
marination authored and ahmadpak committed Aug 30, 2021
1 parent 44eda22 commit 770cdc2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
3 changes: 1 addition & 2 deletions erpnext/buying/doctype/supplier/supplier.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@
"options": "Contact"
},
{
"depends_on": "mobile_no",
"fetch_from": "supplier_primary_contact.mobile_no",
"fieldname": "mobile_no",
"fieldtype": "Read Only",
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions erpnext/buying/doctype/supplier/supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def on_update(self):
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:
Expand Down Expand Up @@ -90,18 +93,25 @@ def create_primary_contact(self):

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:
frappe.db.sql(f"""
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)
Expand Down
1 change: 1 addition & 0 deletions erpnext/public/js/erpnext.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion erpnext/public/js/utils/supplier_quick_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions erpnext/selling/doctype/customer/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,14 @@ def create_primary_contact(self):
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"
Expand Down Expand Up @@ -246,9 +252,15 @@ def validate_credit_limit_on_change(self):

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:
Expand Down

0 comments on commit 770cdc2

Please sign in to comment.