Skip to content
Snippets Groups Projects
Commit ab90580d87c3 authored by oury.balde's avatar oury.balde
Browse files

Overwrite postprocess_pdf_report hook to add doc attachment capabilities

parent 5bca3edf14ac
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,11 @@
""",
"website": "http://odoo.consulting/",
"depends": ["base", "document"],
"data": ["security/ir.model.access.csv", "views/document_attachment.xml"],
"data": [
"security/ir.model.access.csv",
"views/document_attachment.xml",
"views/ir_actions_report.xml",
],
"test": [],
"installable": True,
}
# flake8: noqa
from . import document_attachment
from . import ir_actions_report
##############################################################################
#
# Accounting customizations for GLE JAL
# Copyright (C) 2019 XCG Consulting (www.xcg-consulting.fr)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from odoo import api, fields, models
class IrActReport(models.Model):
_inherit = "ir.actions.report"
docatt_use = fields.Boolean(string="Save as Document Attachment")
docatt_field_id = fields.Many2one(
comodel_name="ir.model.fields",
string="Field for document attachment",
domain="""
[
('model', '=', model),
('relation', '=', 'document_attachment')
]
""",
help="Specify the field which will contain the document attachment.",
)
docatt_type_id = fields.Many2one(
comodel_name="document_attachment.type",
string="Document attachment type",
domain="[('model', '=', model)]",
help="Specify the document attachment type",
)
@api.multi
def postprocess_pdf_report(self, record, buffer):
"""Catch invoice reports to save a typed link to the attached document.
"""
attachment = super(IrActReport, self).postprocess_pdf_report(
record, buffer
)
if (
attachment
and self
and len(self) == 1
and self.docatt_type_id
and self.docatt_field_id
and self.report_name
):
setattr(
record,
self.docatt_field_id.name,
(
self.env["document_attachment"]
.with_context(res_id=record.id, res_model=record._name)
.create(
{
"file_id": attachment.id,
"type_id": self.docatt_type_id.id,
}
)
),
)
return attachment
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="docatt_act_report_xml_view" model="ir.ui.view">
<field name="name">docatt_act_report_xml_view</field>
<field name="model">ir.actions.report</field>
<field name="inherit_id" ref="base.act_report_xml_view" />
<field name="arch" type="xml">
<page name="advanced" position="inside">
<group>
<field name="docatt_use" />
<field name="docatt_field_id"
attrs="{
'invisible': [('docatt_use', '=', False)],
'required': [('docatt_use', '=', True)]
}" options="{'no_create': True}" />
<field name="docatt_type_id"
attrs="{
'invisible': [('docatt_use', '=', False)],
'required': [('docatt_use', '=', True)]
}" options="{'no_create': True}" />
</group>
</page>
</field>
</record>
</odoo>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment