Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] account_invoice_files_download #1096

Open
wants to merge 8 commits into
base: 16.0
Choose a base branch
from
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
87 changes: 87 additions & 0 deletions account_invoice_files_download/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
==============================
Account Invoice Files Download
==============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:66222ecd351b6fd4c6e33cc1e6ba5e586921554ea203d4415a1405600b4f5ad3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github
:target: https://github.com/OCA/edi/tree/16.0/account_invoice_files_download
:alt: OCA/edi
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-account_invoice_files_download
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Allow to download all files (PDF, EDI files) of (possibly multiple) invoices
as one zip file.

**Table of contents**

.. contents::
:local:

Usage
=====

This module adds a “Download invoice files (zip)” action on invoices. It is
available from the actions menu on the invoice form and on the invoice list
when invoices are selected.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_files_download%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Coop IT Easy SC

Contributors
~~~~~~~~~~~~

* `Coop IT Easy SC <https://coopiteasy.be>`_:

* Rémy Taymans <[email protected]>
* hugues de keyzer

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/16.0/account_invoice_files_download>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions account_invoice_files_download/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2021 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from . import models
19 changes: 19 additions & 0 deletions account_invoice_files_download/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: 2021 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

{
"name": "Account Invoice Files Download",
"summary": "Allow to download all files of invoices as one zip file",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Coop IT Easy SC, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/edi",
"depends": [
"account_edi",
],
"data": [
"data/ir_actions_server.xml",
"data/ir_cron.xml",
],
}
17 changes: 17 additions & 0 deletions account_invoice_files_download/data/ir_actions_server.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
SPDX-FileCopyrightText: 2021 Coop IT Easy SC

SPDX-License-Identifier: AGPL-3.0-or-later
-->
<odoo>

<record id="account_invoice_download_edi_files_zip" model="ir.actions.server">
<field name="name">Download invoice files (zip)</field>
<field name="model_id" ref="model_account_move" />
<field name="binding_model_id" ref="model_account_move" />
<field name="state">code</field>
<field name="code">action = records.download_edi_files_zip()</field>
</record>

</odoo>
18 changes: 18 additions & 0 deletions account_invoice_files_download/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
SPDX-FileCopyrightText: 2021 Coop IT Easy SC

SPDX-License-Identifier: AGPL-3.0-or-later
-->
<odoo>
<record id="ir_cron_remove_tmp_edi_zip_files" model="ir.cron">
<field name="name">Remove temporary EDI zip files</field>
<field name="model_id" ref="model_account_move" />
<field name="state">code</field>
<field name="code">model._cron_remove_tmp_edi_zip_files()</field>
<field name='interval_number'>1</field>
<field name='interval_type'>days</field>
<field name="numbercall">-1</field>
<field name="active" eval="True" />
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_invoice_files_download
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.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: account_invoice_files_download
#: code:addons/account_invoice_files_download/models/account_move.py:0
#, python-format
msgid ""
"Cannot generate file because invoice {invoice_name} is not an invoice or a "
"refund or that invoice is not posted."
msgstr ""

#. module: account_invoice_files_download
#: model:ir.model.fields,field_description:account_invoice_files_download.field_account_move__display_name
msgid "Display Name"
msgstr ""

#. module: account_invoice_files_download
#: model:ir.actions.server,name:account_invoice_files_download.account_invoice_download_edi_files_zip
msgid "Download invoice files (zip)"
msgstr ""

#. module: account_invoice_files_download
#: model:ir.model.fields,field_description:account_invoice_files_download.field_account_move__id
msgid "ID"
msgstr ""

#. module: account_invoice_files_download
#: model:ir.model,name:account_invoice_files_download.model_account_move
msgid "Journal Entry"
msgstr ""

#. module: account_invoice_files_download
#: model:ir.model.fields,field_description:account_invoice_files_download.field_account_move____last_update
msgid "Last Modified on"
msgstr ""

#. module: account_invoice_files_download
#: model:ir.actions.server,name:account_invoice_files_download.ir_cron_remove_tmp_edi_zip_files_ir_actions_server
#: model:ir.cron,cron_name:account_invoice_files_download.ir_cron_remove_tmp_edi_zip_files
#: model:ir.cron,name:account_invoice_files_download.ir_cron_remove_tmp_edi_zip_files
msgid "Remove temporary EDI zip files"
msgstr ""
57 changes: 57 additions & 0 deletions account_invoice_files_download/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_invoice_files_download
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: account_invoice_files_download
#: code:addons/account_invoice_files_download/models/account_move.py:0
#, python-format
msgid ""
"Cannot generate file because invoice {invoice_name} is not an invoice or a "
"refund or that invoice is not posted."
msgstr ""
"Impossible de générer le fichier car la facture {invoice_name} n'est pas une "
"facture ou un avoir ou la facture n'est pas comptabilisée."

#. module: account_invoice_files_download
#: model:ir.model.fields,field_description:account_invoice_files_download.field_account_move__display_name
msgid "Display Name"
msgstr ""

#. module: account_invoice_files_download
#: model:ir.actions.server,name:account_invoice_files_download.account_invoice_download_edi_files_zip
msgid "Download invoice files (zip)"
msgstr "Télécharcher les fichiers de facture (zip)"

#. module: account_invoice_files_download
#: model:ir.model.fields,field_description:account_invoice_files_download.field_account_move__id
msgid "ID"
msgstr ""

#. module: account_invoice_files_download
#: model:ir.model,name:account_invoice_files_download.model_account_move
msgid "Journal Entry"
msgstr ""

#. module: account_invoice_files_download
#: model:ir.model.fields,field_description:account_invoice_files_download.field_account_move____last_update
msgid "Last Modified on"
msgstr ""

