Skip to content

Commit f97f52f

Browse files
[16.0][IMP] Take allow_out_payment into account on payment order
A previous MR existed but only when payment order was triggered from invoices. We added the case also directement from confirm button on payment order original PR: #1177
1 parent 8f45bcc commit f97f52f

File tree

8 files changed

+81
-30
lines changed

8 files changed

+81
-30
lines changed

account_payment_mode/demo/payment_demo.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@
4444
<field name="acc_number">FR66 1212 1212 1212 1212 1212 121</field>
4545
<field name="bank_id" ref="bank_fiducial" />
4646
<field name="partner_id" ref="base.res_partner_12" />
47-
<field name="allow_out_payment" eval="True" />
4847
</record>
4948
<record id="res_partner_2_iban" model="res.partner.bank">
5049
<field name="acc_number">BE96 9988 7766 5544</field>
5150
<field name="bank_id" ref="bank_fortis" />
5251
<field name="partner_id" ref="base.res_partner_2" />
53-
<field name="allow_out_payment" eval="True" />
5452
</record>
5553
<!-- Asustek already has a demo IBAN provided by base_iban -->
5654
<record id="payment_mode_outbound_ct1" model="account.payment.mode">

account_payment_order/models/account_move.py

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

66
from odoo import _, api, fields, models
77
from odoo.exceptions import UserError
8-
from odoo.fields import first
98

109

