mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 21:59:13 +00:00
* feat: (consistency) Add Primary Address and Contact section in Supplier
- The same is present in customer and is inconsistent with supplier
- Helps quickly create primary address and contact via quick entry
* 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)
* fix: Indentation and removed f-strings
- Sider: fixed indentation in js
- Dont use f-strings in queries
(cherry picked from commit 3d87d9f1d3)
Co-authored-by: Marica <maricadsouza221197@gmail.com>
This commit is contained in:
@@ -24,7 +24,26 @@ frappe.ui.form.on("Supplier", {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
frm.set_query("supplier_primary_contact", function(doc) {
|
||||
return {
|
||||
query: "erpnext.buying.doctype.supplier.supplier.get_supplier_primary_contact",
|
||||
filters: {
|
||||
"supplier": doc.name
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("supplier_primary_address", function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
"link_doctype": "Supplier",
|
||||
"link_name": doc.name
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
refresh: function (frm) {
|
||||
frappe.dynamic_link = { doc: frm.doc, fieldname: 'name', doctype: 'Supplier' }
|
||||
|
||||
@@ -78,6 +97,30 @@ frappe.ui.form.on("Supplier", {
|
||||
});
|
||||
},
|
||||
|
||||
supplier_primary_address: function(frm) {
|
||||
if (frm.doc.supplier_primary_address) {
|
||||
frappe.call({
|
||||
method: 'frappe.contacts.doctype.address.address.get_address_display',
|
||||
args: {
|
||||
"address_dict": frm.doc.supplier_primary_address
|
||||
},
|
||||
callback: function(r) {
|
||||
frm.set_value("primary_address", r.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!frm.doc.supplier_primary_address) {
|
||||
frm.set_value("primary_address", "");
|
||||
}
|
||||
},
|
||||
|
||||
supplier_primary_contact: function(frm) {
|
||||
if (!frm.doc.supplier_primary_contact) {
|
||||
frm.set_value("mobile_no", "");
|
||||
frm.set_value("email_id", "");
|
||||
}
|
||||
},
|
||||
|
||||
is_internal_supplier: function(frm) {
|
||||
if (frm.doc.is_internal_supplier == 1) {
|
||||
frm.toggle_reqd("represents_company", true);
|
||||
|
||||
@@ -49,6 +49,13 @@
|
||||
"address_html",
|
||||
"column_break1",
|
||||
"contact_html",
|
||||
"primary_address_and_contact_detail_section",
|
||||
"supplier_primary_contact",
|
||||
"mobile_no",
|
||||
"email_id",
|
||||
"column_break_44",
|
||||
"supplier_primary_address",
|
||||
"primary_address",
|
||||
"default_payable_accounts",
|
||||
"accounts",
|
||||
"default_tax_withholding_config",
|
||||
@@ -378,6 +385,47 @@
|
||||
"fieldname": "allow_purchase_invoice_creation_without_purchase_receipt",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow Purchase Invoice Creation Without Purchase Receipt"
|
||||
},
|
||||
{
|
||||
"fieldname": "primary_address_and_contact_detail_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Primary Address and Contact Detail"
|
||||
},
|
||||
{
|
||||
"description": "Reselect, if the chosen contact is edited after save",
|
||||
"fieldname": "supplier_primary_contact",
|
||||
"fieldtype": "Link",
|
||||
"label": "Supplier Primary Contact",
|
||||
"options": "Contact"
|
||||
},
|
||||
{
|
||||
"fetch_from": "supplier_primary_contact.mobile_no",
|
||||
"fieldname": "mobile_no",
|
||||
"fieldtype": "Read Only",
|
||||
"label": "Mobile No"
|
||||
},
|
||||
{
|
||||
"fetch_from": "supplier_primary_contact.email_id",
|
||||
"fieldname": "email_id",
|
||||
"fieldtype": "Read Only",
|
||||
"label": "Email Id"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_44",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "primary_address",
|
||||
"fieldtype": "Text",
|
||||
"label": "Primary Address",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"description": "Reselect, if the chosen address is edited after save",
|
||||
"fieldname": "supplier_primary_address",
|
||||
"fieldtype": "Link",
|
||||
"label": "Supplier Primary Address",
|
||||
"options": "Address"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-user",
|
||||
@@ -390,7 +438,7 @@
|
||||
"link_fieldname": "supplier"
|
||||
}
|
||||
],
|
||||
"modified": "2021-05-18 15:10:11.087191",
|
||||
"modified": "2021-08-27 18:02:44.314077",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Supplier",
|
||||
|
||||
@@ -42,7 +42,12 @@ class Supplier(TransactionBase):
|
||||
if not self.naming_series:
|
||||
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:
|
||||
@@ -76,7 +81,39 @@ class Supplier(TransactionBase):
|
||||
frappe.throw(_("Internal Supplier for company {0} already exists").format(
|
||||
frappe.bold(self.represents_company)))
|
||||
|
||||
def create_primary_contact(self):
|
||||
from erpnext.selling.doctype.customer.customer import make_contact
|
||||
|
||||
if not self.supplier_primary_contact:
|
||||
if self.mobile_no or self.email_id:
|
||||
contact = make_contact(self)
|
||||
self.db_set('supplier_primary_contact', contact.name)
|
||||
self.db_set('mobile_no', self.mobile_no)
|
||||
self.db_set('email_id', self.email_id)
|
||||
|
||||
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'):
|
||||
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("""
|
||||
UPDATE `tabSupplier`
|
||||
SET
|
||||
supplier_primary_contact=null,
|
||||
supplier_primary_address=null,
|
||||
mobile_no=null,
|
||||
email_id=null,
|
||||
primary_address=null
|
||||
WHERE name=%(name)s""", {"name": self.name})
|
||||
|
||||
delete_contact_and_address('Supplier', self.name)
|
||||
|
||||
def after_rename(self, olddn, newdn, merge=False):
|
||||
@@ -104,3 +141,21 @@ class Supplier(TransactionBase):
|
||||
doc.name, args.get('supplier_email_' + str(i)))
|
||||
except frappe.NameError:
|
||||
pass
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_supplier_primary_contact(doctype, txt, searchfield, start, page_len, filters):
|
||||
supplier = filters.get("supplier")
|
||||
return frappe.db.sql("""
|
||||
SELECT
|
||||
`tabContact`.name from `tabContact`,
|
||||
`tabDynamic Link`
|
||||
WHERE
|
||||
`tabContact`.name = `tabDynamic Link`.parent
|
||||
and `tabDynamic Link`.link_name = %(supplier)s
|
||||
and `tabDynamic Link`.link_doctype = 'Supplier'
|
||||
and `tabContact`.name like %(txt)s
|
||||
""", {
|
||||
'supplier': supplier,
|
||||
'txt': '%%%s%%' % txt
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user