From 8d8af941823ab1f054c3e59229c962f034f78227 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Fri, 4 Sep 2020 12:17:56 +0530 Subject: [PATCH 1/7] fix: capture advance payments in payment order --- .../doctype/payment_entry/payment_entry.py | 29 +++++++------------ .../payment_order_reference.json | 13 +++------ 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 842c64fdbe3..bb312bf72e4 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1172,30 +1172,23 @@ def make_payment_order(source_name, target_doc=None): from frappe.model.mapper import get_mapped_doc def set_missing_values(source, target): target.payment_order_type = "Payment Entry" + target.append('references', dict( + reference_doctype="Payment Entry", + reference_name=source.name, + bank_account=source.party_bank_account, + amount=source.paid_amount, + account=source.paid_to, + supplier=source.party, + mode_of_payment=source.mode_of_payment, + )) - def update_item(source_doc, target_doc, source_parent): - target_doc.bank_account = source_parent.party_bank_account - target_doc.amount = source_doc.allocated_amount - target_doc.account = source_parent.paid_to - target_doc.payment_entry = source_parent.name - target_doc.supplier = source_parent.party - target_doc.mode_of_payment = source_parent.mode_of_payment - - - doclist = get_mapped_doc("Payment Entry", source_name, { + doclist = get_mapped_doc("Payment Entry", source_name, { "Payment Entry": { "doctype": "Payment Order", - "validation": { - "docstatus": ["=", 1] - } - }, - "Payment Entry Reference": { - "doctype": "Payment Order Reference", "validation": { "docstatus": ["=", 1] }, - "postprocess": update_item - }, + } }, target_doc, set_missing_values) diff --git a/erpnext/accounts/doctype/payment_order_reference/payment_order_reference.json b/erpnext/accounts/doctype/payment_order_reference/payment_order_reference.json index db0b76135dd..d94ba74c8c9 100644 --- a/erpnext/accounts/doctype/payment_order_reference/payment_order_reference.json +++ b/erpnext/accounts/doctype/payment_order_reference/payment_order_reference.json @@ -1,4 +1,5 @@ { + "actions": [], "creation": "2018-07-20 16:38:06.630813", "doctype": "DocType", "editable_grid": 1, @@ -10,7 +11,6 @@ "column_break_4", "supplier", "payment_request", - "payment_entry", "mode_of_payment", "bank_account_details", "bank_account", @@ -103,17 +103,12 @@ "no_copy": 1, "print_hide": 1, "read_only": 1 - }, - { - "fieldname": "payment_entry", - "fieldtype": "Link", - "label": "Payment Entry", - "options": "Payment Entry", - "read_only": 1 } ], + "index_web_pages_for_search": 1, "istable": 1, - "modified": "2019-05-08 13:56:25.724557", + "links": [], + "modified": "2020-09-04 08:29:51.014390", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Order Reference", From e1889d0c1b213df492f56f37cac0361fef3ed486 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Fri, 4 Sep 2020 14:45:19 +0530 Subject: [PATCH 2/7] fix(payment entry): update payment order status --- erpnext/accounts/doctype/payment_order/payment_order.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/payment_order/payment_order.py b/erpnext/accounts/doctype/payment_order/payment_order.py index e5880aa67a8..8d29ae70ae7 100644 --- a/erpnext/accounts/doctype/payment_order/payment_order.py +++ b/erpnext/accounts/doctype/payment_order/payment_order.py @@ -21,10 +21,15 @@ class PaymentOrder(Document): if cancel: status = 'Initiated' - ref_field = "status" if self.payment_order_type == "Payment Request" else "payment_order_status" + if self.payment_order_type == "Payment Request": + ref_field = "status" + ref_doc_field = frappe.scrub(self.payment_order_type) + else: + ref_field = "payment_order_status" + ref_doc_field = "reference_name" for d in self.references: - frappe.db.set_value(self.payment_order_type, d.get(frappe.scrub(self.payment_order_type)), ref_field, status) + frappe.db.set_value(self.payment_order_type, d.get(ref_doc_field), ref_field, status) @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs From d9e48833926bca7ad0eb8700e5d4d46719eaabe7 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Fri, 4 Sep 2020 18:55:14 +0530 Subject: [PATCH 3/7] test: check payment order creation against payment entry --- .../bank_transaction/test_bank_transaction.py | 37 ++++++++++--------- .../payment_order/test_payment_order.py | 35 +++++++++++++++++- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py index 0fe57c32399..47d2de18164 100644 --- a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py @@ -91,28 +91,31 @@ class TestBankTransaction(unittest.TestCase): self.assertEqual(frappe.db.get_value("Bank Transaction", bank_transaction.name, "unallocated_amount"), 0) self.assertTrue(frappe.db.get_value("Sales Invoice Payment", dict(parent=payment.name), "clearance_date") is not None) +def create_bank_account(bank_name="Citi Bank", account_name="_Test Bank - _TC"): + try: + frappe.get_doc({ + "doctype": "Bank", + "bank_name":bank_name, + }).insert() + except frappe.DuplicateEntryError: + pass + + try: + doc = frappe.get_doc({ + "doctype": "Bank Account", + "account_name":"Checking Account", + "bank": bank_name, + "account": account_name + }).insert() + except frappe.DuplicateEntryError: + pass + def add_transactions(): if frappe.flags.test_bank_transactions_created: return frappe.set_user("Administrator") - try: - frappe.get_doc({ - "doctype": "Bank", - "bank_name":"Citi Bank", - }).insert() - except frappe.DuplicateEntryError: - pass - - try: - frappe.get_doc({ - "doctype": "Bank Account", - "account_name":"Checking Account", - "bank": "Citi Bank", - "account": "_Test Bank - _TC" - }).insert() - except frappe.DuplicateEntryError: - pass + create_bank_account() doc = frappe.get_doc({ "doctype": "Bank Transaction", diff --git a/erpnext/accounts/doctype/payment_order/test_payment_order.py b/erpnext/accounts/doctype/payment_order/test_payment_order.py index 711c4cc1dfd..d871e3b71fe 100644 --- a/erpnext/accounts/doctype/payment_order/test_payment_order.py +++ b/erpnext/accounts/doctype/payment_order/test_payment_order.py @@ -5,6 +5,39 @@ from __future__ import unicode_literals import frappe import unittest +from frappe.utils import getdate +from erpnext.accounts.doctype.bank_transaction.test_bank_transaction import create_bank_account +from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry, InvalidPaymentEntry, make_payment_order +from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice, make_purchase_invoice_against_cost_center class TestPaymentOrder(unittest.TestCase): - pass + def setUp(self): + create_bank_account() + + def test_payment_order_creation_against_payment_entry(self): + purchase_invoice = make_purchase_invoice() + payment_entry = get_payment_entry("Purchase Invoice", purchase_invoice.name, bank_account="_Test Bank - _TC") + payment_entry.reference_no = "_Test_Payment_Order" + payment_entry.reference_date = getdate() + payment_entry.party_bank_account = "Checking Account - Citi Bank" + payment_entry.insert() + payment_entry.submit() + + doc = create_payment_order_against_payment_entry(payment_entry, "Payment Entry") + reference_doc = doc.get("references")[0] + self.assertEquals(reference_doc.reference_name, payment_entry.name) + self.assertEquals(reference_doc.reference_doctype, "Payment Entry") + self.assertEquals(reference_doc.supplier, "_Test Supplier") + self.assertEquals(reference_doc.amount, 250) + +def create_payment_order_against_payment_entry(ref_doc, order_type): + payment_order = frappe.get_doc(dict( + doctype="Payment Order", + company="_Test Company", + payment_order_type=order_type, + company_bank_account="Checking Account - Citi Bank" + )) + doc = make_payment_order(ref_doc.name, payment_order) + doc.save() + doc.submit() + return doc \ No newline at end of file From a76bf4d7af53dfe96274bc2c75a6c31b10ac8add Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Fri, 4 Sep 2020 19:08:08 +0530 Subject: [PATCH 4/7] fix: remove unused imports --- .../doctype/bank_transaction/test_bank_transaction.py | 2 +- erpnext/accounts/doctype/payment_order/test_payment_order.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py index 47d2de18164..27546335c91 100644 --- a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py @@ -101,7 +101,7 @@ def create_bank_account(bank_name="Citi Bank", account_name="_Test Bank - _TC"): pass try: - doc = frappe.get_doc({ + frappe.get_doc({ "doctype": "Bank Account", "account_name":"Checking Account", "bank": bank_name, diff --git a/erpnext/accounts/doctype/payment_order/test_payment_order.py b/erpnext/accounts/doctype/payment_order/test_payment_order.py index d871e3b71fe..1093a9b60ae 100644 --- a/erpnext/accounts/doctype/payment_order/test_payment_order.py +++ b/erpnext/accounts/doctype/payment_order/test_payment_order.py @@ -7,8 +7,8 @@ import frappe import unittest from frappe.utils import getdate from erpnext.accounts.doctype.bank_transaction.test_bank_transaction import create_bank_account -from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry, InvalidPaymentEntry, make_payment_order -from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice, make_purchase_invoice_against_cost_center +from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry, make_payment_order +from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice class TestPaymentOrder(unittest.TestCase): def setUp(self): From 7456ffca0f89ed608733887b26f7f68524d7d3f4 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Fri, 4 Sep 2020 19:59:01 +0530 Subject: [PATCH 5/7] fix: teardown created payment order --- .../accounts/doctype/payment_order/test_payment_order.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/erpnext/accounts/doctype/payment_order/test_payment_order.py b/erpnext/accounts/doctype/payment_order/test_payment_order.py index 1093a9b60ae..1c23e2a0ec2 100644 --- a/erpnext/accounts/doctype/payment_order/test_payment_order.py +++ b/erpnext/accounts/doctype/payment_order/test_payment_order.py @@ -14,6 +14,12 @@ class TestPaymentOrder(unittest.TestCase): def setUp(self): create_bank_account() + def tearDown(self): + for bt in frappe.get_all("Payment Order"): + doc = frappe.get_doc("Payment Order", bt.name) + doc.cancel() + doc.delete() + def test_payment_order_creation_against_payment_entry(self): purchase_invoice = make_purchase_invoice() payment_entry = get_payment_entry("Purchase Invoice", purchase_invoice.name, bank_account="_Test Bank - _TC") From 03b0ad4f98aaf0b6555f8df7899fa14f30ffe0bc Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 7 Sep 2020 23:22:21 +0530 Subject: [PATCH 6/7] fix: Only submitted Loan security pledges should be approved --- erpnext/loan_management/doctype/loan/loan.py | 10 +++++++--- .../loan_security_unpledge/loan_security_unpledge.py | 3 --- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/erpnext/loan_management/doctype/loan/loan.py b/erpnext/loan_management/doctype/loan/loan.py index e2e27dd45d5..d1b7589a17e 100644 --- a/erpnext/loan_management/doctype/loan/loan.py +++ b/erpnext/loan_management/doctype/loan/loan.py @@ -240,15 +240,19 @@ def unpledge_security(loan=None, loan_security_pledge=None, as_dict=0, save=0, s unpledge_request = create_loan_security_unpledge(security_map, pledge_doc.loan, pledge_doc.company, pledge_doc.applicant_type, pledge_doc.applicant) - if approve: - unpledge_request.status = 'Approved' - if save: unpledge_request.save() if submit: unpledge_request.submit() + if approve: + if unpledge_request.docstatus == 1: + unpledge_request.status = 'Approved' + unpledge_request.save() + else: + frappe.throw(_('Only submittted unpledge requests can be approved')) + if as_dict: return unpledge_request else: diff --git a/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.py b/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.py index a87d832b1ca..b3eb6001e42 100644 --- a/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.py +++ b/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.py @@ -20,9 +20,6 @@ class LoanSecurityUnpledge(Document): self.update_loan_status(cancel=1) self.db_set('status', 'Requested') - def on_submit(self): - self.approve() - def validate_duplicate_securities(self): security_list = [] for d in self.securities: From 5b381ac5b782030d0bc9aff0777c27d440efa199 Mon Sep 17 00:00:00 2001 From: barry86m <65860880+barry86m@users.noreply.github.com> Date: Tue, 8 Sep 2020 00:27:57 +0100 Subject: [PATCH 7/7] fix: consolidated financial statement sums values into wrong parent fix proposed by Andriesvn in bug report closes #22180 --- .../consolidated_financial_statement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py index 219871b1d66..d0116890b65 100644 --- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py +++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py @@ -256,7 +256,7 @@ def accumulate_values_into_parents(accounts, accounts_by_name, companies): """accumulate children's values in parent accounts""" for d in reversed(accounts): if d.parent_account: - account = d.parent_account.split('-')[0].strip() + account = d.parent_account.split(' - ')[0].strip() if not accounts_by_name.get(account): continue