Skip to content

Commit adb3c59

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 adb3c59

File tree

8 files changed

+56
-27
lines changed

8 files changed

+56
-27
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: 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):
@@ -244,3 +245,18 @@ def _prepare_account_payment_vals(self):
244245
if transfer_journal:
245246
vals["journal_id"] = transfer_journal.id
246247
return vals
248+
249+
def _check_bank_allows_out_payments(self):
250+
for line in self:
251+
bank = line.partner_bank_id or first(line.partner_id.bank_ids)
252+
if bank and not bank.allow_out_payment:
253+
raise UserError(
254+
_(
255+
'The option "Send Money" is not enabled on the bank '
256+
"account %(bank_account)s of partner %(partner)s."
257+
)
258+
% {
259+
"bank_account": bank.acc_number,
260+
"partner": line.partner_id.name,
261+
}
262+
)

account_payment_order/models/account_payment_order.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ def draft2open(self):
336336
for payline in order.payment_line_ids:
337337
try:
338338
payline.draft2open_payment_line_check()
339+
payline._check_bank_allows_out_payments()
339340
except UserError as e:
340341
payline_err_text.append(e.args[0])
341342
# Compute requested payment date

account_payment_order/tests/test_payment_order_outbound.py

Lines changed: 33 additions & 6 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,37 @@ 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

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

0 commit comments

Comments
 (0)