Merge pull request #16335 from deepeshgarg007/accounts-receivable-fix
perf: Customer contact column in accounts receivable report
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index 121d5b0..22d4d94 100755
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -32,6 +32,15 @@
columns += [_(args.get("party_type")) + ":Link/" + args.get("party_type") + ":200"]
+ if args.get("party_type") == 'Customer':
+ columns.append({
+ "label": _("Customer Contact"),
+ "fieldtype": "Link",
+ "fieldname": "contact",
+ "options":"Contact",
+ "width": 100
+ })
+
if party_naming_by == "Naming Series":
columns += [args.get("party_type") + " Name::110"]
@@ -282,6 +291,9 @@
if party_naming_by == "Naming Series":
row += [self.get_party_name(gle.party_type, gle.party)]
+ if args.get("party_type") == 'Customer':
+ row += [self.get_customer_contact(gle.party_type, gle.party)]
+
# get due date
if not due_date:
due_date = self.voucher_details.get(gle.voucher_no, {}).get("due_date", "")
@@ -407,6 +419,9 @@
def get_party_name(self, party_type, party_name):
return self.get_party_map(party_type).get(party_name, {}).get("customer_name" if party_type == "Customer" else "supplier_name") or ""
+ def get_customer_contact(self, party_type, party_name):
+ return self.get_party_map(party_type).get(party_name, {}).get("customer_primary_contact")
+
def get_territory(self, party_name):
return self.get_party_map("Customer").get(party_name, {}).get("territory") or ""
@@ -419,7 +434,7 @@
def get_party_map(self, party_type):
if not hasattr(self, "party_map"):
if party_type == "Customer":
- select_fields = "name, customer_name, territory, customer_group"
+ select_fields = "name, customer_name, territory, customer_group, customer_primary_contact"
elif party_type == "Supplier":
select_fields = "name, supplier_name, supplier_group"
diff --git a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py
index 34e6c83..f911eaa 100644
--- a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py
@@ -21,24 +21,24 @@
expected_data = [[100,30], [100,50], [100,20]]
- self.assertEqual(expected_data[0], report[1][0][6:8])
- self.assertEqual(expected_data[1], report[1][1][6:8])
- self.assertEqual(expected_data[2], report[1][2][6:8])
+ self.assertEqual(expected_data[0], report[1][0][7:9])
+ self.assertEqual(expected_data[1], report[1][1][7:9])
+ self.assertEqual(expected_data[2], report[1][2][7:9])
make_payment(name)
report = execute(filters)
expected_data_after_payment = [[100,50], [100,20]]
- self.assertEqual(expected_data_after_payment[0], report[1][0][6:8])
- self.assertEqual(expected_data_after_payment[1], report[1][1][6:8])
+ self.assertEqual(expected_data_after_payment[0], report[1][0][7:9])
+ self.assertEqual(expected_data_after_payment[1], report[1][1][7:9])
make_credit_note(name)
report = execute(filters)
expected_data_after_credit_note = [[100,100,30,100,-30]]
- self.assertEqual(expected_data_after_credit_note[0], report[1][0][6:11])
+ self.assertEqual(expected_data_after_credit_note[0], report[1][0][7:12])
def make_sales_invoice():