[IMP] payment order: hide ebics_upload button on non-ebics journals

This commit is contained in:
Luc De Meyer
2026-04-14 19:16:57 +02:00
parent 747e5a81c8
commit c6e2660128
4 changed files with 23 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
# Copyright 2009-2024 Noviat. # Copyright 2015 Noviat.
# License LGPL-3 or later (https://www.gnu.org/licenses/lgpl). # License LGPL-3 or later (https://www.gnu.org/licenses/lgpl).
{ {

View File

@@ -1,4 +1,4 @@
# Copyright 2009-2024 Noviat. # Copyright 2015 Noviat.
# License LGPL-3 or later (https://www.gnu.org/licenses/lpgl). # License LGPL-3 or later (https://www.gnu.org/licenses/lpgl).
from odoo import fields, models from odoo import fields, models

View File

@@ -1,20 +1,28 @@
# Copyright 2009-2024 Noviat. # Copyright 2015 Noviat.
# License LGPL-3 or later (https://www.gnu.org/licenses/lgpl). # License LGPL-3 or later (https://www.gnu.org/licenses/lgpl).
from odoo import _, models from odoo import fields, models
from odoo.exceptions import UserError from odoo.exceptions import UserError
class AccountPaymentOrder(models.Model): class AccountPaymentOrder(models.Model):
_inherit = "account.payment.order" _inherit = "account.payment.order"
hide_ebics_upload = fields.Boolean(compute="_compute_hide_ebics_upload")
def _compute_hide_ebics_upload(self):
for rec in self:
rec.hide_ebics_upload = (
not rec.journal_id.ebics_config_id or rec.state != "generated"
)
def ebics_upload(self): def ebics_upload(self):
self.ensure_one() self.ensure_one()
ctx = self.env.context.copy() ctx = self.env.context.copy()
ebics_format_id = self.payment_mode_id.ebics_format_id ebics_format_id = self.payment_mode_id.ebics_format_id
if not ebics_format_id: if not ebics_format_id:
raise UserError( raise UserError(
_("Missing EBICS File Format setting on your Payment Mode.") self.env._("Missing EBICS File Format setting on your Payment Mode.")
) )
ctx.update( ctx.update(
{ {
@@ -27,14 +35,14 @@ class AccountPaymentOrder(models.Model):
) )
if not attach: if not attach:
raise UserError( raise UserError(
_( self.env._(
"This payment order doesn't contains attachements." "This payment order doesn't contains attachments."
"\nPlease generate first the Payment Order file first." "\nPlease generate first the Payment Order file."
) )
) )
elif len(attach) > 1: elif len(attach) > 1:
raise UserError( raise UserError(
_( self.env._(
"This payment order contains multiple attachments." "This payment order contains multiple attachments."
"\nPlease remove the obsolete attachments or upload " "\nPlease remove the obsolete attachments or upload "
"the payment order file via the " "the payment order file via the "
@@ -42,24 +50,17 @@ class AccountPaymentOrder(models.Model):
) )
) )
else: else:
origin = _("Payment Order") + ": " + self.name origin = self.env._("Payment Order") + ": " + self.name
ebics_config = self.env["ebics.config"].search( if not self.journal_id.ebics_config_id:
[
("journal_ids", "=", self.journal_id.id),
("state", "=", "confirm"),
]
)
if not ebics_config:
raise UserError( raise UserError(
_( self.env._(
"No active EBICS configuration available " "No active EBICS configuration available "
"for the selected bank." "for the selected bank."
) )
) )
if len(ebics_config) == 1:
ctx["default_ebics_config_id"] = ebics_config.id
ctx.update( ctx.update(
{ {
"default_ebics_config_id": self.journal_id.ebics_config_id.id,
"default_upload_data": attach.datas, "default_upload_data": attach.datas,
"default_upload_fname": attach.name, "default_upload_fname": attach.name,
"origin": origin, "origin": origin,
@@ -75,7 +76,7 @@ class AccountPaymentOrder(models.Model):
ebics_xfer._onchange_upload_data() ebics_xfer._onchange_upload_data()
view = self.env.ref("account_ebics.ebics_xfer_view_form_upload") view = self.env.ref("account_ebics.ebics_xfer_view_form_upload")
act = { act = {
"name": _("EBICS Upload"), "name": self.env._("EBICS Upload"),
"view_mode": "form", "view_mode": "form",
"res_model": "ebics.xfer", "res_model": "ebics.xfer",
"view_id": view.id, "view_id": view.id,

View File

@@ -12,7 +12,7 @@
<button <button
name="ebics_upload" name="ebics_upload"
type="object" type="object"
invisible="state != 'generated'" invisible="hide_ebics_upload"
string="EBICS Upload" string="EBICS Upload"
class="oe_highlight" class="oe_highlight"
/> />