-
-
Notifications
You must be signed in to change notification settings - Fork 796
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft: [14.0][ADD] keep latest report record attachment
- Loading branch information
1 parent
5f69af6
commit 94e1fbe
Showing
18 changed files
with
741 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:8bf0d41eac285579cbab02964f0931e9605a4f01de81c55988c45265aad5ba33 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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 <kkahumba@therp.nl> | ||
* Tom Blauwendraat <tblauwendraat@therp.nl> | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 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"], | ||
"demo": ["demo/report_keep_latest_attachment_demo.xml"], | ||
} |
41 changes: 41 additions & 0 deletions
41
report_keep_latest_attachment/demo/report_keep_latest_attachment_demo.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<template id="report_keep_latest_attachment_demo_document"> | ||
<t t-call="web.external_layout"> | ||
<div class="page"> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<span> | ||
This is a sample report for testing keeping of the | ||
latest PDF Report. | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
</t> | ||
</template> | ||
<template id="report_keep_latest_attachment_demo"> | ||
<t t-call="web.html_container"> | ||
<t t-foreach="docs" t-as="o"> | ||
<t | ||
t-call="report_keep_latest_attachment.report_keep_latest_attachment_demo_document" | ||
t-lang="o.lang" | ||
/> | ||
</t> | ||
</t> | ||
</template> | ||
<record id="action_keep_latest_attachment_report" model="ir.actions.report"> | ||
<field name="name">Test PDF Latest Attachment</field> | ||
<field name="model">res.partner</field> | ||
<field name="report_type">qweb-pdf</field> | ||
<field | ||
name="report_name" | ||
>report_keep_latest_attachment.report_keep_latest_attachment_demo</field> | ||
<field name="attachment">'%s.pdf' % object.name or ''</field> | ||
<field name="attachment_use">True</field> | ||
<field name="binding_model_id" ref="base.model_res_partner" /> | ||
<field name="binding_type">report</field> | ||
</record> | ||
|
||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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*. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* Kevin Kamau <kkahumba@therp.nl> | ||
* Tom Blauwendraat <tblauwendraat@therp.nl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.