diff --git a/erpnext/public/js/utils/contact_address_quick_entry.js b/erpnext/public/js/utils/contact_address_quick_entry.js index 137fbf59879c741e216b322268dbb9bb5146d127..952ebdfcfacafe8eaa0a525205e7b28c48462588 100644 --- a/erpnext/public/js/utils/contact_address_quick_entry.js +++ b/erpnext/public/js/utils/contact_address_quick_entry.js @@ -1,37 +1,59 @@ frappe.provide('frappe.ui.form'); frappe.ui.form.ContactAddressQuickEntryForm = class ContactAddressQuickEntryForm extends frappe.ui.form.QuickEntryForm { + map_field_names = { + "email_address": "email_id", + "mobile_number": "mobile_no", + }; + constructor(doctype, after_insert, init_callback, doc, force) { super(doctype, after_insert, init_callback, doc, force); this.skip_redirect_on_error = true; } - render_dialog() { - const me = this; + async render_dialog() { this.mandatory = this.mandatory.concat(this.get_variant_fields()); - // @dokos - this.mandatory.map(m => { + for (const m of this.mandatory) { + // @dokos if (m.fieldname == "company_search") { - m.get_query = function() { + m.get_query = () => { return { query: "erpnext.buying.doctype.supplier.supplier.company_query" }; } - m.onchange = function() { - const selection = this._data.filter(f => f.value == me.dialog.get_value("company_search")) + m.onchange = () => { + const selection = this._data.filter(f => f.value == this.dialog.get_value("company_search")) if (selection.length){ const selected_company = selection[0] - me.dialog.set_values({ + this.dialog.set_values({ customer_name: selected_company.label, siren_number: selected_company.value }) } } } - }) + + // Grab the original df from the doctype definition + if (m.fieldname) { + let fieldname = m.fieldname; + fieldname = this.map_field_names[fieldname] ?? fieldname; + + const dt = m._for_doctype ?? this.doctype; + await frappe.model.with_doctype(dt); + + const original_df = frappe.meta.get_docfield(dt, fieldname); + if (original_df) { + const default_value = frappe.defaults.get_default(fieldname); + Object.assign(m, original_df, { + "depends_on": "", + "default": default_value, + }); + } + } + } super.render_dialog(); } @@ -41,12 +63,7 @@ frappe.ui.form.ContactAddressQuickEntryForm = class ContactAddressQuickEntryForm * Using alias fieldnames because the doctype definition define "email_id" and "mobile_no" as readonly fields. * Therefor, resulting in the fields being "hidden". */ - const map_field_names = { - "email_address": "email_id", - "mobile_number": "mobile_no", - }; - - Object.entries(map_field_names).forEach(([fieldname, new_fieldname]) => { + Object.entries(this.map_field_names).forEach(([fieldname, new_fieldname]) => { this.dialog.doc[new_fieldname] = this.dialog.doc[fieldname]; delete this.dialog.doc[fieldname]; }); @@ -61,6 +78,7 @@ frappe.ui.form.ContactAddressQuickEntryForm = class ContactAddressQuickEntryForm collapsible: 1 }, { + _for_doctype: "Contact", label: __("Email Id"), fieldname: "email_address", fieldtype: "Data", @@ -70,6 +88,7 @@ frappe.ui.form.ContactAddressQuickEntryForm = class ContactAddressQuickEntryForm fieldtype: "Column Break" }, { + _for_doctype: "Contact", label: __("Mobile Number"), fieldname: "mobile_number", fieldtype: "Data" @@ -80,16 +99,19 @@ frappe.ui.form.ContactAddressQuickEntryForm = class ContactAddressQuickEntryForm collapsible: 1 }, { + _for_doctype: "Address", label: __("Address Line 1"), fieldname: "address_line1", fieldtype: "Data" }, { + _for_doctype: "Address", label: __("Address Line 2"), fieldname: "address_line2", fieldtype: "Data" }, { + _for_doctype: "Address", label: __("ZIP Code"), fieldname: "pincode", fieldtype: "Data" @@ -98,16 +120,19 @@ frappe.ui.form.ContactAddressQuickEntryForm = class ContactAddressQuickEntryForm fieldtype: "Column Break" }, { + _for_doctype: "Address", label: __("City"), fieldname: "city", fieldtype: "Data" }, { + _for_doctype: "Address", label: __("State"), fieldname: "state", fieldtype: "Data" }, { + _for_doctype: "Address", label: __("Country"), fieldname: "country", fieldtype: "Link",