#. module: account_invoice_files_download
#: model:ir.actions.server,name:account_invoice_files_download.ir_cron_remove_tmp_edi_zip_files_ir_actions_server
#: model:ir.cron,cron_name:account_invoice_files_download.ir_cron_remove_tmp_edi_zip_files
#: model:ir.cron,name:account_invoice_files_download.ir_cron_remove_tmp_edi_zip_files
msgid "Remove temporary EDI zip files"
msgstr "Supprimer les fichiers zip EDI temporaires"
5 changes: 5 additions & 0 deletions account_invoice_files_download/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2021 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from . import account_move
95 changes: 95 additions & 0 deletions account_invoice_files_download/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# SPDX-FileCopyrightText: 2021 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

import io
import logging
import zipfile

from odoo import _, fields, models
from odoo.exceptions import UserError
from odoo.tools.safe_eval import safe_eval, time

_logger = logging.getLogger(__name__)

ATTACHMENT_TMP_DESC = "temporary-invoice-edi-zip-file"
ZIP_FILE_NAME = "invoice_files-{timestamp}.zip"
REPORT_REF = "account.account_invoices"
PDF_EMBEDDED_EDI_FORMATS = ["facturx_1_0_05"]


class AccountMove(models.Model):
_inherit = "account.move"

def _get_invoice_pdf(self):
report = self.env.ref(REPORT_REF)
report_name = safe_eval(

Check warning on line 26 in account_invoice_files_download/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_files_download/models/account_move.py#L25-L26

Added lines #L25 - L26 were not covered by tests
report.print_report_name, {"object": self, "time": time}
)
filename = "{}.pdf".format(report_name.replace("/", "_"))
report_contents = report._render_qweb_pdf(REPORT_REF, [self.id])[0]
return filename, report_contents

Check warning on line 31 in account_invoice_files_download/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_files_download/models/account_move.py#L29-L31

Added lines #L29 - L31 were not covered by tests

def _add_invoice_edi_files(self, ziparc):
# first, the pdf must be generated, because some of the edi documents
# will be embedded in it, while others will embed the pdf in them.
pdf_filename, pdf_contents = self._get_invoice_pdf()
ziparc.writestr(pdf_filename, pdf_contents)

Check warning on line 37 in account_invoice_files_download/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_files_download/models/account_move.py#L36-L37

Added lines #L36 - L37 were not covered by tests
# now, add all edi documents that are not embedded in the pdf.
for edi_document in self.edi_document_ids:
if edi_document.edi_format_id.code in PDF_EMBEDDED_EDI_FORMATS:
# already present in the pdf
continue
attachment = edi_document.attachment_id
ziparc.writestr(attachment.name, attachment.raw)

Check warning on line 44 in account_invoice_files_download/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_files_download/models/account_move.py#L42-L44

Added lines #L42 - L44 were not covered by tests

def download_edi_files_zip(self):
"""
Create a zip file with the EDI documents and the PDF for each invoice.
"""
for invoice in self:
# fail fast
if (
invoice.move_type not in ("out_invoice", "out_refund")
or invoice.state != "posted"
):
raise UserError(

Check warning on line 56 in account_invoice_files_download/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_files_download/models/account_move.py#L56

Added line #L56 was not covered by tests
_(
"Cannot generate file because invoice {invoice_name} "
"is not an invoice or a refund or that invoice is "
"not posted."
).format(invoice_name=invoice.name)
)
with io.BytesIO() as buffer:
with zipfile.ZipFile(

Check warning on line 64 in account_invoice_files_download/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_files_download/models/account_move.py#L63-L64

Added lines #L63 - L64 were not covered by tests
buffer, mode="w", compression=zipfile.ZIP_DEFLATED
) as ziparc:
for invoice in self:
invoice._add_invoice_edi_files(ziparc)
zip_filename = ZIP_FILE_NAME.format(

Check warning on line 69 in account_invoice_files_download/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_files_download/models/account_move.py#L68-L69

Added lines #L68 - L69 were not covered by tests
timestamp=fields.Datetime.now().isoformat().replace(":", "-"),
)
attachment = self.env["ir.attachment"].create(

Check warning on line 72 in account_invoice_files_download/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_files_download/models/account_move.py#L72

Added line #L72 was not covered by tests
{
"name": zip_filename,
"description": ATTACHMENT_TMP_DESC,
"raw": buffer.getvalue(),
"type": "binary",
}
)
return {

Check warning on line 80 in account_invoice_files_download/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_files_download/models/account_move.py#L80

Added line #L80 was not covered by tests
"type": "ir.actions.act_url",
"url": "/web/content/ir.attachment/{}/datas?download=true".format(
attachment.id
),
"target": "self",
}

def _cron_remove_tmp_edi_zip_files(self):
"""
Find temporary zipped file created and delete it.
"""
_logger.info("Removing temporary EDI zip files")
self.env["ir.attachment"].search(

Check warning on line 93 in account_invoice_files_download/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_files_download/models/account_move.py#L92-L93

Added lines #L92 - L93 were not covered by tests
[("description", "=", ATTACHMENT_TMP_DESC)]
).unlink()
4 changes: 4 additions & 0 deletions account_invoice_files_download/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Coop IT Easy SC <https://coopiteasy.be>`_:

* Rémy Taymans <[email protected]>
* hugues de keyzer
2 changes: 2 additions & 0 deletions account_invoice_files_download/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Allow to download all files (PDF, EDI files) of (possibly multiple) invoices
as one zip file.
3 changes: 3 additions & 0 deletions account_invoice_files_download/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module adds a “Download invoice files (zip)” action on invoices. It is
available from the actions menu on the invoice form and on the invoice list
when invoices are selected.
Loading
Loading