Merge branch '17-imp-file-format-on-payment-mode' into '17.0'

[IMP]account_ebics: file format filter on ebics_upload

See merge request Noviat/Noviat_Generic/accounting-ebics!56
This commit is contained in:
Luc De Meyer 2024-05-18 18:08:04 +00:00
commit ed708ece80
11 changed files with 90 additions and 22 deletions

View File

@ -3,7 +3,7 @@
{ {
"name": "EBICS banking protocol", "name": "EBICS banking protocol",
"version": "17.0.1.0.2", "version": "17.0.1.1.0",
"license": "LGPL-3", "license": "LGPL-3",
"author": "Noviat", "author": "Noviat",
"website": "https://www.noviat.com", "website": "https://www.noviat.com",

View File

@ -1,4 +1,4 @@
# Copyright 2009-2023 Noviat. # Copyright 2009-2024 Noviat.
# License LGPL-3 or later (http://www.gnu.org/licenses/lgpl). # License LGPL-3 or later (http://www.gnu.org/licenses/lgpl).
import base64 import base64
@ -79,6 +79,9 @@ class EbicsXfer(models.TransientModel):
help="Select EBICS File Format to upload/download." help="Select EBICS File Format to upload/download."
"\nLeave blank to download all available files.", "\nLeave blank to download all available files.",
) )
upload_format_ids = fields.Many2many(
comodel_name="ebics.file.format", compute="_compute_upload_format_ids"
)
allowed_format_ids = fields.Many2many( allowed_format_ids = fields.Many2many(
related="ebics_config_id.ebics_file_format_ids", related="ebics_config_id.ebics_file_format_ids",
string="Allowed EBICS File Formats", string="Allowed EBICS File Formats",
@ -117,6 +120,17 @@ class EbicsXfer(models.TransientModel):
else: else:
rec.ebics_sig_passphrase_invisible = False rec.ebics_sig_passphrase_invisible = False
@api.depends("ebics_config_id")
def _compute_upload_format_ids(self):
for rec in self:
rec.upload_format_ids = False
if not self.env.context.get("ebics_download"):
rec.upload_format_ids = (
rec.ebics_config_id.ebics_file_format_ids.filtered(
lambda r: r.type == "up"
)
)
@api.onchange("ebics_config_id") @api.onchange("ebics_config_id")
def _onchange_ebics_config_id(self): def _onchange_ebics_config_id(self):
avail_userids = self.ebics_config_id.ebics_userid_ids.filtered( avail_userids = self.ebics_config_id.ebics_userid_ids.filtered(
@ -127,21 +141,26 @@ class EbicsXfer(models.TransientModel):
avail_formats = self.ebics_config_id.ebics_file_format_ids.filtered( avail_formats = self.ebics_config_id.ebics_file_format_ids.filtered(
lambda r: r.type == "down" lambda r: r.type == "down"
) )
if avail_formats and len(avail_formats) == 1:
self.format_id = avail_formats
else:
self.format_id = False
avail_userids = avail_userids.filtered( avail_userids = avail_userids.filtered(
lambda r: r.transaction_rights in ["both", "down"] lambda r: r.transaction_rights in ["both", "down"]
) )
else: # Upload Form else: # Upload Form
avail_formats = self.ebics_config_id.ebics_file_format_ids.filtered( if not self.env.context.get("active_model") == "account.payment.order":
lambda r: r.type == "up" avail_formats = self.ebics_config_id.ebics_file_format_ids.filtered(
) lambda r: r.type == "up"
)
if avail_formats and len(avail_formats) == 1:
self.format_id = avail_formats
else:
self.format_id = False
avail_userids = avail_userids.filtered( avail_userids = avail_userids.filtered(
lambda r: r.transaction_rights in ["both", "up"] lambda r: r.transaction_rights in ["both", "up"]
) )
if avail_formats and len(avail_formats) == 1:
self.format_id = avail_formats
else:
self.format_id = False
if avail_userids: if avail_userids:
if len(avail_userids) == 1: if len(avail_userids) == 1:
self.ebics_userid_id = avail_userids self.ebics_userid_id = avail_userids
@ -156,6 +175,8 @@ class EbicsXfer(models.TransientModel):
@api.onchange("upload_data") @api.onchange("upload_data")
def _onchange_upload_data(self): def _onchange_upload_data(self):
if self.env.context.get("active_model") == "account.payment.order":
return
self.upload_fname_dummy = self.upload_fname self.upload_fname_dummy = self.upload_fname
self.format_id = False self.format_id = False
self._detect_upload_format() self._detect_upload_format()
@ -173,10 +194,6 @@ class EbicsXfer(models.TransientModel):
if len(upload_formats) == 1: if len(upload_formats) == 1:
self.format_id = upload_formats self.format_id = upload_formats
@api.onchange("format_id")
def _onchange_format_id(self):
self.order_type = self.format_id.order_type
def ebics_upload(self): def ebics_upload(self):
self.ensure_one() self.ensure_one()
ctx = self._context.copy() ctx = self._context.copy()

View File

@ -91,10 +91,12 @@
<field name="upload_data" filename="upload_fname" required="1" /> <field name="upload_data" filename="upload_fname" required="1" />
<field name="upload_fname" invisible="1" /> <field name="upload_fname" invisible="1" />
<field name="upload_fname_dummy" string="Upload Filename" /> <field name="upload_fname_dummy" string="Upload Filename" />
<field name="upload_format_ids" invisible="1" />
<field <field
name="format_id" name="format_id"
required="1" required="1"
domain="[('type', '=', 'up'), ('id', 'in', allowed_format_ids)]" domain="[('type', '=', 'up'), ('id', 'in', allowed_format_ids)]"
readonly="context.get('active_model') == 'account.payment.order'"
/> />
<field name="order_type" /> <field name="order_type" />
<field name="test_mode" invisible="order_type not in ('FUL', 'BTU')" /> <field name="test_mode" invisible="order_type not in ('FUL', 'BTU')" />

View File

@ -3,7 +3,7 @@
{ {
"name": "Upload Batch Payment via EBICS", "name": "Upload Batch Payment via EBICS",
"version": "17.0.1.0.0", "version": "17.0.1.0.1",
"license": "LGPL-3", "license": "LGPL-3",
"author": "Noviat", "author": "Noviat",
"website": "https://www.noviat.com", "website": "https://www.noviat.com",

View File

@ -37,7 +37,6 @@ class AccountBatchPayment(models.Model):
ebics_xfer = self.env["ebics.xfer"].with_context(**ctx).create({}) ebics_xfer = self.env["ebics.xfer"].with_context(**ctx).create({})
ebics_xfer._onchange_ebics_config_id() ebics_xfer._onchange_ebics_config_id()
ebics_xfer._onchange_upload_data() ebics_xfer._onchange_upload_data()
ebics_xfer._onchange_format_id()
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": _("EBICS Upload"),

View File

@ -16,9 +16,13 @@ This module depends upon the following modules (cf. apps.odoo.com):
- account_ebics - account_ebics
- account_payment_order - account_payment_order
Configuration
=============
Set the EBICS File Format on your Payment Modes.
Usage Usage
===== =====
Create your Payment Order and generate the bank file. Create your Payment Order and generate the bank file.
Upload the generated file via the 'EBICS Upload' button on the payment order. Upload the generated file via the 'EBICS Upload' button on the payment order.

View File

@ -3,7 +3,7 @@
{ {
"name": "Upload Payment Order via EBICS", "name": "Upload Payment Order via EBICS",
"version": "17.0.1.0.0", "version": "17.0.1.1.0",
"license": "LGPL-3", "license": "LGPL-3",
"author": "Noviat", "author": "Noviat",
"website": "https://www.noviat.com", "website": "https://www.noviat.com",
@ -11,6 +11,7 @@
"depends": ["account_ebics", "account_payment_order"], "depends": ["account_ebics", "account_payment_order"],
"data": [ "data": [
"views/account_payment_order_views.xml", "views/account_payment_order_views.xml",
"views/account_payment_mode_views.xml",
], ],
"images": ["static/description/cover.png"], "images": ["static/description/cover.png"],
"installable": True, "installable": True,

View File

@ -1 +1,2 @@
from . import account_payment_mode
from . import account_payment_order from . import account_payment_order

View File

@ -0,0 +1,15 @@
# Copyright 2009-2024 Noviat.
# License LGPL-3 or later (http://www.gnu.org/licenses/lpgl).
from odoo import fields, models
class AccountPaymentMode(models.Model):
_inherit = "account.payment.mode"
ebics_format_id = fields.Many2one(
comodel_name="ebics.file.format",
string="EBICS File Format",
domain="[('type', '=', 'up')]",
help="Select EBICS File Format to upload.",
)

View File

@ -1,4 +1,4 @@
# Copyright 2009-2023 Noviat. # Copyright 2009-2024 Noviat.
# License LGPL-3 or later (http://www.gnu.org/licenses/lgpl). # License LGPL-3 or later (http://www.gnu.org/licenses/lgpl).
from odoo import _, models from odoo import _, models
@ -10,6 +10,18 @@ class AccountPaymentOrder(models.Model):
def ebics_upload(self): def ebics_upload(self):
self.ensure_one() self.ensure_one()
ctx = self.env.context.copy()
ebics_format_id = self.payment_mode_id.ebics_format_id
if not ebics_format_id:
raise UserError(
_("Missing EBICS File Format setting on your Payment Mode.")
)
ctx.update(
{
"active_model": self._name,
"default_format_id": ebics_format_id.id,
}
)
attach = self.env["ir.attachment"].search( attach = self.env["ir.attachment"].search(
[("res_model", "=", self._name), ("res_id", "=", self.id)] [("res_model", "=", self._name), ("res_id", "=", self.id)]
) )
@ -44,7 +56,6 @@ class AccountPaymentOrder(models.Model):
"for the selected bank." "for the selected bank."
) )
) )
ctx = self.env.context.copy()
if len(ebics_config) == 1: if len(ebics_config) == 1:
ctx["default_ebics_config_id"] = ebics_config.id ctx["default_ebics_config_id"] = ebics_config.id
ctx.update( ctx.update(
@ -52,13 +63,16 @@ class AccountPaymentOrder(models.Model):
"default_upload_data": attach.datas, "default_upload_data": attach.datas,
"default_upload_fname": attach.name, "default_upload_fname": attach.name,
"origin": origin, "origin": origin,
"force_comany": self.company_id.id,
} }
) )
ebics_xfer = self.env["ebics.xfer"].with_context(**ctx).create({}) ebics_xfer = (
self.env["ebics.xfer"]
.with_company(self.company_id)
.with_context(**ctx)
.create({})
)
ebics_xfer._onchange_ebics_config_id() ebics_xfer._onchange_ebics_config_id()
ebics_xfer._onchange_upload_data() ebics_xfer._onchange_upload_data()
ebics_xfer._onchange_format_id()
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": _("EBICS Upload"),

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="account_payment_mode_form" model="ir.ui.view">
<field name="name">account.payment.mode.form</field>
<field name="model">account.payment.mode</field>
<field name="inherit_id" ref="account_payment_mode.account_payment_mode_form" />
<field name="arch" type="xml">
<field name="payment_type" position="after">
<field name="ebics_format_id" invisible="not payment_order_ok" />
</field>
</field>
</record>
</odoo>