Skip to content
Open
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
4 changes: 2 additions & 2 deletions account_payment_order/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def _prepare_payment_line_vals(self, payment_order):
# in this case
if payment_order.payment_type == "outbound":
amount_currency *= -1
partner_bank_id = self.partner_bank_id.id or first(self.partner_id.bank_ids).id
partner_bank = self.partner_bank_id or first(self.partner_id.bank_ids)
vals = {
"order_id": payment_order.id,
"partner_bank_id": partner_bank_id,
"partner_bank_id": partner_bank.id,
"partner_id": self.partner_id.id,
"move_line_id": self.id,
"communication": communication,
Expand Down
16 changes: 16 additions & 0 deletions account_payment_order/models/account_payment_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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


class AccountPaymentLine(models.Model):
Expand Down Expand Up @@ -249,3 +250,18 @@ def action_open_business_doc(self):
if not self.move_line_id:
return False
return self.move_line_id.action_open_business_doc()

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,
}
)
7 changes: 7 additions & 0 deletions account_payment_order/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools import str2bool


class AccountPaymentOrder(models.Model):
Expand Down Expand Up @@ -338,6 +339,12 @@ def draft2open(self):
for payline in order.payment_line_ids:
try:
payline.draft2open_payment_line_check()
if str2bool(
self.env["ir.config_parameter"]
.sudo()
.get_param("account_payment_order.use_allow_out_payment")
):
payline._check_bank_allows_out_payments()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to check that payment_type is outbound here? Because this check does not make sense for a debit order.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmarion-source I looks like you have not handled this comment?

except UserError as e:
payline_err_text.append(e.args[0])
# Compute requested payment date
Expand Down
62 changes: 58 additions & 4 deletions account_payment_order/tests/test_payment_order_outbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.company = cls.company_data["company"]

cls.env["ir.config_parameter"].sudo().set_param(
"account_payment_order.use_allow_out_payment", True
)
cls.env.user.company_id = cls.company.id
cls.partner = cls.env["res.partner"].create(
{
Expand All @@ -29,9 +33,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 @@ -79,6 +81,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 @@ -227,7 +236,7 @@ def order_creation(self, date_prefered):
order.payment_line_ids.partner_bank_id.action_unarchive()
self.assertFalse(order.partner_banks_archive_msg)
order.draft2open()
self.assertEqual(order.payment_ids[0].partner_bank_id, self.partner.bank_ids)
self.assertEqual(order.payment_ids[0].partner_bank_id, self.partner.bank_ids[0])
order.open2generated()
order.generated2uploaded()
self.assertEqual(order.move_ids[0].date, order.payment_ids[0].date)
Expand All @@ -240,6 +249,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 @@ -573,3 +583,47 @@ def test_action_open_business_document(self):
self.assertEqual(invoice_action["res_id"], self.invoice.id)
manual_line_action = order.payment_line_ids[1].action_open_business_doc()
self.assertFalse(manual_line_action)

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
for line in self.invoice.line_ids:
for bank in line.partner_id.bank_ids:
bank.allow_out_payment = False

self.env["account.invoice.payment.line.multi"].with_context(
active_model="account.move", active_ids=self.invoice.ids
).create({}).run()
payment_order = self.env["account.payment.order"].search(self.domain)
payment_order.write({"journal_id": self.bank_journal.id})
# Add to payment order using the wizard: error raised
with self.assertRaises(UserError):
payment_order.draft2open()

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()
4 changes: 4 additions & 0 deletions account_payment_order/wizard/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ class ResConfigSettings(models.TransientModel):
transfer_journal_id = fields.Many2one(
related="company_id.transfer_journal_id", readonly=False
)
use_allow_out_payment = fields.Boolean(
string=" Use allow out payment on partner bank",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
string=" Use allow out payment on partner bank",
string="Verify that Send Money is enabled on partner bank accounts",

Is this easier to understand by non technical users?

config_parameter=("account_payment_order.use_allow_out_payment"),
)
13 changes: 13 additions & 0 deletions account_payment_order/wizard/res_config_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
</div>
</div>
</div>
<div class="row mt16 o_settings_container" id="allow_out_payment_order">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="use_allow_out_payment" />
</div>
<div class="o_setting_right_pane">
<label for="use_allow_out_payment" />
<div class="text-muted">
If checked, we will check that the account on payment order can be used for out payments
</div>
</div>
</div>
</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ends up in the next section. Not sure this is fixable in this PR, though.

Image

</xpath>
</field>
</record>
Expand Down