mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 16:04:46 +00:00
Merge pull request #27197 from marination/supplier-primary-address
feat: (consistency) Add Primary Address and Contact section in Supplier
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) {
|
refresh: function (frm) {
|
||||||
frappe.dynamic_link = { doc: frm.doc, fieldname: 'name', doctype: 'Supplier' }
|
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) {
|
is_internal_supplier: function(frm) {
|
||||||
if (frm.doc.is_internal_supplier == 1) {
|
if (frm.doc.is_internal_supplier == 1) {
|
||||||
frm.toggle_reqd("represents_company", true);
|
frm.toggle_reqd("represents_company", true);
|
||||||
|
|||||||
@@ -49,6 +49,13 @@
|
|||||||
"address_html",
|
"address_html",
|
||||||
"column_break1",
|
"column_break1",
|
||||||
"contact_html",
|
"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",
|
"default_payable_accounts",
|
||||||
"accounts",
|
"accounts",
|
||||||
"default_tax_withholding_config",
|
"default_tax_withholding_config",
|
||||||
@@ -378,6 +385,47 @@
|
|||||||
"fieldname": "allow_purchase_invoice_creation_without_purchase_receipt",
|
"fieldname": "allow_purchase_invoice_creation_without_purchase_receipt",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Allow Purchase Invoice Creation Without Purchase Receipt"
|
"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",
|
"icon": "fa fa-user",
|
||||||
@@ -390,7 +438,7 @@
|
|||||||
"link_fieldname": "supplier"
|
"link_fieldname": "supplier"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2021-05-18 15:10:11.087191",
|
"modified": "2021-08-27 18:02:44.314077",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Supplier",
|
"name": "Supplier",
|
||||||
|
|||||||
@@ -42,7 +42,12 @@ class Supplier(TransactionBase):
|
|||||||
if not self.naming_series:
|
if not self.naming_series:
|
||||||
self.naming_series = ''
|
self.naming_series = ''
|
||||||
|
|
||||||
|
self.create_primary_contact()
|
||||||
|
self.create_primary_address()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
self.flags.is_new_doc = self.is_new()
|
||||||
|
|
||||||
# validation for Naming Series mandatory field...
|
# validation for Naming Series mandatory field...
|
||||||
if frappe.defaults.get_global_default('supp_master_name') == 'Naming Series':
|
if frappe.defaults.get_global_default('supp_master_name') == 'Naming Series':
|
||||||
if not self.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.throw(_("Internal Supplier for company {0} already exists").format(
|
||||||
frappe.bold(self.represents_company)))
|
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):
|
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)
|
delete_contact_and_address('Supplier', self.name)
|
||||||
|
|
||||||
def after_rename(self, olddn, newdn, merge=False):
|
def after_rename(self, olddn, newdn, merge=False):
|
||||||
@@ -104,3 +141,21 @@ class Supplier(TransactionBase):
|
|||||||
doc.name, args.get('supplier_email_' + str(i)))
|
doc.name, args.get('supplier_email_' + str(i)))
|
||||||
except frappe.NameError:
|
except frappe.NameError:
|
||||||
pass
|
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/templates/item_quick_entry.html",
|
||||||
"public/js/utils/item_quick_entry.js",
|
"public/js/utils/item_quick_entry.js",
|
||||||
"public/js/utils/customer_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/student_button.html",
|
||||||
"public/js/education/assessment_result_tool.html",
|
"public/js/education/assessment_result_tool.html",
|
||||||
"public/js/hub/hub_factory.js",
|
"public/js/hub/hub_factory.js",
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import "./agriculture/ternary_plot";
|
|||||||
import "./templates/item_quick_entry.html";
|
import "./templates/item_quick_entry.html";
|
||||||
import "./utils/item_quick_entry";
|
import "./utils/item_quick_entry";
|
||||||
import "./utils/customer_quick_entry";
|
import "./utils/customer_quick_entry";
|
||||||
|
import "./utils/supplier_quick_entry";
|
||||||
import "./education/student_button.html";
|
import "./education/student_button.html";
|
||||||
import "./education/assessment_result_tool.html";
|
import "./education/assessment_result_tool.html";
|
||||||
import "./hub/hub_factory";
|
import "./hub/hub_factory";
|
||||||
|
|||||||
77
erpnext/public/js/utils/supplier_quick_entry.js
Normal file
77
erpnext/public/js/utils/supplier_quick_entry.js
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -150,8 +150,14 @@ class Customer(TransactionBase):
|
|||||||
self.db_set('email_id', self.email_id)
|
self.db_set('email_id', self.email_id)
|
||||||
|
|
||||||
def create_primary_address(self):
|
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'):
|
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):
|
def update_lead_status(self):
|
||||||
'''If Customer created from Lead, update lead status to "Converted"
|
'''If Customer created from Lead, update lead status to "Converted"
|
||||||
@@ -246,9 +252,15 @@ class Customer(TransactionBase):
|
|||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
if self.customer_primary_contact:
|
if self.customer_primary_contact:
|
||||||
frappe.db.sql("""update `tabCustomer`
|
frappe.db.sql("""
|
||||||
set customer_primary_contact=null, mobile_no=null, email_id=null
|
UPDATE `tabCustomer`
|
||||||
where name=%s""", self.name)
|
SET
|
||||||
|
customer_primary_contact=null,
|
||||||
|
customer_primary_address=null,
|
||||||
|
mobile_no=null,
|
||||||
|
email_id=null,
|
||||||
|
primary_address=null
|
||||||
|
WHERE name=%(name)s""", {"name": self.name})
|
||||||
|
|
||||||
delete_contact_and_address('Customer', self.name)
|
delete_contact_and_address('Customer', self.name)
|
||||||
if self.lead_name:
|
if self.lead_name:
|
||||||
|
|||||||
Reference in New Issue
Block a user