Skip to content

Commit

Permalink
Draft: [14.0][ADD] keep latest report record attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
KKamaa committed Nov 18, 2023
1 parent d0c3dcc commit 8cb01b5
Show file tree
Hide file tree
Showing 17 changed files with 699 additions and 1 deletion.
97 changes: 97 additions & 0 deletions report_keep_latest_attachment/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
=============================
Report Keep Latest Attachment
=============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c1d2d814d9bb914eef442d1649473d697d6b97e5fc4ecda588ed6e7eff615c9c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/14.0/report_keep_latest_attachment
:alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/reporting-engine-14-0/reporting-engine-14-0-report_keep_latest_attachment
: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/reporting-engine&target_branch=14.0
:alt: Try me on Runboat

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

This module restricts pdf reports to keep only the latest attachment of the
report, by only storing the latest copy of it. Basically it removes duplicates
where applicable.

**Table of contents**

.. contents::
:local:

Configuration
=============

1. Go to *Technical -> Actions -> Reports* to the target report record (i.e ir.actions.report)
2. Check the *keep_latest_attachment* option under *Advanced Properties*.

Usage
=====

1. Go to *Technical -> Actions -> Reports* to the target report record (i.e ir.actions.report)
2. Check the *keep_latest_attachment* option under *Advanced Properties*
3. Generate attachments for selected report.

e.g Under *Sales -> Orders -> Quotations* records; send a draft order mail
attachment and check the attachments if duplicate attachment of the report
are saved and if only the latest remained.


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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/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/reporting-engine/issues/new?body=module:%20report_keep_latest_attachment%0Aversion:%2014.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
~~~~~~~

* Therp BV

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

* Kevin Kamau <[email protected]>
* Tom Blauwendraat <[email protected]>

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/reporting-engine <https://github.com/OCA/reporting-engine/tree/14.0/report_keep_latest_attachment>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions report_keep_latest_attachment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import models
15 changes: 15 additions & 0 deletions report_keep_latest_attachment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Report Keep Latest Attachment",
"version": "14.0.1.0.0",
"summary": "Keeps the latest attachment for a give report",
"author": "Therp BV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine",
"license": "LGPL-3",
"category": "Reporting",
"depends": [
"base",
],
"data": ["views/ir_actions_report.xml"],
}
3 changes: 3 additions & 0 deletions report_keep_latest_attachment/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import ir_actions_report
36 changes: 36 additions & 0 deletions report_keep_latest_attachment/models/ir_actions_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import fields, models


class IrActionsReport(models.Model):
_inherit = "ir.actions.report"

keep_latest_attachment = fields.Boolean()

def _post_pdf(self, save_in_attachment, pdf_content=None, res_ids=None):
ir_attachment_obj = self.env["ir.attachment"]
ids = []
if self.keep_latest_attachment:
if res_ids:
ids = res_ids
if save_in_attachment:
ids = list(save_in_attachment.keys())
if ids:
record = self.env[self.model_id.model].browse(ids)
domain = [
("res_model", "=", record._name),
("res_id", "=", str(record.id)),
("res_name", "ilike", "%{}%".format(record.name)),
("name", "ilike", "%.pdf"),
]
attachments = ir_attachment_obj.search(domain, order="create_date desc")

if len(attachments) > 1:
attachments_to_delete = attachments[1:]
if attachments_to_delete:
attachments_to_delete.unlink()

return super(IrActionsReport, self)._post_pdf(
save_in_attachment, pdf_content, res_ids
)
2 changes: 2 additions & 0 deletions report_keep_latest_attachment/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. Go to *Technical -> Actions -> Reports* to the target report record (i.e ir.actions.report)
2. Check the *keep_latest_attachment* option under *Advanced Properties*.
2 changes: 2 additions & 0 deletions report_keep_latest_attachment/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Kevin Kamau <[email protected]>
* Tom Blauwendraat <[email protected]>
3 changes: 3 additions & 0 deletions report_keep_latest_attachment/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module restricts pdf reports to keep only the latest attachment of the
report, by only storing the latest copy of it. Basically it removes duplicates
where applicable.
8 changes: 8 additions & 0 deletions report_keep_latest_attachment/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1. Go to *Technical -> Actions -> Reports* to the target report record (i.e ir.actions.report)
2. Check the *keep_latest_attachment* option under *Advanced Properties*
3. Generate attachments for selected report.

e.g Under *Sales -> Orders -> Quotations* records; send a draft order mail
attachment and check the attachments if duplicate attachment of the report
are saved and if only the latest remained.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8cb01b5

Please sign in to comment.