From 4b8c3b6217f9c864d59339fc7c41b36611714662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Rold=C3=A1n?= Date: Wed, 17 May 2023 09:33:58 -0300 Subject: [PATCH] =?UTF-8?q?Contacto=20de=20Facturaci=C3=B3n=20(#739)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: billing contact * feat: billing contact in SO * Update party.py --- erpnext/accounts/party.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 6f9e61c5da70..6def5bf57b0f 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -63,7 +63,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) @@ -134,8 +134,8 @@ 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): + party_details.contact_person = get_default_contact(party_type, party.name, doctype) if not party_details.contact_person: party_details.update({ @@ -652,11 +652,16 @@ def get_partywise_advanced_payment_amount(party_type, posting_date = None, futur if data: return frappe._dict(data) -def get_default_contact(doctype, name): +def get_default_contact(doctype, name, document_doctype=None): """ Returns default contact for the given doctype and name. Can be ordered by `contact_type` to either is_primary_contact or is_billing_contact. """ + order_by = 'ORDER BY is_primary_contact DESC, is_billing_contact DESC' + + if document_doctype and document_doctype in ['Sales Invoice', 'Sales Order', 'Purchase Invoice', 'Purchase Order']: + order_by = 'ORDER BY is_billing_contact DESC, is_primary_contact DESC' + out = frappe.db.sql(""" SELECT dl.parent, c.is_primary_contact, c.is_billing_contact FROM `tabDynamic Link` dl @@ -665,8 +670,8 @@ def get_default_contact(doctype, name): dl.link_doctype=%s AND dl.link_name=%s AND dl.parenttype = "Contact" - ORDER BY is_primary_contact DESC, is_billing_contact DESC - """, (doctype, name)) + {order_by} + """.format(order_by=order_by), (doctype, name)) if out: try: return out[0][0]