Merge pull request #23640 from abhishekbalam/address_customisation
This commit is contained in:
commit
c6f4e84a45
@ -1,58 +1,126 @@
|
|||||||
{
|
{
|
||||||
"custom_fields": [
|
"custom_fields": [
|
||||||
{
|
{
|
||||||
"_assign": null,
|
"_assign": null,
|
||||||
"_comments": null,
|
"_comments": null,
|
||||||
"_liked_by": null,
|
"_liked_by": null,
|
||||||
"_user_tags": null,
|
"_user_tags": null,
|
||||||
"allow_on_submit": 0,
|
"allow_in_quick_entry": 0,
|
||||||
"bold": 0,
|
"allow_on_submit": 0,
|
||||||
"collapsible": 0,
|
"bold": 0,
|
||||||
"collapsible_depends_on": null,
|
"collapsible": 0,
|
||||||
"columns": 0,
|
"collapsible_depends_on": null,
|
||||||
"creation": "2018-12-28 22:29:21.828090",
|
"columns": 0,
|
||||||
"default": null,
|
"creation": "2018-12-28 22:29:21.828090",
|
||||||
"depends_on": null,
|
"default": null,
|
||||||
"description": null,
|
"depends_on": null,
|
||||||
"docstatus": 0,
|
"description": null,
|
||||||
"dt": "Address",
|
"docstatus": 0,
|
||||||
"fetch_from": null,
|
"dt": "Address",
|
||||||
"fieldname": "tax_category",
|
"fetch_from": null,
|
||||||
"fieldtype": "Link",
|
"fetch_if_empty": 0,
|
||||||
"hidden": 0,
|
"fieldname": "tax_category",
|
||||||
"idx": 14,
|
"fieldtype": "Link",
|
||||||
"ignore_user_permissions": 0,
|
"hidden": 0,
|
||||||
"ignore_xss_filter": 0,
|
"hide_border": 0,
|
||||||
"in_global_search": 0,
|
"hide_days": 0,
|
||||||
"in_list_view": 0,
|
"hide_seconds": 0,
|
||||||
"in_standard_filter": 0,
|
"idx": 15,
|
||||||
"insert_after": "fax",
|
"ignore_user_permissions": 0,
|
||||||
"label": "Tax Category",
|
"ignore_xss_filter": 0,
|
||||||
"modified": "2018-12-28 22:29:21.828090",
|
"in_global_search": 0,
|
||||||
"modified_by": "Administrator",
|
"in_list_view": 0,
|
||||||
"name": "Address-tax_category",
|
"in_preview": 0,
|
||||||
"no_copy": 0,
|
"in_standard_filter": 0,
|
||||||
"options": "Tax Category",
|
"insert_after": "fax",
|
||||||
"owner": "Administrator",
|
"label": "Tax Category",
|
||||||
"parent": null,
|
"length": 0,
|
||||||
"parentfield": null,
|
"mandatory_depends_on": null,
|
||||||
"parenttype": null,
|
"modified": "2018-12-28 22:29:21.828090",
|
||||||
"permlevel": 0,
|
"modified_by": "Administrator",
|
||||||
"precision": "",
|
"name": "Address-tax_category",
|
||||||
"print_hide": 0,
|
"no_copy": 0,
|
||||||
"print_hide_if_no_value": 0,
|
"options": "Tax Category",
|
||||||
"print_width": null,
|
"owner": "Administrator",
|
||||||
"read_only": 0,
|
"parent": null,
|
||||||
"report_hide": 0,
|
"parentfield": null,
|
||||||
"reqd": 0,
|
"parenttype": null,
|
||||||
"search_index": 0,
|
"permlevel": 0,
|
||||||
"translatable": 0,
|
"precision": "",
|
||||||
"unique": 0,
|
"print_hide": 0,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"print_width": null,
|
||||||
|
"read_only": 0,
|
||||||
|
"read_only_depends_on": null,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"translatable": 0,
|
||||||
|
"unique": 0,
|
||||||
|
"width": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_assign": null,
|
||||||
|
"_comments": null,
|
||||||
|
"_liked_by": null,
|
||||||
|
"_user_tags": null,
|
||||||
|
"allow_in_quick_entry": 0,
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"collapsible_depends_on": null,
|
||||||
|
"columns": 0,
|
||||||
|
"creation": "2020-10-14 17:41:40.878179",
|
||||||
|
"default": "0",
|
||||||
|
"depends_on": null,
|
||||||
|
"description": null,
|
||||||
|
"docstatus": 0,
|
||||||
|
"dt": "Address",
|
||||||
|
"fetch_from": null,
|
||||||
|
"fetch_if_empty": 0,
|
||||||
|
"fieldname": "is_your_company_address",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"hidden": 0,
|
||||||
|
"hide_border": 0,
|
||||||
|
"hide_days": 0,
|
||||||
|
"hide_seconds": 0,
|
||||||
|
"idx": 20,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"ignore_xss_filter": 0,
|
||||||
|
"in_global_search": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"in_preview": 0,
|
||||||
|
"in_standard_filter": 0,
|
||||||
|
"insert_after": "linked_with",
|
||||||
|
"label": "Is Your Company Address",
|
||||||
|
"length": 0,
|
||||||
|
"mandatory_depends_on": null,
|
||||||
|
"modified": "2020-10-14 17:41:40.878179",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"name": "Address-is_your_company_address",
|
||||||
|
"no_copy": 0,
|
||||||
|
"options": null,
|
||||||
|
"owner": "Administrator",
|
||||||
|
"parent": null,
|
||||||
|
"parentfield": null,
|
||||||
|
"parenttype": null,
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"print_width": null,
|
||||||
|
"read_only": 0,
|
||||||
|
"read_only_depends_on": null,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"translatable": 0,
|
||||||
|
"unique": 0,
|
||||||
"width": null
|
"width": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"custom_perms": [],
|
"custom_perms": [],
|
||||||
"doctype": "Address",
|
"doctype": "Address",
|
||||||
"property_setters": [],
|
"property_setters": [],
|
||||||
"sync_on_migrate": 1
|
"sync_on_migrate": 1
|
||||||
}
|
}
|
42
erpnext/accounts/custom/address.py
Normal file
42
erpnext/accounts/custom/address.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import frappe
|
||||||
|
from frappe import _
|
||||||
|
from frappe.contacts.doctype.address.address import Address
|
||||||
|
from frappe.contacts.doctype.address.address import get_address_templates
|
||||||
|
|
||||||
|
class ERPNextAddress(Address):
|
||||||
|
def validate(self):
|
||||||
|
self.validate_reference()
|
||||||
|
super(ERPNextAddress, self).validate()
|
||||||
|
|
||||||
|
def link_address(self):
|
||||||
|
"""Link address based on owner"""
|
||||||
|
if self.is_your_company_address:
|
||||||
|
return
|
||||||
|
|
||||||
|
return super(ERPNextAddress, self).link_address()
|
||||||
|
|
||||||
|
def validate_reference(self):
|
||||||
|
if self.is_your_company_address and not [
|
||||||
|
row for row in self.links if row.link_doctype == "Company"
|
||||||
|
]:
|
||||||
|
frappe.throw(_("Address needs to be linked to a Company. Please add a row for Company in the Links table."),
|
||||||
|
title=_("Company Not Linked"))
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_shipping_address(company, address = None):
|
||||||
|
filters = [
|
||||||
|
["Dynamic Link", "link_doctype", "=", "Company"],
|
||||||
|
["Dynamic Link", "link_name", "=", company],
|
||||||
|
["Address", "is_your_company_address", "=", 1]
|
||||||
|
]
|
||||||
|
fields = ["*"]
|
||||||
|
if address and frappe.db.get_value('Dynamic Link',
|
||||||
|
{'parent': address, 'link_name': company}):
|
||||||
|
filters.append(["Address", "name", "=", address])
|
||||||
|
|
||||||
|
address = frappe.get_all("Address", filters=filters, fields=fields) or {}
|
||||||
|
|
||||||
|
if address:
|
||||||
|
address_as_dict = address[0]
|
||||||
|
name, address_template = get_address_templates(address_as_dict)
|
||||||
|
return address_as_dict.get("name"), frappe.render_template(address_template, address_as_dict)
|
@ -21,11 +21,16 @@ web_include_js = "assets/js/erpnext-web.min.js"
|
|||||||
web_include_css = "assets/css/erpnext-web.css"
|
web_include_css = "assets/css/erpnext-web.css"
|
||||||
|
|
||||||
doctype_js = {
|
doctype_js = {
|
||||||
|
"Address": "public/js/address.js",
|
||||||
"Communication": "public/js/communication.js",
|
"Communication": "public/js/communication.js",
|
||||||
"Event": "public/js/event.js",
|
"Event": "public/js/event.js",
|
||||||
"Newsletter": "public/js/newsletter.js"
|
"Newsletter": "public/js/newsletter.js"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override_doctype_class = {
|
||||||
|
'Address': 'erpnext.accounts.custom.address.ERPNextAddress'
|
||||||
|
}
|
||||||
|
|
||||||
welcome_email = "erpnext.setup.utils.welcome_email"
|
welcome_email = "erpnext.setup.utils.welcome_email"
|
||||||
|
|
||||||
# setup wizard
|
# setup wizard
|
||||||
@ -561,4 +566,4 @@ global_search_doctypes = {
|
|||||||
{'doctype': 'Hotel Room Package', 'index': 3},
|
{'doctype': 'Hotel Room Package', 'index': 3},
|
||||||
{'doctype': 'Hotel Room Type', 'index': 4}
|
{'doctype': 'Hotel Room Type', 'index': 4}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
25
erpnext/public/js/address.js
Normal file
25
erpnext/public/js/address.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (c) 2016, Frappe Technologies and contributors
|
||||||
|
// For license information, please see license.txt
|
||||||
|
|
||||||
|
frappe.ui.form.on("Address", {
|
||||||
|
is_your_company_address: function(frm) {
|
||||||
|
frm.clear_table('links');
|
||||||
|
if(frm.doc.is_your_company_address) {
|
||||||
|
frm.add_child('links', {
|
||||||
|
link_doctype: 'Company',
|
||||||
|
link_name: frappe.defaults.get_user_default('Company')
|
||||||
|
});
|
||||||
|
frm.set_query('link_doctype', 'links', () => {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
name: 'Company'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
frm.refresh_field('links');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
frm.trigger('refresh');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
@ -277,7 +277,7 @@ erpnext.utils.validate_mandatory = function(frm, label, value, trigger_on) {
|
|||||||
erpnext.utils.get_shipping_address = function(frm, callback){
|
erpnext.utils.get_shipping_address = function(frm, callback){
|
||||||
if (frm.doc.company) {
|
if (frm.doc.company) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "frappe.contacts.doctype.address.address.get_shipping_address",
|
method: "erpnext.accounts.custom.address.get_shipping_address",
|
||||||
args: {
|
args: {
|
||||||
company: frm.doc.company,
|
company: frm.doc.company,
|
||||||
address: frm.doc.shipping_address
|
address: frm.doc.shipping_address
|
||||||
|
Loading…
Reference in New Issue
Block a user