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
41 changes: 41 additions & 0 deletions l10n_fr_fec_background/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

=============================
Run FEC reports in Background
=============================

Usage
=====

* This module extends the features of l10n_fr_account module.

* It enables to run the FEC reports in background and after finishing the report, it will send an email to the requested/logged in user.

* It adds an option to download a report in .txt format.

|

.. image:: /l10n_fr_fec_background/static/src/image/FEC_Report.png
:width: 1100px


|

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/druidoo/FoodCoops/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Credits
=======

Contributors
------------

* La Louve <http://www.lalouve.net/>
* Druidoo <https://www.druidoo.io>
* Phan Hong Phuc \<<[email protected]>\>
1 change: 1 addition & 0 deletions l10n_fr_fec_background/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import wizard
16 changes: 16 additions & 0 deletions l10n_fr_fec_background/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "France - FEC Custom",
"version": "18.0.1.0.0",
"category": "Localization",
"summary": "Fichier d'Échange Informatisé (FEC) for France",
"author": "Druidoo,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-france",
"license": "AGPL-3",
"depends": ["l10n_fr_fec_oca", "queue_job"],
"data": [
"data/mail_templates.xml",
"wizard/account_fr_fec_view.xml",
],
"installable": True,
"auto_install": True,
}
15 changes: 15 additions & 0 deletions l10n_fr_fec_background/data/mail_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" ?>
<odoo noupdate="1">
<record id="send_fec_file_mail_template" model="mail.template">
<field name="name">Send FEC file</field>
<field
name="model_id"
ref="l10n_fr_fec_background.model_l10n_fr_fec_export_wizard"
/>
<field name="email_to">{{ object.env.user.partner_id.email }}</field>
<field name="partner_to">{{ object.env.user.partner_id.id }}</field>
<field name="subject">Your requested FEC file</field>
<field name="auto_delete" eval="False" />
<field name="body_html"><![CDATA[<p>Your requested FEC file</p>]]></field>
</record>
</odoo>
50 changes: 50 additions & 0 deletions l10n_fr_fec_background/i18n/l10n_fr_fec_background.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * l10n_fr_fec_background
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: l10n_fr_fec_background
#: model:mail.template,body_html:l10n_fr_fec_background.send_fec_file_mail_template
msgid "<p>Your requested FEC file</p>"
msgstr ""

#. module: l10n_fr_fec_background
#: model_terms:ir.ui.view,arch_db:l10n_fr_fec_background.account_fr_fec_view_inherit
msgid "CSV"
msgstr ""

#. module: l10n_fr_fec_background
#: model_terms:ir.ui.view,arch_db:l10n_fr_fec_background.account_fr_fec_view_inherit
msgid "CSV Background"
msgstr ""

#. module: l10n_fr_fec_background
#: model:ir.model,name:l10n_fr_fec_background.model_account_fr_fec
msgid "Ficher Echange Informatise"
msgstr ""

#. module: l10n_fr_fec_background
#: model_terms:ir.ui.view,arch_db:l10n_fr_fec_background.account_fr_fec_view_inherit
msgid "TXT"
msgstr ""

#. module: l10n_fr_fec_background
#: model_terms:ir.ui.view,arch_db:l10n_fr_fec_background.account_fr_fec_view_inherit
msgid "TXT Background"
msgstr ""

#. module: l10n_fr_fec_background
#: model:mail.template,subject:l10n_fr_fec_background.send_fec_file_mail_template
msgid "Your requested FEC file"
msgstr ""

3 changes: 3 additions & 0 deletions l10n_fr_fec_background/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
4 changes: 4 additions & 0 deletions l10n_fr_fec_background/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- La Louve \<<http://www.lalouve.net/>\>
- Druidoo \<<https://www.druidoo.io/>\>
- Trobz \<<https://www.trobz.com/>\>
- Phan Hong Phuc \<<[email protected]>\>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions l10n_fr_fec_background/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_l10n_fr_fec_background
33 changes: 33 additions & 0 deletions l10n_fr_fec_background/tests/test_l10n_fr_fec_background.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from odoo.tests.common import TransactionCase


class TestFrFECBackground(TransactionCase):
def setUp(self):
super().setUp()
self.fec_wizard = self.env["l10n_fr.fec.export.wizard"].create(
{"date_from": "2020-01-01", "date_to": "2020-02-29"}
)

