* add new function - `get_party_shipping_address` * `swap `get_default_address` with `get_party_shipping_address` * test cases * properly sets order by direction * move `get_party_shipping_address` to party.py * fix test module import
This commit is contained in:
parent
e6712c129c
commit
40a02769c5
@ -76,7 +76,7 @@ def set_address_details(out, party, party_type, doctype=None, company=None):
|
|||||||
|
|
||||||
# shipping address
|
# shipping address
|
||||||
if party_type in ["Customer", "Lead"]:
|
if party_type in ["Customer", "Lead"]:
|
||||||
out.shipping_address_name = get_default_address(party_type, party.name, 'is_shipping_address')
|
out.shipping_address_name = get_party_shipping_address(party_type, party.name)
|
||||||
out.shipping_address = get_address_display(out["shipping_address_name"])
|
out.shipping_address = get_address_display(out["shipping_address_name"])
|
||||||
if doctype:
|
if doctype:
|
||||||
out.update(get_fetch_values(doctype, 'shipping_address_name', out.shipping_address_name))
|
out.update(get_fetch_values(doctype, 'shipping_address_name', out.shipping_address_name))
|
||||||
@ -418,3 +418,32 @@ def get_dashboard_info(party_type, party):
|
|||||||
info["total_unpaid"] = -1 * info["total_unpaid"]
|
info["total_unpaid"] = -1 * info["total_unpaid"]
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
||||||
|
def get_party_shipping_address(doctype, name):
|
||||||
|
"""
|
||||||
|
Returns an Address name (best guess) for the given doctype and name for which `address_type == 'Shipping'` is true.
|
||||||
|
and/or `is_shipping_address = 1`.
|
||||||
|
|
||||||
|
It returns an empty string if there is no matching record.
|
||||||
|
|
||||||
|
:param doctype: Party Doctype
|
||||||
|
:param name: Party name
|
||||||
|
:return: String
|
||||||
|
"""
|
||||||
|
out = frappe.db.sql(
|
||||||
|
'SELECT dl.parent '
|
||||||
|
'from `tabDynamic Link` dl join `tabAddress` ta on dl.parent=ta.name '
|
||||||
|
'where '
|
||||||
|
'dl.link_doctype=%s '
|
||||||
|
'and dl.link_name=%s '
|
||||||
|
'and dl.parenttype="Address" '
|
||||||
|
'and '
|
||||||
|
'(ta.address_type="Shipping" or ta.is_shipping_address=1) '
|
||||||
|
'order by ta.is_shipping_address desc, ta.address_type desc limit 1',
|
||||||
|
(doctype, name)
|
||||||
|
)
|
||||||
|
if out:
|
||||||
|
return out[0][0]
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
0
erpnext/accounts/test/__init__.py
Normal file
0
erpnext/accounts/test/__init__.py
Normal file
84
erpnext/accounts/test/test_utils.py
Normal file
84
erpnext/accounts/test/test_utils.py
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
import unittest
|
||||||
|
from erpnext.accounts.party import get_party_shipping_address
|
||||||
|
from frappe.test_runner import make_test_objects
|
||||||
|
|
||||||
|
|
||||||
|
class TestUtils(unittest.TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super(TestUtils, cls).setUpClass()
|
||||||
|
make_test_objects('Address', ADDRESS_RECORDS)
|
||||||
|
|
||||||
|
def test_get_party_shipping_address(self):
|
||||||
|
address = get_party_shipping_address('Customer', '_Test Customer 1')
|
||||||
|
self.assertEqual(address, '_Test Billing Address 2 Title-Billing')
|
||||||
|
|
||||||
|
def test_get_party_shipping_address2(self):
|
||||||
|
address = get_party_shipping_address('Customer', '_Test Customer 2')
|
||||||
|
self.assertEqual(address, '_Test Shipping Address 2 Title-Shipping')
|
||||||
|
|
||||||
|
|
||||||
|
ADDRESS_RECORDS = [
|
||||||
|
{
|
||||||
|
"doctype": "Address",
|
||||||
|
"address_type": "Billing",
|
||||||
|
"address_line1": "Address line 1",
|
||||||
|
"address_title": "_Test Billing Address Title",
|
||||||
|
"city": "Lagos",
|
||||||
|
"country": "Nigeria",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"link_doctype": "Customer",
|
||||||
|
"link_name": "_Test Customer 2",
|
||||||
|
"doctype": "Dynamic Link"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Address",
|
||||||
|
"address_type": "Shipping",
|
||||||
|
"address_line1": "Address line 2",
|
||||||
|
"address_title": "_Test Shipping Address 1 Title",
|
||||||
|
"city": "Lagos",
|
||||||
|
"country": "Nigeria",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"link_doctype": "Customer",
|
||||||
|
"link_name": "_Test Customer 2",
|
||||||
|
"doctype": "Dynamic Link"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Address",
|
||||||
|
"address_type": "Shipping",
|
||||||
|
"address_line1": "Address line 3",
|
||||||
|
"address_title": "_Test Shipping Address 2 Title",
|
||||||
|
"city": "Lagos",
|
||||||
|
"country": "Nigeria",
|
||||||
|
"is_shipping_address": "1",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"link_doctype": "Customer",
|
||||||
|
"link_name": "_Test Customer 2",
|
||||||
|
"doctype": "Dynamic Link"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Address",
|
||||||
|
"address_type": "Billing",
|
||||||
|
"address_line1": "Address line 4",
|
||||||
|
"address_title": "_Test Billing Address 2 Title",
|
||||||
|
"city": "Lagos",
|
||||||
|
"country": "Nigeria",
|
||||||
|
"is_shipping_address": "1",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"link_doctype": "Customer",
|
||||||
|
"link_name": "_Test Customer 1",
|
||||||
|
"doctype": "Dynamic Link"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
Loading…
x
Reference in New Issue
Block a user