mirror of
https://github.com/brain-tec/account_ebics.git
synced 2026-10-16 07:49:07 +00:00
[IMP] Add upload state tracking on EBICS payment files
account_ebics: - Add pain_state and ebics_order_number to ebics.file - Set these fields after a successful upload - Add neutralized property to api.Environment account_ebics_batch_payment: - Add EBICS notebook page with upload info to batch payment form - Post chatter message with OrderID after upload account_ebics_payment_order: - Fix broken postprocess: replace deprecated active_model/active_id context keys with model/id
This commit is contained in:
1 parent
2cfdbd50f8
commit
2d301e87f8
10 files changed
+109
-16
No files matched your search
@@ -1,5 +1,8 @@
|
||||
import functools
|
||||
import logging
|
||||
|
||||
from odoo import api
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
@@ -7,3 +10,22 @@ try:
|
||||
from . import wizards
|
||||
except Exception:
|
||||
_logger.warning("Import Error, check if fintech lib has been installed")
|
||||
|
||||
|
||||
@functools.cached_property
|
||||
def neutralized(self):
|
||||
return bool(
|
||||
self["ir.config_parameter"].sudo().get_param("database.is_neutralized")
|
||||
or self["ir.ui.view"]
|
||||
.sudo()
|
||||
.search_count(
|
||||
[
|
||||
("key", "in", ("web.neutralize_banner", "website.neutralize_ribbon")),
|
||||
("active", "=", True),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
api.Environment.neutralized = neutralized
|
||||
neutralized.__set_name__(api.Environment, "neutralized")
|
||||
@@ -5,7 +5,7 @@
|
||||
"name": "EBICS Banking Protocol",
|
||||
"summary": "Download bank statements and upload payment "
|
||||
"files directly from Odoo, using the European EBICS standard",
|
||||
"version": "19.0.1.2.0",
|
||||
"version": "19.0.1.3.0",
|
||||
"license": "LGPL-3",
|
||||
"author": "Noviat",
|
||||
"website": "https://www.noviat.com/",
|
||||
|
||||
@@ -70,6 +70,12 @@ class EbicsFile(models.Model):
|
||||
readonly=True,
|
||||
)
|
||||
note = fields.Text(string="Notes")
|
||||
ebics_order_number = fields.Char(string="EBICS OrderID", readonly=True)
|
||||
pain_state = fields.Selection(
|
||||
[("draft", "Draft"), ("uploaded", "Uploaded"), ("error", "Error")],
|
||||
default="draft",
|
||||
readonly=True,
|
||||
)
|
||||
note_process = fields.Text(
|
||||
string="Process Notes",
|
||||
readonly=True,
|
||||
|
||||
@@ -135,6 +135,10 @@
|
||||
string="Upload Date"
|
||||
invisible="context.get('ebics_mode') == 'down'"
|
||||
/>
|
||||
<field
|
||||
name="ebics_order_number"
|
||||
invisible="context.get('ebics_mode') != 'up'"
|
||||
/>
|
||||
<field name="user_id" />
|
||||
<field name="ebics_userid_id" />
|
||||
</group>
|
||||
|
||||
@@ -406,11 +406,9 @@ class EbicsXfer(models.TransientModel):
|
||||
self.note += self.env._(
|
||||
"EBICS File has been uploaded (OrderID %s).", OrderID
|
||||
)
|
||||
ef_note = self.env._("EBICS OrderID: %s", OrderID)
|
||||
ef_note = ""
|
||||
if self.env.context.get("origin"):
|
||||
ef_note += "\n" + self.env._(
|
||||
"Origin: %s", self.env.context["origin"]
|
||||
)
|
||||
ef_note = self.env._("Origin: %s", self.env.context["origin"])
|
||||
suffix = self.format_id.suffix
|
||||
fn = self.upload_fname
|
||||
if suffix and not fn.endswith(suffix):
|
||||
@@ -430,6 +428,9 @@ class EbicsXfer(models.TransientModel):
|
||||
}
|
||||
self._update_ef_vals(ef_vals)
|
||||
ebics_file = self.env["ebics.file"].create(ef_vals)
|
||||
ebics_file.write(
|
||||
{"ebics_order_number": OrderID, "pain_state": "uploaded"}
|
||||
)
|
||||
|
||||
except EbicsFunctionalError:
|
||||
e = exc_info()
|
||||
@@ -458,16 +459,32 @@ class EbicsXfer(models.TransientModel):
|
||||
OrderID = self.ebics_config_id._get_order_number()
|
||||
self.ebics_config_id.sudo()._update_order_number(OrderID)
|
||||
|
||||
ebics_file and self._payment_order_postprocess(ebics_file)
|
||||
ebics_file and self._payment_upload_postprocess(ebics_file)
|
||||
return ebics_file
|
||||
|
||||
def _payment_order_postprocess(self, ebics_file):
|
||||
active_model = self.env.context.get("model")
|
||||
def _payment_upload_postprocess(self, ebics_file):
|
||||
ctx = self.env.context
|
||||
active_model = ctx.get("model")
|
||||
active_id = ctx.get("id")
|
||||
payment_doc = None
|
||||
if active_model == "account.payment.order":
|
||||
order = self.env["account.payment.order"].browse(
|
||||
self.env.context["active_id"]
|
||||
payment_doc = self.env["account.payment.order"].browse(active_id)
|
||||
payment_doc.generated2uploaded()
|
||||
elif active_model == "account.batch.payment":
|
||||
payment_doc = self.env["account.batch.payment"].browse(active_id)
|
||||
if payment_doc:
|
||||
payment_doc.ebics_file_id = ebics_file
|
||||
self._payment_upload_chatter_message(payment_doc, ebics_file)
|
||||
|
||||
def _payment_upload_chatter_message(self, payment_doc, ebics_file):
|
||||
payment_doc.message_post(
|
||||
body=self.env._(
|
||||
"'%(filename)s' has been uploaded via EBICS"
|
||||
" (OrderID: %(order_number)s).",
|
||||
filename=ebics_file.name,
|
||||
order_number=ebics_file.ebics_order_number,
|
||||
)
|
||||
order.generated2uploaded()
|
||||
)
|
||||
|
||||
def _setup_client(self):
|
||||
self.ebics_config_id._check_ebics_keys()
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
{
|
||||
"name": "EBICS - Batch Payments (Odoo Enterprise)",
|
||||
"summary": "Send an Odoo Enterprise batch payment to the bank over EBICS",
|
||||
"version": "19.0.1.2.0",
|
||||
"version": "19.0.1.3.0",
|
||||
"license": "LGPL-3",
|
||||
"author": "Noviat",
|
||||
"website": "https://www.noviat.com/",
|
||||
|
||||
@@ -8,19 +8,47 @@ from odoo.exceptions import UserError
|
||||
class AccountBatchPayment(models.Model):
|
||||
_inherit = "account.batch.payment"
|
||||
|
||||
ebics_config_id = fields.Many2one(
|
||||
comodel_name="ebics.config",
|
||||
related="journal_id.ebics_config_id",
|
||||
)
|
||||
ebics_file_id = fields.Many2one(
|
||||
comodel_name="ebics.file",
|
||||
string="EBICS Upload File",
|
||||
readonly=True,
|
||||
)
|
||||
ebics_pain_state = fields.Selection(
|
||||
related="ebics_file_id.pain_state",
|
||||
string="EBICS Upload Status",
|
||||
)
|
||||
ebics_order_number = fields.Char(
|
||||
related="ebics_file_id.ebics_order_number",
|
||||
string="EBICS OrderID",
|
||||
)
|
||||
hide_ebics_upload = fields.Boolean(
|
||||
compute="_compute_hide_ebics_upload", default=True
|
||||
)
|
||||
|
||||
@api.depends("journal_id.ebics_config_id", "file_generation_enabled", "state")
|
||||
@api.depends(
|
||||
"journal_id.ebics_config_id",
|
||||
"file_generation_enabled",
|
||||
"state",
|
||||
"ebics_file_id.pain_state",
|
||||
)
|
||||
def _compute_hide_ebics_upload(self):
|
||||
for rec in self:
|
||||
rec.hide_ebics_upload = (
|
||||
not rec.journal_id.ebics_config_id
|
||||
self.env.neutralized
|
||||
or not rec.journal_id.ebics_config_id
|
||||
or not rec.file_generation_enabled
|
||||
or rec.state != "sent"
|
||||
or rec.ebics_pain_state == "uploaded"
|
||||
)
|
||||
|
||||
def export_batch_payment(self):
|
||||
self.filtered("ebics_file_id").write({"ebics_file_id": False})
|
||||
return super().export_batch_payment()
|
||||
|
||||
def ebics_upload(self):
|
||||
self.ensure_one()
|
||||
ctx = self.env.context.copy()
|
||||
@@ -38,6 +66,8 @@ class AccountBatchPayment(models.Model):
|
||||
"default_upload_data": self.export_file,
|
||||
"default_upload_fname": self.export_filename,
|
||||
"origin": origin,
|
||||
"model": self._name,
|
||||
"id": self.id,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -14,6 +14,19 @@
|
||||
class="oe_highlight"
|
||||
/>
|
||||
</button>
|
||||
<notebook position="inside">
|
||||
<page
|
||||
string="EBICS upload info"
|
||||
name="ebics"
|
||||
invisible="not ebics_config_id"
|
||||
>
|
||||
<group name="ebics_info">
|
||||
<field name="ebics_file_id" string="Upload File" />
|
||||
<field name="ebics_pain_state" string="Upload Status" />
|
||||
<field name="ebics_order_number" />
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -4,7 +4,7 @@
|
||||
{
|
||||
"name": "EBICS - Payment Orders (OCA)",
|
||||
"summary": "Send an OCA payment order to the bank over EBICS",
|
||||
"version": "19.0.1.0.0",
|
||||
"version": "19.0.1.0.1",
|
||||
"license": "LGPL-3",
|
||||
"author": "Noviat",
|
||||
"website": "https://www.noviat.com/",
|
||||
|
||||
@@ -29,7 +29,8 @@ class AccountPaymentOrder(models.Model):
|
||||
)
|
||||
ctx.update(
|
||||
{
|
||||
"active_model": self._name,
|
||||
"model": self._name,
|
||||
"id": self.id,
|
||||
"default_format_id": ebics_format_id.id,
|
||||
}
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user