Skip to content

Commit

Permalink
Merge PR #1177 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Aug 22, 2024
2 parents f498d2b + 81254af commit 08f8f89
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions account_payment_mode/demo/payment_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
<field name="acc_number">FR66 1212 1212 1212 1212 1212 121</field>
<field name="bank_id" ref="bank_fiducial" />
<field name="partner_id" ref="base.res_partner_12" />
<field name="allow_out_payment" eval="True" />
</record>
<record id="res_partner_2_iban" model="res.partner.bank">
<field name="acc_number">BE96 9988 7766 5544</field>
<field name="bank_id" ref="bank_fortis" />
<field name="partner_id" ref="base.res_partner_2" />
<field name="allow_out_payment" eval="True" />
</record>
<!-- Asustek already has a demo IBAN provided by base_iban -->
<record id="payment_mode_outbound_ct1" model="account.payment.mode">
Expand Down
19 changes: 19 additions & 0 deletions account_payment_order/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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


class AccountMove(models.Model):
Expand Down Expand Up @@ -151,6 +152,24 @@ def create_account_payment_line(self):
"order": payment_lines.order_id.mapped("name"),
}
)

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

for payment_mode in payment_modes:
payorder = apoo.search(
move.get_account_payment_domain(payment_mode), limit=1
Expand Down
23 changes: 23 additions & 0 deletions account_payment_order/tests/test_payment_order_outbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def setUpClass(cls, chart_template_ref=None):
("company_id", "=", cls.env.user.company_id.id),
]
cls.env["account.payment.order"].search(cls.domain).unlink()
cls.partner_bank = cls.env["res.partner.bank"].create(
{
"acc_number": "1234",
"partner_id": cls.partner.id,
"allow_out_payment": True,
}
)

def _create_supplier_invoice(self, ref):
invoice = self.env["account.move"].create(
Expand Down Expand Up @@ -516,3 +523,19 @@ def test_supplier_manual_refund(self):
self.assertEqual(len(payment_order.payment_line_ids), 1)

self.assertEqual("F1242 R1234", payment_order.payment_line_ids.communication)

def test_check_allow_out_payment(self):
"""Check that, in case option "Send Money" is not enabled on
the bank, out payments are not allowed.
"""
# Open invoice
self.invoice.action_post()

# Do not allow out payments
self.partner_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()

0 comments on commit 08f8f89

Please sign in to comment.