1110
class AccountMove(models.Model):
@@ -152,24 +151,6 @@ def create_account_payment_line(self):
152151
"order": payment_lines.order_id.mapped("name"),
153152
}
154153
)
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-
173154
for payment_mode in payment_modes:
174155
payorder = apoo.search(
175156
move.get_account_payment_domain(payment_mode), limit=1

account_payment_order/models/account_move_line.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ def _prepare_payment_line_vals(self, payment_order):
7171
# in this case
7272
if payment_order.payment_type == "outbound":
7373
amount_currency *= -1
74-
partner_bank_id = self.partner_bank_id.id or first(self.partner_id.bank_ids).id
74+
partner_bank_id = self.partner_bank_id or first(self.partner_id.bank_ids)
7575
vals = {
7676
"order_id": payment_order.id,
77-
"partner_bank_id": partner_bank_id,
77+
"partner_bank_id": partner_bank_id.id,
7878
"partner_id": self.partner_id.id,
7979
"move_line_id": self.id,
8080
"communication": communication,

account_payment_order/models/account_payment_line.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from odoo import _, api, fields, models
55
from odoo.exceptions import UserError
6+
from odoo.fields import first
67

78

89
class AccountPaymentLine(models.Model):
@@ -249,3 +250,18 @@ def action_open_business_doc(self):
249250
if not self.move_line_id:
250251
return False
251252
return self.move_line_id.action_open_business_doc()
253+
254+
def _check_bank_allows_out_payments(self):
255+
for line in self:
256+
bank = line.partner_bank_id or first(line.partner_id.bank_ids)
257+
if bank and not bank.allow_out_payment:
258+
raise UserError(
259+
_(
260+
'The option "Send Money" is not enabled on the bank '
261+
"account %(bank_account)s of partner %(partner)s."
262+
)
263+
% {
264+
"bank_account": bank.acc_number,
265+
"partner": line.partner_id.name,
266+
}
267+
)

account_payment_order/models/account_payment_order.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from odoo import _, api, fields, models
1010
from odoo.exceptions import UserError, ValidationError
11+
from odoo.tools import str2bool
1112

1213

1314
class AccountPaymentOrder(models.Model):
@@ -338,6 +339,12 @@ def draft2open(self):
338339
for payline in order.payment_line_ids:
339340
try:
340341
payline.draft2open_payment_line_check()
342+
if str2bool(
343+
self.env["ir.config_parameter"]
344+
.sudo()
345+
.get_param("account_payment_order.use_allow_out_payment")
346+
):
347+
payline._check_bank_allows_out_payments()
341348
except UserError as e:
342349
payline_err_text.append(e.args[0])
343350
# Compute requested payment date

account_payment_order/tests/test_payment_order_outbound.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def setUpClass(cls, chart_template_ref=None):
2121
super().setUpClass(chart_template_ref=chart_template_ref)
2222
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
2323
cls.company = cls.company_data["company"]
24+
25+
cls.env["ir.config_parameter"].sudo().set_param(
26+
"account_payment_order.use_allow_out_payment", True
27+
)
2428
cls.env.user.company_id = cls.company.id
2529
cls.partner = cls.env["res.partner"].create(
2630
{
@@ -29,9 +33,7 @@ def setUpClass(cls, chart_template_ref=None):
2933
(
3034
0,
3135
0,
32-
{
33-
"acc_number": "TEST-NUMBER",
34-
},
36+
{"acc_number": "TEST-NUMBER", "allow_out_payment": True},
3537
)
3638
],
3739
}
@@ -234,7 +236,7 @@ def order_creation(self, date_prefered):
234236
order.payment_line_ids.partner_bank_id.action_unarchive()
235237
self.assertFalse(order.partner_banks_archive_msg)
236238
order.draft2open()
237-
self.assertEqual(order.payment_ids[0].partner_bank_id, self.partner.bank_ids)
239+
self.assertEqual(order.payment_ids[0].partner_bank_id, self.partner.bank_ids[0])
238240
order.open2generated()
239241
order.generated2uploaded()
240242
self.assertEqual(order.move_ids[0].date, order.payment_ids[0].date)
@@ -247,6 +249,7 @@ def _line_creation(self, outbound_order):
247249
"currency_id": outbound_order.payment_mode_id.company_id.currency_id.id,
248250
"amount_currency": 200.38,
249251
"move_line_id": self.invoice.invoice_line_ids[0].id,
252+
"partner_bank_id": self.partner_bank.id,
250253
}
251254
return self.env["account.payment.line"].create(vals)
252255

@@ -580,6 +583,7 @@ def test_action_open_business_document(self):
580583
self.assertEqual(invoice_action["res_id"], self.invoice.id)
581584
manual_line_action = order.payment_line_ids[1].action_open_business_doc()
582585
self.assertFalse(manual_line_action)
586+
583587
def test_check_allow_out_payment(self):
584588
"""Check that, in case option "Send Money" is not enabled on
585589
the bank, out payments are not allowed.
@@ -589,9 +593,37 @@ def test_check_allow_out_payment(self):
589593

590594
# Do not allow out payments
591595
self.partner_bank.allow_out_payment = False
596+
for line in self.invoice.line_ids:
597+
for bank in line.partner_id.bank_ids:
598+
bank.allow_out_payment = False
592599

600+
self.env["account.invoice.payment.line.multi"].with_context(
601+
active_model="account.move", active_ids=self.invoice.ids
602+
).create({}).run()
603+
payment_order = self.env["account.payment.order"].search(self.domain)
604+
payment_order.write({"journal_id": self.bank_journal.id})
593605
# Add to payment order using the wizard: error raised
594606
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()
607+
payment_order.draft2open()
608+
609+
def test_check_allow_out_payment_from_payment_order(self):
610+
"""Check that, in case option "Send Money" is not enabled on
611+
the bank, out payments are not allowed.
612+
"""
613+
self.partner_bank.allow_out_payment = False
614+
outbound_order = self.env["account.payment.order"].create(
615+
{
616+
"date_prefered": "due",
617+
"payment_type": "outbound",
618+
"payment_mode_id": self.mode.id,
619+
"journal_id": self.bank_journal.id,
620+
"description": "order with manual line",
621+
}
622+
)
623+
payment_line_1 = self._line_creation(outbound_order)
624+
625+
payment_line_1.partner_bank_id = self.partner_bank.id
626+
627+
# Add to payment order using the wizard: error raised
628+
with self.assertRaises(UserError):
629+
outbound_order.draft2open()

account_payment_order/wizard/res_config_settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ class ResConfigSettings(models.TransientModel):
1010
transfer_journal_id = fields.Many2one(
1111
related="company_id.transfer_journal_id", readonly=False
1212
)
13+
use_allow_out_payment = fields.Boolean(
14+
string=" Use allow out payment on partner bank",
15+
config_parameter=("account_payment_order.use_allow_out_payment"),
16+
)

account_payment_order/wizard/res_config_settings.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@
2323
</div>
2424
</div>
2525
</div>
26+
<div class="row mt16 o_settings_container" id="allow_out_payment_order">
27+
<div class="col-12 col-lg-6 o_setting_box">
28+
<div class="o_setting_left_pane">
29+
<field name="use_allow_out_payment" />
30+
</div>
31+
<div class="o_setting_right_pane">
32+
<label for="use_allow_out_payment" />
33+
<div class="text-muted">
34+
If checked, we will check that the account on payment order can be used for out payments
35+
</div>
36+
</div>
37+
</div>
38+
</div>
2639
</xpath>
2740
</field>
2841
</record>

0 commit comments

Comments
 (0)