fix: move get_shipping_address() from frappe to erpnext and fix references

This commit is contained in:
Abhishek Balam 2020-10-14 20:09:05 +05:30
parent 2f528c1c73
commit 89419c9a30
2 changed files with 21 additions and 2 deletions

View File

@ -3,6 +3,7 @@ from frappe import _
from frappe.contacts.doctype.address.address import Address
from frappe.contacts.address_and_contact import set_link_title
from frappe.core.doctype.dynamic_link.dynamic_link import deduplicate_dynamic_links
from frappe.contacts.doctype.address.address import get_address_templates
class CustomAddress(Address):
def validate(self):
@ -31,3 +32,21 @@ class CustomAddress(Address):
frappe.throw(_("Address needs to be linked to a Company. Please add a row for Company in the Links table below."),
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)

View File

@ -277,7 +277,7 @@ erpnext.utils.validate_mandatory = function(frm, label, value, trigger_on) {
erpnext.utils.get_shipping_address = function(frm, callback){
if (frm.doc.company) {
frappe.call({
method: "frappe.contacts.doctype.address.address.get_shipping_address",
method: "erpnext.accounts.custom.address.get_shipping_address",
args: {
company: frm.doc.company,
address: frm.doc.shipping_address