From 9e1fbaf59e2808640f2c6aee4080aa29ad66e5c3 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Mon, 3 Feb 2020 15:58:50 +0530 Subject: [PATCH] fix: Label and UX fixes while creating payment entry against customer (#20465) * fix: Label and UX fixes while creating payment entry against customer * fix: filter --- erpnext/accounts/doctype/bank_account/bank_account.json | 6 ++++-- erpnext/accounts/doctype/payment_entry/payment_entry.py | 4 +++- erpnext/selling/doctype/customer/customer.js | 8 ++++++++ erpnext/selling/doctype/customer/customer.json | 6 ++++-- erpnext/selling/doctype/customer/customer.py | 6 ++++++ 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/bank_account/bank_account.json b/erpnext/accounts/doctype/bank_account/bank_account.json index 8e30b8555c..c8ae26d9f2 100644 --- a/erpnext/accounts/doctype/bank_account/bank_account.json +++ b/erpnext/accounts/doctype/bank_account/bank_account.json @@ -1,4 +1,5 @@ { + "actions": [], "allow_import": 1, "allow_rename": 1, "creation": "2017-05-29 21:35:13.136357", @@ -82,7 +83,7 @@ "default": "0", "fieldname": "is_default", "fieldtype": "Check", - "label": "Is the Default Account" + "label": "Is Default Account" }, { "default": "0", @@ -211,7 +212,8 @@ "read_only": 1 } ], - "modified": "2019-10-02 01:34:12.417601", + "links": [], + "modified": "2020-01-29 20:42:26.458316", "modified_by": "Administrator", "module": "Accounts", "name": "Bank Account", diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index e36e23add8..55d275831e 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -102,7 +102,9 @@ class PaymentEntry(AccountsController): self.bank = bank_data.bank self.bank_account_no = bank_data.bank_account_no - self.set(field, bank_data.account) + + if not self.get(field): + self.set(field, bank_data.account) def validate_allocated_amount(self): for d in self.get("references"): diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index ec1b79b2b2..825b170a90 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -55,6 +55,14 @@ frappe.ui.form.on("Customer", { } } }) + + frm.set_query('default_bank_account', function() { + return { + filters: { + 'is_company_account': 1 + } + } + }); }, customer_primary_address: function(frm){ if(frm.doc.customer_primary_address){ diff --git a/erpnext/selling/doctype/customer/customer.json b/erpnext/selling/doctype/customer/customer.json index dc8febdb99..89ce325a84 100644 --- a/erpnext/selling/doctype/customer/customer.json +++ b/erpnext/selling/doctype/customer/customer.json @@ -1,4 +1,5 @@ { + "actions": [], "allow_events_in_timeline": 1, "allow_import": 1, "allow_rename": 1, @@ -122,7 +123,7 @@ { "fieldname": "default_bank_account", "fieldtype": "Link", - "label": "Default Bank Account", + "label": "Default Company Bank Account", "options": "Bank Account" }, { @@ -470,7 +471,8 @@ "icon": "fa fa-user", "idx": 363, "image_field": "image", - "modified": "2020-01-24 15:07:48.815546", + "links": [], + "modified": "2020-01-29 20:36:37.879581", "modified_by": "Administrator", "module": "Selling", "name": "Customer", diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 136236c417..7f2fe60f59 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -54,6 +54,7 @@ class Customer(TransactionBase): self.validate_credit_limit_on_change() self.set_loyalty_program() self.check_customer_group_change() + self.validate_default_bank_account() # set loyalty program tier if frappe.db.exists('Customer', self.name): @@ -72,6 +73,11 @@ class Customer(TransactionBase): if self.customer_group != frappe.db.get_value('Customer', self.name, 'customer_group'): frappe.flags.customer_group_changed = True + def validate_default_bank_account(self): + if self.default_bank_account: + is_company_account = frappe.db.get_value('Bank Account', self.default_bank_account, 'is_company_account') + frappe.throw(_("{0} is not a company bank account").format(frappe.bold(self.default_bank_account))) + def on_update(self): self.validate_name_with_customer_group() self.create_primary_contact()