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
This commit is contained in:
parent
71b7c63ec0
commit
bf72ec0598
@ -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,48 @@
|
||||
"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"
|
||||
},
|
||||
{
|
||||
"depends_on": "mobile_no",
|
||||
"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 +439,7 @@
|
||||
"link_fieldname": "supplier"
|
||||
}
|
||||
],
|
||||
"modified": "2021-05-18 15:10:11.087191",
|
||||
"modified": "2021-08-27 13:46:18.212802",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Supplier",
|
||||
|
@ -42,6 +42,8 @@ class Supplier(TransactionBase):
|
||||
if not self.naming_series:
|
||||
self.naming_series = ''
|
||||
|
||||
self.create_primary_contact()
|
||||
|
||||
def validate(self):
|
||||
# validation for Naming Series mandatory field...
|
||||
if frappe.defaults.get_global_default('supp_master_name') == 'Naming Series':
|
||||
@ -76,7 +78,32 @@ 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
|
||||
|
||||
if self.flags.is_new_doc and self.get('address_line1'):
|
||||
make_address(self)
|
||||
|
||||
def on_trash(self):
|
||||
if self.supplier_primary_contact:
|
||||
frappe.db.sql(f"""
|
||||
UPDATE `tabSupplier`
|
||||
SET
|
||||
supplier_primary_contact=null,
|
||||
mobile_no=null,
|
||||
email_id=null
|
||||
WHERE name='{self.name}'""")
|
||||
|
||||
delete_contact_and_address('Supplier', self.name)
|
||||
|
||||
def after_rename(self, olddn, newdn, merge=False):
|
||||
@ -104,3 +131,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
|
||||
})
|
||||
|
@ -38,6 +38,7 @@
|
||||
"public/js/templates/item_quick_entry.html",
|
||||
"public/js/utils/item_quick_entry.js",
|
||||
"public/js/utils/customer_quick_entry.js",
|
||||
"public/js/utils/supplier_quick_entry.js",
|
||||
"public/js/education/student_button.html",
|
||||
"public/js/education/assessment_result_tool.html",
|
||||
"public/js/hub/hub_factory.js",
|
||||
|
75
erpnext/public/js/utils/supplier_quick_entry.js
Normal file
75
erpnext/public/js/utils/supplier_quick_entry.js
Normal file
@ -0,0 +1,75 @@
|
||||
frappe.provide('frappe.ui.form');
|
||||
|
||||
frappe.ui.form.SupplierQuickEntryForm = class SupplierQuickEntryForm extends frappe.ui.form.QuickEntryForm {
|
||||
constructor(doctype, after_insert, init_callback, doc, force) {
|
||||
super(doctype, after_insert, init_callback, doc, force);
|
||||
this.skip_redirect_on_error = true;
|
||||
}
|
||||
|
||||
render_dialog() {
|
||||
this.mandatory = this.mandatory.concat(this.get_variant_fields());
|
||||
super.render_dialog();
|
||||
}
|
||||
|
||||
get_variant_fields() {
|
||||
var variant_fields = [{
|
||||
fieldtype: "Section Break",
|
||||
label: __("Primary Contact Details"),
|
||||
collapsible: 1
|
||||
},
|
||||
{
|
||||
label: __("Email Id"),
|
||||
fieldname: "email_id",
|
||||
fieldtype: "Data"
|
||||
},
|
||||
{
|
||||
fieldtype: "Column Break"
|
||||
},
|
||||
{
|
||||
label: __("Mobile Number"),
|
||||
fieldname: "mobile_no",
|
||||
fieldtype: "Data"
|
||||
},
|
||||
{
|
||||
fieldtype: "Section Break",
|
||||
label: __("Primary Address Details"),
|
||||
collapsible: 1
|
||||
},
|
||||
{
|
||||
label: __("Address Line 1"),
|
||||
fieldname: "address_line1",
|
||||
fieldtype: "Data"
|
||||
},
|
||||
{
|
||||
label: __("Address Line 2"),
|
||||
fieldname: "address_line2",
|
||||
fieldtype: "Data"
|
||||
},
|
||||
{
|
||||
label: __("ZIP Code"),
|
||||
fieldname: "pincode",
|
||||
fieldtype: "Data"
|
||||
},
|
||||
{
|
||||
fieldtype: "Column Break"
|
||||
},
|
||||
{
|
||||
label: __("City"),
|
||||
fieldname: "city",
|
||||
fieldtype: "Data"
|
||||
},
|
||||
{
|
||||
label: __("State"),
|
||||
fieldname: "state",
|
||||
fieldtype: "Data"
|
||||
},
|
||||
{
|
||||
label: __("Country"),
|
||||
fieldname: "country",
|
||||
fieldtype: "Link",
|
||||
options: "Country"
|
||||
}];
|
||||
|
||||
return variant_fields;
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user