From a7b64baf909fe05eed7c579d6b2fe0316768eb73 Mon Sep 17 00:00:00 2001 From: Andrea Stirpe Date: Tue, 14 Nov 2023 14:06:59 +0100 Subject: [PATCH 1/2] [16.0][IMP] account_payment_order: check that bank allows out payments --- account_payment_order/models/account_move.py | 19 +++++++++++++++ .../tests/test_payment_order_outbound.py | 23 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/account_payment_order/models/account_move.py b/account_payment_order/models/account_move.py index c7bcbe9d597c..7620bcd2ad01 100644 --- a/account_payment_order/models/account_move.py +++ b/account_payment_order/models/account_move.py @@ -5,6 +5,7 @@ from odoo import _, api, fields, models from odoo.exceptions import UserError +from odoo.fields import first class AccountMove(models.Model): @@ -153,6 +154,24 @@ def create_account_payment_line(self): "order": payment_lines.order_id.mapped("name"), } ) + + # Check that the bank allows out payments + for line in applicable_lines.filtered( + lambda l: l.account_id.account_type == "liability_payable" + ): + bank = line.partner_bank_id or first(line.partner_id.bank_ids) + if bank and not bank.allow_out_payment: + raise UserError( + _( + 'The option "Send Money" is not enabled on the bank ' + "account %(bank_account)s of partner %(partner)s." + ) + % { + "bank_account": bank.bank_name, + "partner": line.partner_id.name, + } + ) + for payment_mode in payment_modes: payorder = apoo.search( move.get_account_payment_domain(payment_mode), limit=1 diff --git a/account_payment_order/tests/test_payment_order_outbound.py b/account_payment_order/tests/test_payment_order_outbound.py index 681616243ffb..ce6615b914d1 100644 --- a/account_payment_order/tests/test_payment_order_outbound.py +++ b/account_payment_order/tests/test_payment_order_outbound.py @@ -61,6 +61,13 @@ def setUpClass(cls, chart_template_ref=None): ("company_id", "=", cls.env.user.company_id.id), ] cls.env["account.payment.order"].search(cls.domain).unlink() + cls.partner_bank = cls.env["res.partner.bank"].create( + { + "acc_number": "1234", + "partner_id": cls.partner.id, + "allow_out_payment": True, + } + ) def _create_supplier_invoice(self, ref): invoice = self.env["account.move"].create( @@ -451,3 +458,19 @@ def test_supplier_manual_refund(self): self.assertEqual(len(payment_order.payment_line_ids), 1) self.assertEqual("F1242 R1234", payment_order.payment_line_ids.communication) + + def test_check_allow_out_payment(self): + """Check that, in case option "Send Money" is not enabled on + the bank, out payments are not allowed. + """ + # Open invoice + self.invoice.action_post() + + # Do not allow out payments + self.partner_bank.allow_out_payment = False + + # Add to payment order using the wizard: error raised + with self.assertRaises(UserError): + self.env["account.invoice.payment.line.multi"].with_context( + active_model="account.move", active_ids=self.invoice.ids + ).create({}).run() From 81254af039b57d61e6b62ec8a956cc1ba654588c Mon Sep 17 00:00:00 2001 From: Andrea Stirpe Date: Tue, 14 Nov 2023 15:34:39 +0100 Subject: [PATCH 2/2] [IMP] account_payment_mode: set allow_out_payment on demo banks --- account_payment_mode/demo/payment_demo.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/account_payment_mode/demo/payment_demo.xml b/account_payment_mode/demo/payment_demo.xml index 927f6ec9aad9..888cc448fce8 100644 --- a/account_payment_mode/demo/payment_demo.xml +++ b/account_payment_mode/demo/payment_demo.xml @@ -44,11 +44,13 @@ FR66 1212 1212 1212 1212 1212 121 + BE96 9988 7766 5544 +