Merge pull request #20809 from ronelvcabrera/billing-contact
feat(Contacts): select billing contact for sales invoice
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 8567740..4cfeb25 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -11,7 +11,7 @@
add_years, get_timestamp, nowdate, flt, cstr, add_months, get_last_day)
from frappe.contacts.doctype.address.address import (get_address_display,
get_default_address, get_company_address)
-from frappe.contacts.doctype.contact.contact import get_contact_details, get_default_contact
+from frappe.contacts.doctype.contact.contact import get_contact_details
from erpnext.exceptions import PartyFrozen, PartyDisabled, InvalidAccountCurrency
from erpnext.accounts.utils import get_fiscal_year
from erpnext import get_company_currency
@@ -613,3 +613,26 @@
if data:
return frappe._dict(data)
+
+def get_default_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_primary_contact DESC, is_billing_contact DESC
+ """, (doctype, name))
+ if out:
+ try:
+ return out[0][0]
+ except:
+ return None
+ else:
+ return None
\ No newline at end of file
diff --git a/erpnext/erpnext_integrations/custom/contact.json b/erpnext/erpnext_integrations/custom/contact.json
new file mode 100644
index 0000000..98a4bbc
--- /dev/null
+++ b/erpnext/erpnext_integrations/custom/contact.json
@@ -0,0 +1,60 @@
+{
+ "custom_fields": [
+ {
+ "_assign": null,
+ "_comments": null,
+ "_liked_by": null,
+ "_user_tags": null,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "collapsible_depends_on": null,
+ "columns": 0,
+ "creation": "2019-12-02 11:00:03.432994",
+ "default": null,
+ "depends_on": null,
+ "description": null,
+ "docstatus": 0,
+ "dt": "Contact",
+ "fetch_from": null,
+ "fetch_if_empty": 0,
+ "fieldname": "is_billing_contact",
+ "fieldtype": "Check",
+ "hidden": 0,
+ "idx": 27,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "insert_after": "is_primary_contact",
+ "label": "Is Billing Contact",
+ "length": 0,
+ "modified": "2019-12-02 11:00:03.432994",
+ "modified_by": "Administrator",
+ "name": "Contact-is_billing_contact",
+ "no_copy": 0,
+ "options": null,
+ "owner": "Administrator",
+ "parent": null,
+ "parentfield": null,
+ "parenttype": null,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "print_width": null,
+ "read_only": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "translatable": 0,
+ "unique": 0,
+ "width": null
+ }
+ ],
+ "custom_perms": [],
+ "doctype": "Contact",
+ "property_setters": [],
+ "sync_on_migrate": 1
+}
\ No newline at end of file