Skip to content

Commit a02bcff

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 404e6f5 commit a02bcff

File tree

7 files changed

+52
-20
lines changed

7 files changed

+52
-20
lines changed

account_banking_mandate/tests/test_invoice_mandate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def setUp(self):
215215
"partner_id": self.partner.id,
216216
"bank_id": self.acme_bank.id,
217217
"company_id": self.company.id,
218+
"allow_out_payment": True,
218219
}
219220
)
220221

account_banking_mandate_sale_contact/tests/test_account_banking_mandate_sale_contact.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def _create_res_partner_bank(cls, partner_id, acc_number):
8282
res_partner_bank_form = Form(cls.env["res.partner.bank"])
8383
res_partner_bank_form.partner_id = partner_id
8484
res_partner_bank_form.acc_number = acc_number
85+
res_partner_bank_form.allow_out_payment = True
8586
return res_partner_bank_form.save()
8687

8788
@classmethod

account_banking_sepa_direct_debit/tests/test_sdd.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def setUpClass(cls):
119119
"acc_type": "iban",
120120
}
121121
)
122+
bank1.allow_out_payment = True
122123
cls.mandate12 = cls.env.ref(
123124
"account_banking_sepa_direct_debit.res_partner_12_mandate"
124125
).copy(
@@ -136,6 +137,7 @@ def setUpClass(cls):
136137
"acc_type": "iban",
137138
}
138139
)
140+
bank2.allow_out_payment = True
139141
cls.mandate2 = cls.env.ref(
140142
"account_banking_sepa_direct_debit.res_partner_2_mandate"
141143
).copy(

account_payment_order/models/account_move.py

Lines changed: 2 additions & 16 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):
@@ -154,22 +153,9 @@ def create_account_payment_line(self):
154153
)
155154

156155
# Check that the bank allows out payments
157-
for line in applicable_lines.filtered(
156+
applicable_lines.filtered(
158157
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-
158+
)._check_bank_allows_out_payments()
173159
for payment_mode in payment_modes:
174160
payorder = apoo.search(
175161
move.get_account_payment_domain(payment_mode), limit=1

account_payment_order/models/account_move_line.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
44

5-
from odoo import api, fields, models
5+
from odoo import _, api, fields, models
6+
from odoo.exceptions import UserError
67
from odoo.fields import first
78

89

@@ -91,3 +92,18 @@ def create_payment_line_from_move_line(self, payment_order):
9192
for mline in self:
9293
vals_list.append(mline._prepare_payment_line_vals(payment_order))
9394
return self.env["account.payment.line"].create(vals_list)
95+
96+
def _check_bank_allows_out_payments(self):
97+
for line in self:
98+
bank = line.partner_bank_id or first(line.partner_id.bank_ids)
99+
if bank and not bank.allow_out_payment:
100+
raise UserError(
101+
_(
102+
'The option "Send Money" is not enabled on the bank '
103+
"account %(bank_account)s of partner %(partner)s."
104+
)
105+
% {
106+
"bank_account": bank.acc_number,
107+
"partner": line.partner_id.name,
108+
}
109+
)

account_payment_order/models/account_payment_order.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,10 @@ def draft2open(self):
336336
for payline in order.payment_line_ids:
337337
try:
338338
payline.draft2open_payment_line_check()
339+
payline.move_line_id._check_bank_allows_out_payments()
339340
except UserError as e:
340341
payline_err_text.append(e.args[0])
342+
341343
# Compute requested payment date
342344
if order.date_prefered == "due":
343345
requested_date = payline.ml_maturity_date or payline.date or today

account_payment_order/tests/test_payment_order_outbound.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ def setUpClass(cls, chart_template_ref=None):
2828
(
2929
0,
3030
0,
31-
{
32-
"acc_number": "TEST-NUMBER",
33-
},
31+
{"acc_number": "TEST-NUMBER", "allow_out_payment": True},
3432
)
3533
],
3634
}
@@ -239,6 +237,7 @@ def _line_creation(self, outbound_order):
239237
"currency_id": outbound_order.payment_mode_id.company_id.currency_id.id,
240238
"amount_currency": 200.38,
241239
"move_line_id": self.invoice.invoice_line_ids[0].id,
240+
"partner_bank_id": self.partner_bank.id,
242241
}
243242
return self.env["account.payment.line"].create(vals)
244243

@@ -533,9 +532,34 @@ def test_check_allow_out_payment(self):
533532

534533
# Do not allow out payments
535534
self.partner_bank.allow_out_payment = False
535+
for line in self.invoice.line_ids:
536+
for bank in line.partner_id.bank_ids:
537+
bank.allow_out_payment = False
536538

537539
# Add to payment order using the wizard: error raised
538540
with self.assertRaises(UserError):
539541
self.env["account.invoice.payment.line.multi"].with_context(
540542
active_model="account.move", active_ids=self.invoice.ids
541543
).create({}).run()
544+
545+
def test_check_allow_out_payment_from_payment_order(self):
546+
"""Check that, in case option "Send Money" is not enabled on
547+
the bank, out payments are not allowed.
548+
"""
549+
self.partner_bank.allow_out_payment = False
550+
outbound_order = self.env["account.payment.order"].create(
551+
{
552+
"date_prefered": "due",
553+
"payment_type": "outbound",
554+
"payment_mode_id": self.mode.id,
555+
"journal_id": self.bank_journal.id,
556+
"description": "order with manual line",
557+
}
558+
)
559+
payment_line_1 = self._line_creation(outbound_order)
560+
561+
payment_line_1.partner_bank_id = self.partner_bank.id
562+
563+
# Add to payment order using the wizard: error raised
564+
with self.assertRaises(UserError):
565+
outbound_order.draft2open()

0 commit comments

Comments
 (0)