def test_001_csv_report_background(self):
self.fec_wizard.generate_fec_file_in_background("csv", "|")
jobs = self.env["queue.job"].search(
[
("func_string", "like", str(self.fec_wizard)),
("state", "=", "pending"),
]
)
self.assertEqual(
len(jobs), 2, "Job for CSV Report is not created in background!"
)

def test_002_txt_report_background(self):
self.fec_wizard.generate_fec_file_in_background("txt", "\t")
jobs = self.env["queue.job"].search(
[
("func_string", "like", str(self.fec_wizard)),
("state", "=", "pending"),
]
)
self.assertEqual(
len(jobs), 2, "Job for TXT Report is not created in background!"
)
1 change: 1 addition & 0 deletions l10n_fr_fec_background/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_fr_fec
81 changes: 81 additions & 0 deletions l10n_fr_fec_background/wizard/account_fr_fec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from dateutil.relativedelta import relativedelta

from odoo import fields, models

from odoo.addons.queue_job.job import identity_exact


class AccountFrFec(models.TransientModel):
_inherit = "l10n_fr.fec.export.wizard"

def write(self, vals):
if self._context.get("extension", "") == "txt" and vals.get("filename"):
vals["filename"] = vals["filename"][:-3] + "txt"
return super().write(vals)

def export_fec_txt(self):
self.ensure_one()
return self.with_context(extension="txt").create_fec_report_action()

def export_fec_csv_background(self):
self.ensure_one()
return self.generate_fec_file_in_background()

def export_fec_txt_background(self):
self.ensure_one()
return self.generate_fec_file_in_background("txt")

def create_attachment(self, date_from, date_to, extension):
self.ensure_one()
self.date_from = date_from
self.date_to = date_to
results = self.with_context(extension=extension).generate_fec()
attachment = self.env["ir.attachment"].create(
{
"name": results.get("file_name"),
"store_fname": self.filename,
"db_datas": results.get("file_content"),
}
)
email_template = self.env.ref(
"l10n_fr_fec_background.send_fec_file_mail_template"
)
email_template.send_mail(
self.id,
force_send=True,
email_values={"attachment_ids": [(4, attachment.id)]},
)
return True

def generate_fec_file_in_background(self, extension="csv"):
self.ensure_one()
# Prepare periods
date_from = fields.Date.from_string(self.date_from)
date_to = fields.Date.from_string(self.date_to)
periods = self.prepare_periods(date_from, date_to)

# Call job
for period_from, period_to in periods:
self.write_fec_lines_session_job(period_from, period_to, extension)
return True

def prepare_periods(self, date_from, date_to):
periods = []
current_start = date_from

while current_start <= date_to:
current_end = current_start + relativedelta(day=31)
if current_end > date_to:
current_end = date_to

periods.append((current_start, current_end))
current_start = current_end + relativedelta(days=1)

return periods

def write_fec_lines_session_job(self, date_from, date_to, extension):
"""Job to write FEC lines per period"""
self.with_delay(
identity_key=identity_exact,
description="Create FEC attachment",
).create_attachment(date_from, date_to, extension)
40 changes: 40 additions & 0 deletions l10n_fr_fec_background/wizard/account_fr_fec_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="account_fr_fec_view_inherit" model="ir.ui.view">
<field name="name">l10n_fr.fec.export.wizard.view.inherit</field>
<field name="model">l10n_fr.fec.export.wizard</field>
<field name="priority">100</field>
<field name="inherit_id" ref="l10n_fr_fec_oca.account_fr_fec_oca_form" />
<field name="arch" type="xml">
<xpath
expr="//footer/button[@name='create_fec_report_action']"
position="after"
>
<button
string="TXT"
name="export_fec_txt"
type="object"
class="oe_highlight"
/>
<button
string="CSV Background"
name="export_fec_csv_background"
type="object"
class="oe_highlight"
/>
<button
string="TXT Background"
name="export_fec_txt_background"
type="object"
class="oe_highlight"
/>
</xpath>
<xpath
expr="//footer/button[@name='create_fec_report_action']"
position="attributes"
>
<attribute name="string">CSV</attribute>
</xpath>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
odoo-addon-l10n_fr_fec_oca @ git+https://github.com/OCA/l10n-france.git@refs/pull/687/head#subdirectory=l10n_fr_fec_oca
Loading