Skip to content

Commit

Permalink
Contacto de Facturación (#739)
Browse files Browse the repository at this point in the history
* feat: billing contact

* feat: billing contact in SO

* Update party.py
  • Loading branch information
fproldan authored and github-actions[bot] committed May 17, 2023
1 parent 56deb1d commit 4b8c3b6
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions erpnext/accounts/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down

0 comments on commit 4b8c3b6

Please sign in to comment.