From d968f6134208c96e3b4e8d0e4d0f82c8d083270b Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Tue, 1 Aug 2023 14:47:55 +0530 Subject: [PATCH 1/3] fix: payment allocation in invoice payment schedule --- erpnext/controllers/accounts_controller.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 79404894cd2a..d7ab160ca16d 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1679,8 +1679,13 @@ def set_payment_schedule(self): ) self.append("payment_schedule", data) + allocate_payment_based_on_payment_terms = frappe.db.get_value( + "Payment Terms Template", self.payment_terms_template, "allocate_payment_based_on_payment_terms" + ) + if not ( automatically_fetch_payment_terms + and allocate_payment_based_on_payment_terms and self.linked_order_has_payment_terms(po_or_so, fieldname, doctype) ): for d in self.get("payment_schedule"): From d7f7ed5fec2bbbfde2ddc6518b806ec3629d150e Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Tue, 1 Aug 2023 15:46:53 +0530 Subject: [PATCH 2/3] test: payment allocation for payment terms --- .../purchase_invoice/test_purchase_invoice.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 8c9648047861..c45fb832b059 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -1736,6 +1736,52 @@ def test_gl_entries_for_standalone_debit_note(self): rate = flt(sle.stock_value_difference) / flt(sle.actual_qty) self.assertAlmostEqual(returned_inv.items[0].rate, rate) + def test_payment_allocation_for_payment_terms(self): + from erpnext.buying.doctype.purchase_order.test_purchase_order import ( + create_pr_against_po, + create_purchase_order, + ) + from erpnext.selling.doctype.sales_order.test_sales_order import ( + automatically_fetch_payment_terms, + ) + from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( + make_purchase_invoice as make_pi_from_pr, + ) + + automatically_fetch_payment_terms() + frappe.db.set_value( + "Payment Terms Template", + "_Test Payment Term Template", + "allocate_payment_based_on_payment_terms", + 0, + ) + + po = create_purchase_order(do_not_save=1) + po.payment_terms_template = "_Test Payment Term Template" + po.save() + po.submit() + + pr = create_pr_against_po(po.name, received_qty=4) + pi = make_pi_from_pr(pr.name) + self.assertEqual(pi.payment_schedule[0].payment_amount, 1000) + + frappe.db.set_value( + "Payment Terms Template", + "_Test Payment Term Template", + "allocate_payment_based_on_payment_terms", + 1, + ) + pi = make_pi_from_pr(pr.name) + self.assertEqual(pi.payment_schedule[0].payment_amount, 2500) + + automatically_fetch_payment_terms(enable=0) + frappe.db.set_value( + "Payment Terms Template", + "_Test Payment Term Template", + "allocate_payment_based_on_payment_terms", + 0, + ) + def set_advance_flag(company, flag, default_account): frappe.db.set_value( From 1f2c3d9501ae894cd578efad5831368f4f6bffb3 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Wed, 2 Aug 2023 10:47:33 +0530 Subject: [PATCH 3/3] chore: linting issues --- .../accounts/doctype/purchase_invoice/test_purchase_invoice.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 6c944e84d265..186b105f73c9 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -1838,7 +1838,6 @@ def test_offsetting_entries_for_accounting_dimensions(self): disable_dimension() - def set_advance_flag(company, flag, default_account): frappe.db.set_value( "Company",