mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 05:39:12 +00:00
feat(Contacts): select billing contact for sales invoice
This commit is contained in:
@@ -46,7 +46,7 @@ def _get_party_details(party=None, account=None, party_type="Customer", company=
|
||||
currency = party.default_currency if party.get("default_currency") else get_company_currency(company)
|
||||
|
||||
party_address, shipping_address = set_address_details(party_details, party, party_type, doctype, company, party_address, company_address, shipping_address)
|
||||
set_contact_details(party_details, party, party_type)
|
||||
set_contact_details(party_details, party, party_type, doctype)
|
||||
set_other_values(party_details, party, party_type)
|
||||
set_price_list(party_details, party, party_type, price_list, pos_profile)
|
||||
|
||||
@@ -115,8 +115,11 @@ def set_address_details(party_details, party, party_type, doctype=None, company=
|
||||
def get_regional_address_details(party_details, doctype, company):
|
||||
pass
|
||||
|
||||
def set_contact_details(party_details, party, party_type):
|
||||
party_details.contact_person = get_default_contact(party_type, party.name)
|
||||
def set_contact_details(party_details, party, party_type, doctype=None):
|
||||
if doctype == 'Sales Invoice':
|
||||
party_details.contact_person = get_default_billing_contact(doctype, party.name)
|
||||
else:
|
||||
party_details.contact_person = get_default_contact(party_type, party.name)
|
||||
|
||||
if not party_details.contact_person:
|
||||
party_details.update({
|
||||
@@ -615,3 +618,26 @@ def get_partywise_advanced_payment_amount(party_type, posting_date = None):
|
||||
|
||||
if data:
|
||||
return frappe._dict(data)
|
||||
|
||||
def get_default_billing_contact(doctype, name):
|
||||
"""
|
||||
Returns default contact for the given doctype and name.
|
||||
Can be ordered by `contact_type` to either is_primary_contact or is_billing_contact.
|
||||
"""
|
||||
out = frappe.db.sql("""
|
||||
SELECT dl.parent, c.is_primary_contact, c.is_billing_contact
|
||||
FROM `tabDynamic Link` dl
|
||||
INNER JOIN tabContact c ON c.name = dl.parent
|
||||
WHERE
|
||||
dl.link_doctype=%s AND
|
||||
dl.link_name=%s AND
|
||||
dl.parenttype = "Contact"
|
||||
ORDER BY is_billing_contact DESC, is_primary_contact DESC
|
||||
""", (doctype, name))
|
||||
if out:
|
||||
try:
|
||||
return out[0][0]
|
||||
except:
|
||||
return None
|
||||
else:
|
||||
return None
|
||||
Reference in New Issue
Block a user