Skip to content

Commit d6943e5

Browse files
astirpelmarion-source
authored andcommitted
[16.0][IMP] account_payment_order: check that bank allows out payments
1 parent 9b8437d commit d6943e5

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

account_payment_order/models/account_move.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from odoo import _, api, fields, models
77
from odoo.exceptions import UserError
8+
from odoo.fields import first
89

910

1011
class AccountMove(models.Model):
@@ -151,6 +152,24 @@ def create_account_payment_line(self):
151152
"order": payment_lines.order_id.mapped("name"),
152153
}
153154
)
155+
156+
# Check that the bank allows out payments
157+
for line in applicable_lines.filtered(
158+
lambda l: l.account_id.account_type == "liability_payable"
159+
):
160+
bank = line.partner_bank_id or first(line.partner_id.bank_ids)
161+
if bank and not bank.allow_out_payment:
162+
raise UserError(
163+
_(
164+
'The option "Send Money" is not enabled on the bank '
165+
"account %(bank_account)s of partner %(partner)s."
166+
)
167+
% {
168+
"bank_account": bank.bank_name,
169+
"partner": line.partner_id.name,
170+
}
171+
)
172+
154173
for payment_mode in payment_modes:
155174
payorder = apoo.search(
156175
move.get_account_payment_domain(payment_mode), limit=1

account_payment_order/tests/test_payment_order_outbound.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ def setUpClass(cls, chart_template_ref=None):
7979
("company_id", "=", cls.env.user.company_id.id),
8080
]
8181
cls.env["account.payment.order"].search(cls.domain).unlink()
82+
cls.partner_bank = cls.env["res.partner.bank"].create(
83+
{
84+
"acc_number": "1234",
85+
"partner_id": cls.partner.id,
86+
"allow_out_payment": True,
87+
}
88+
)
8289

8390
def _create_supplier_invoice(self, ref):
8491
invoice = self.env["account.move"].create(
@@ -573,3 +580,18 @@ def test_action_open_business_document(self):
573580
self.assertEqual(invoice_action["res_id"], self.invoice.id)
574581
manual_line_action = order.payment_line_ids[1].action_open_business_doc()
575582
self.assertFalse(manual_line_action)
583+
def test_check_allow_out_payment(self):
584+
"""Check that, in case option "Send Money" is not enabled on
585+
the bank, out payments are not allowed.
586+
"""
587+
# Open invoice
588+
self.invoice.action_post()
589+
590+
# Do not allow out payments
591+
self.partner_bank.allow_out_payment = False
592+
593+
# Add to payment order using the wizard: error raised
594+
with self.assertRaises(UserError):
595+
self.env["account.invoice.payment.line.multi"].with_context(
596+
active_model="account.move", active_ids=self.invoice.ids
597+
).create({}).run()

0 commit comments

Comments
 (0)