fix: fix to fetch customers and billing email in PSOA (#27363)
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
index 295a3b8..a26267b 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
@@ -219,6 +219,7 @@
},
{
"default": "1",
+ "description": "A customer must have primary contact email.",
"fieldname": "primary_mandatory",
"fieldtype": "Check",
"label": "Send To Primary Contact"
@@ -286,10 +287,11 @@
}
],
"links": [],
- "modified": "2021-05-21 11:14:22.426672",
+ "modified": "2021-09-06 21:00:45.732505",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Process Statement Of Accounts",
+ "naming_rule": "Set by user",
"owner": "Administrator",
"permissions": [
{
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py
index 73f3038..503fd0d 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py
@@ -196,7 +196,10 @@
primary_email = customer.get('email_id') or ''
billing_email = get_customer_emails(customer.name, 1, billing_and_primary=False)
- if billing_email == '' or (primary_email == '' and int(primary_mandatory)):
+ if int(primary_mandatory):
+ if (primary_email == ''):
+ continue
+ elif (billing_email == '') and (primary_email == ''):
continue
customer_list.append({
@@ -208,10 +211,29 @@
@frappe.whitelist()
def get_customer_emails(customer_name, primary_mandatory, billing_and_primary=True):
+ """ Returns first email from Contact Email table as a Billing email
+ when Is Billing Contact checked
+ and Primary email- email with Is Primary checked """
+
billing_email = frappe.db.sql("""
- SELECT c.email_id FROM `tabContact` AS c JOIN `tabDynamic Link` AS l ON c.name=l.parent
- WHERE l.link_doctype='Customer' and l.link_name=%s and c.is_billing_contact=1
- order by c.creation desc""", customer_name)
+ SELECT
+ email.email_id
+ FROM
+ `tabContact Email` AS email
+ JOIN
+ `tabDynamic Link` AS link
+ ON
+ email.parent=link.parent
+ JOIN
+ `tabContact` AS contact
+ ON
+ contact.name=link.parent
+ WHERE
+ link.link_doctype='Customer'
+ and link.link_name=%s
+ and contact.is_billing_contact=1
+ ORDER BY
+ contact.creation desc""", customer_name)
if len(billing_email) == 0 or (billing_email[0][0] is None):
if billing_and_primary: