Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport diamoerp-staging] Contacto de Facturación #745

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading