Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] account_payment_order: check that bank allows out-payments #1177

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -153,6 +154,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 @@ -61,6 +61,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 @@ -451,3 +458,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()
Loading