From e4bbb696ab12f11b83cabc3e3a70297bc0248710 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 4 Jul 2016 16:16:24 +0530 Subject: [PATCH 1/2] Payment Entry minor improvements --- .../doctype/payment_entry/payment_entry.json | 54 +++++++++---------- .../doctype/payment_entry/payment_entry.py | 4 +- erpnext/accounts/utils.py | 18 +++---- erpnext/config/accounts.py | 12 ++--- 4 files changed, 43 insertions(+), 45 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.json b/erpnext/accounts/doctype/payment_entry/payment_entry.json index d40ba9ddcc..d816eb800e 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.json +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.json @@ -848,32 +848,6 @@ "set_only_once": 0, "unique": 0 }, - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "depends_on": "difference_amount", - "fieldname": "write_off_difference_amount", - "fieldtype": "Button", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_list_view": 0, - "label": "Write Off Difference Amount", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, { "allow_on_submit": 0, "bold": 0, @@ -976,6 +950,32 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "depends_on": "difference_amount", + "fieldname": "write_off_difference_amount", + "fieldtype": "Button", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Write Off Difference Amount", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -1372,7 +1372,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-07-01 17:14:17.562924", + "modified": "2016-07-04 15:00:53.731584", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Entry", diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index d4d93a7ae1..6e441e4276 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -194,7 +194,7 @@ class PaymentEntry(AccountsController): """, (self.party_account, self.party, d.reference_name), as_dict=True) if not je_accounts: - frappe.throw(_("Row #{0}: Journal Entry {0} does not have account {1} or already matched against another voucher") + frappe.throw(_("Row #{0}: Journal Entry {1} does not have account {2} or already matched against another voucher") .format(d.idx, d.reference_name, self.party_account)) else: dr_or_cr = "debit" if self.payment_type == "Receive" else "credit" @@ -270,6 +270,7 @@ class PaymentEntry(AccountsController): def validate_payment_against_negative_invoice(self): if ((self.payment_type=="Pay" and self.party_type=="Customer") or (self.payment_type=="Receive" and self.party_type=="Supplier")): + total_negative_outstanding = sum([abs(flt(d.outstanding_amount)) for d in self.get("references") if flt(d.outstanding_amount) < 0]) @@ -535,6 +536,7 @@ def get_party_details(company, party_type, party, date): @frappe.whitelist() def get_account_details(account, date): + frappe.has_permission('Payment Entry', throw=True) return frappe._dict({ "account_currency": get_account_currency(account), "account_balance": get_balance_on(account, date), diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 6bd5eb1301..2d1b2db705 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -434,15 +434,13 @@ def get_outstanding_invoices(party_type, party, account, condition=None): dr_or_cr = "credit_in_account_currency - debit_in_account_currency" payment_dr_or_cr = "payment_gl_entry.debit_in_account_currency - payment_gl_entry.credit_in_account_currency" - invoice_list = frappe.db.sql("""select - voucher_no, voucher_type, posting_date, - ifnull(sum({dr_or_cr}), 0) as invoice_amount, + invoice_list = frappe.db.sql(""" + select + voucher_no, voucher_type, posting_date, ifnull(sum({dr_or_cr}), 0) as invoice_amount, ( - select - ifnull(sum({payment_dr_or_cr}), 0) + select ifnull(sum({payment_dr_or_cr}), 0) from `tabGL Entry` payment_gl_entry - where - payment_gl_entry.against_voucher_type = invoice_gl_entry.voucher_type + where payment_gl_entry.against_voucher_type = invoice_gl_entry.voucher_type and payment_gl_entry.against_voucher = invoice_gl_entry.voucher_no and payment_gl_entry.party_type = invoice_gl_entry.party_type and payment_gl_entry.party = invoice_gl_entry.party @@ -452,10 +450,8 @@ def get_outstanding_invoices(party_type, party, account, condition=None): from `tabGL Entry` invoice_gl_entry where - party_type = %(party_type)s - and party = %(party)s - and account = %(account)s - and {dr_or_cr} > 0 + party_type = %(party_type)s and party = %(party)s + and account = %(account)s and {dr_or_cr} > 0 {condition} and ((voucher_type = 'Journal Entry' and (against_voucher = '' or against_voucher is null)) diff --git a/erpnext/config/accounts.py b/erpnext/config/accounts.py index 9dd50f8c72..e93f0176f6 100644 --- a/erpnext/config/accounts.py +++ b/erpnext/config/accounts.py @@ -21,10 +21,15 @@ def get_data(): "name": "Payment Request", "description": _("Payment Request") }, + { + "type": "doctype", + "name": "Payment Entry", + "description": _("Bank/Cash transactions against party or for internal transfer") + }, { "type": "report", "name": "Accounts Receivable", - "doctype": "Sales Invoice", + "doctype": "Sales Invoice", "is_query_report": True }, { @@ -44,11 +49,6 @@ def get_data(): "name": "Company", "description": _("Company (not Customer or Supplier) master.") }, - { - "type": "doctype", - "name": "Payment Entry", - "description": _("Payment entries against party or for internal transfer") - }, { "type": "doctype", "name": "Journal Entry", From f6a0d789d0f14abadc58a7417b4b1e69f3cba4a6 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 4 Jul 2016 17:24:21 +0530 Subject: [PATCH 2/2] Payment entry fixes --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 6e441e4276..441760bd9e 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -49,6 +49,7 @@ class PaymentEntry(AccountsController): self.set_remarks() def on_submit(self): + self.setup_party_account_field() if self.difference_amount: frappe.throw(_("Difference Amount must be zero")) self.make_gl_entries() @@ -127,7 +128,7 @@ class PaymentEntry(AccountsController): def validate_account_type(self, account, account_types): account_type = frappe.db.get_value("Account", account, "account_type") if account_type not in account_types: - frappe.throw(_("Account Type for {0} must be {1}").format(comma_or(account_types))) + frappe.throw(_("Account Type for {0} must be {1}").format(account, comma_or(account_types))) def set_exchange_rate(self): if self.paid_from and not self.source_exchange_rate: @@ -380,7 +381,7 @@ class PaymentEntry(AccountsController): gle = party_gl_dict.copy() gle.update({ - dr_or_cr + "_in_account_currency": d.unallocated_amount, + dr_or_cr + "_in_account_currency": self.unallocated_amount, dr_or_cr: base_unallocated_amount })