Skip to content

Commit

Permalink
[16.0][IMP] Take allow_out_payment into account on payment order
Browse files Browse the repository at this point in the history
        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
  • Loading branch information
lmarion-source committed Sep 11, 2024
1 parent 404e6f5 commit a02bcff
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 20 deletions.
1 change: 1 addition & 0 deletions account_banking_mandate/tests/test_invoice_mandate.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def setUp(self):
"partner_id": self.partner.id,
"bank_id": self.acme_bank.id,
"company_id": self.company.id,
"allow_out_payment": True,
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def _create_res_partner_bank(cls, partner_id, acc_number):
res_partner_bank_form = Form(cls.env["res.partner.bank"])
res_partner_bank_form.partner_id = partner_id
res_partner_bank_form.acc_number = acc_number
res_partner_bank_form.allow_out_payment = True
return res_partner_bank_form.save()

@classmethod
Expand Down
2 changes: 2 additions & 0 deletions account_banking_sepa_direct_debit/tests/test_sdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def setUpClass(cls):
"acc_type": "iban",
}
)
bank1.allow_out_payment = True
cls.mandate12 = cls.env.ref(
"account_banking_sepa_direct_debit.res_partner_12_mandate"
).copy(
Expand All @@ -136,6 +137,7 @@ def setUpClass(cls):
"acc_type": "iban",
}
)
bank2.allow_out_payment = True
cls.mandate2 = cls.env.ref(
"account_banking_sepa_direct_debit.res_partner_2_mandate"
).copy(
Expand Down
18 changes: 2 additions & 16 deletions account_payment_order/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.fields import first


class AccountMove(models.Model):
Expand Down Expand Up @@ -154,22 +153,9 @@ def create_account_payment_line(self):
)

# Check that the bank allows out payments
for line in applicable_lines.filtered(
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,
}
)

)._check_bank_allows_out_payments()
for payment_mode in payment_modes:
payorder = apoo.search(
move.get_account_payment_domain(payment_mode), limit=1
Expand Down
18 changes: 17 additions & 1 deletion account_payment_order/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.fields import first


Expand Down Expand Up @@ -91,3 +92,18 @@ def create_payment_line_from_move_line(self, payment_order):
for mline in self:
vals_list.append(mline._prepare_payment_line_vals(payment_order))
return self.env["account.payment.line"].create(vals_list)

def _check_bank_allows_out_payments(self):
for line in self:
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.acc_number,
"partner": line.partner_id.name,
}
)
2 changes: 2 additions & 0 deletions account_payment_order/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,10 @@ def draft2open(self):
for payline in order.payment_line_ids:
try:
payline.draft2open_payment_line_check()
payline.move_line_id._check_bank_allows_out_payments()
except UserError as e:
payline_err_text.append(e.args[0])

# Compute requested payment date
if order.date_prefered == "due":
requested_date = payline.ml_maturity_date or payline.date or today
Expand Down
30 changes: 27 additions & 3 deletions account_payment_order/tests/test_payment_order_outbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def setUpClass(cls, chart_template_ref=None):
(
0,
0,
{
"acc_number": "TEST-NUMBER",
},
{"acc_number": "TEST-NUMBER", "allow_out_payment": True},
)
],
}
Expand Down Expand Up @@ -239,6 +237,7 @@ def _line_creation(self, outbound_order):
"currency_id": outbound_order.payment_mode_id.company_id.currency_id.id,
"amount_currency": 200.38,
"move_line_id": self.invoice.invoice_line_ids[0].id,
"partner_bank_id": self.partner_bank.id,
}
return self.env["account.payment.line"].create(vals)

Expand Down Expand Up @@ -533,9 +532,34 @@ def test_check_allow_out_payment(self):

# Do not allow out payments
self.partner_bank.allow_out_payment = False
for line in self.invoice.line_ids:
for bank in line.partner_id.bank_ids:
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()

def test_check_allow_out_payment_from_payment_order(self):
"""Check that, in case option "Send Money" is not enabled on
the bank, out payments are not allowed.
"""
self.partner_bank.allow_out_payment = False
outbound_order = self.env["account.payment.order"].create(
{
"date_prefered": "due",
"payment_type": "outbound",
"payment_mode_id": self.mode.id,
"journal_id": self.bank_journal.id,
"description": "order with manual line",
}
)
payment_line_1 = self._line_creation(outbound_order)

payment_line_1.partner_bank_id = self.partner_bank.id

# Add to payment order using the wizard: error raised
with self.assertRaises(UserError):
outbound_order.draft2open()

0 comments on commit a02bcff

Please sign in to comment.