[IMP] report_batch: black, isort, prettier
parent
912fc102cc
commit
45d3686a7b
|
@ -3,20 +3,15 @@
|
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Batch Report Printing',
|
||||
'summary': 'Ability to print multiple QWeb reports in a single batch.',
|
||||
'version': '11.0.1.0.0',
|
||||
'license': 'AGPL-3',
|
||||
'author': 'Open Source Integrators, Odoo Community Association (OCA)',
|
||||
'category': 'Reporting',
|
||||
'website': 'http://www.opensourceintegrators.com',
|
||||
'depends': [
|
||||
'stock',
|
||||
],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'views/ir_action_report_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'maintainers': ['bodedra'],
|
||||
"name": "Batch Report Printing",
|
||||
"summary": "Ability to print multiple QWeb reports in a single batch.",
|
||||
"version": "11.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Open Source Integrators, Odoo Community Association (OCA)",
|
||||
"category": "Reporting",
|
||||
"website": "http://www.opensourceintegrators.com",
|
||||
"depends": ["stock",],
|
||||
"data": ["security/ir.model.access.csv", "views/ir_action_report_view.xml",],
|
||||
"installable": True,
|
||||
"maintainers": ["bodedra"],
|
||||
}
|
||||
|
|
|
@ -2,86 +2,98 @@
|
|||
# Copyright (C) 2019 Open Source Integrators
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
import random
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class IrActionsReportSubreport(models.Model):
|
||||
_name = 'ir.actions.report.subreport'
|
||||
_description = 'Report Subreport'
|
||||
_order = 'sequence'
|
||||
_name = "ir.actions.report.subreport"
|
||||
_description = "Report Subreport"
|
||||
_order = "sequence"
|
||||
|
||||
parent_report_id = fields.Many2one('ir.actions.report', ondelete='cascade')
|
||||
parent_report_id = fields.Many2one("ir.actions.report", ondelete="cascade")
|
||||
sequence = fields.Integer(default=10)
|
||||
model = fields.Char(related='parent_report_id.model')
|
||||
model = fields.Char(related="parent_report_id.model")
|
||||
subreport_id = fields.Many2one(
|
||||
'ir.actions.report', string='Subreport', required=True)
|
||||
"ir.actions.report", string="Subreport", required=True
|
||||
)
|
||||
|
||||
|
||||
class IrActionsReport(models.Model):
|
||||
_inherit = 'ir.actions.report'
|
||||
_inherit = "ir.actions.report"
|
||||
|
||||
subreport_ids = fields.One2many(
|
||||
'ir.actions.report.subreport', 'parent_report_id')
|
||||
model_id = fields.Many2one('ir.model', string='Model')
|
||||
subreport_ids = fields.One2many("ir.actions.report.subreport", "parent_report_id")
|
||||
model_id = fields.Many2one("ir.model", string="Model")
|
||||
|
||||
@api.onchange('model_id')
|
||||
@api.onchange("model_id")
|
||||
def onchange_model_id(self):
|
||||
if self.model_id:
|
||||
self.model = self.model_id.model
|
||||
|
||||
def generate_top_part(self):
|
||||
return """<?xml version="1.0"?>\n\t<t t-name="%s">\n\t
|
||||
""" % self.report_name
|
||||
return (
|
||||
"""<?xml version="1.0"?>\n\t<t t-name="%s">\n\t
|
||||
"""
|
||||
% self.report_name
|
||||
)
|
||||
|
||||
def generate_bottom_part(self):
|
||||
return """\n
|
||||
\t\t</t>\n\t\t"""
|
||||
|
||||
def generate_custom_content(self, report_name):
|
||||
return """\n
|
||||
\t<t t-call="%s"/>""" % report_name
|
||||
return (
|
||||
"""\n
|
||||
\t<t t-call="%s"/>"""
|
||||
% report_name
|
||||
)
|
||||
|
||||
def _generate_batch_qweb_report(self, update_batch_qweb=False):
|
||||
report_name = self.report_name
|
||||
if '.' in report_name:
|
||||
module = self.report_name.split('.')[0]
|
||||
report_name = self.report_name.split('.')[1]
|
||||
if "." in report_name:
|
||||
module = self.report_name.split(".")[0]
|
||||
report_name = self.report_name.split(".")[1]
|
||||
else:
|
||||
# Generate random number to avoid IntegrityError
|
||||
module = random.randint(1, 1000000)
|
||||
self.report_name = "%s.%s" % (module, report_name)
|
||||
self.report_name = "{}.{}".format(module, report_name)
|
||||
if self.subreport_ids:
|
||||
if update_batch_qweb:
|
||||
report_name = self.report_name.split('.')[1]
|
||||
report_name = self.report_name.split(".")[1]
|
||||
# Delete old Qweb batch report
|
||||
model_data = self.env['ir.model.data'].search(
|
||||
[('res_id', '=', self.id)])
|
||||
model_data = self.env["ir.model.data"].search(
|
||||
[("res_id", "=", self.id)]
|
||||
)
|
||||
model_data.unlink()
|
||||
ui_view = self.env['ir.ui.view'].search(
|
||||
[('name', '=', report_name)])
|
||||
ui_view = self.env["ir.ui.view"].search([("name", "=", report_name)])
|
||||
ui_view.unlink()
|
||||
template_header = self.generate_top_part()
|
||||
template_footer = self.generate_bottom_part()
|
||||
template_content = ''
|
||||
template_content = ""
|
||||
|
||||
for subreport in self.subreport_ids:
|
||||
template_content += self.generate_custom_content(
|
||||
subreport.subreport_id.report_name
|
||||
)
|
||||
data = "%s%s%s" % (
|
||||
template_header, template_content, template_footer)
|
||||
ui_view = self.env['ir.ui.view'].create(
|
||||
{'name': report_name,
|
||||
'type': 'qweb',
|
||||
'model': self.model,
|
||||
'mode': 'primary',
|
||||
'arch_base': data})
|
||||
self.env['ir.model.data'].create(
|
||||
{'module': module,
|
||||
'name': report_name,
|
||||
'res_id': ui_view.id,
|
||||
'model': 'ir.ui.view'})
|
||||
data = "{}{}{}".format(template_header, template_content, template_footer)
|
||||
ui_view = self.env["ir.ui.view"].create(
|
||||
{
|
||||
"name": report_name,
|
||||
"type": "qweb",
|
||||
"model": self.model,
|
||||
"mode": "primary",
|
||||
"arch_base": data,
|
||||
}
|
||||
)
|
||||
self.env["ir.model.data"].create(
|
||||
{
|
||||
"module": module,
|
||||
"name": report_name,
|
||||
"res_id": ui_view.id,
|
||||
"model": "ir.ui.view",
|
||||
}
|
||||
)
|
||||
# Register batch report option
|
||||
if not self.binding_model_id:
|
||||
self.create_action()
|
||||
|
@ -97,7 +109,7 @@ class IrActionsReport(models.Model):
|
|||
@api.multi
|
||||
def write(self, vals):
|
||||
res = super(IrActionsReport, self).write(vals)
|
||||
if 'subreport_ids' in vals or 'model' in vals:
|
||||
if "subreport_ids" in vals or "model" in vals:
|
||||
for report in self:
|
||||
report._generate_batch_qweb_report(update_batch_qweb=True)
|
||||
return res
|
||||
|
|
|
@ -1,39 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="act_batch_report_xml_view" model="ir.ui.view">
|
||||
<field name="name">ir.actions.batch.report.form</field>
|
||||
<field name="model">ir.actions.report</field>
|
||||
<field name="inherit_id" ref="base.act_report_xml_view"/>
|
||||
<field name="inherit_id" ref="base.act_report_xml_view" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="report_type" position="after">
|
||||
<field name="model_id"/>
|
||||
<field name="model_id" />
|
||||
</field>
|
||||
<page name="advanced" position="after">
|
||||
<page name="batch_report" string="Batch Report">
|
||||
<field name="subreport_ids">
|
||||
<tree string="Batch Reports" editable="bottom">
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="subreport_id" domain="[('model', '=', parent.model)]"/>
|
||||
<field name="sequence" widget="handle" />
|
||||
<field
|
||||
name="subreport_id"
|
||||
domain="[('model', '=', parent.model)]"
|
||||
/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</page>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_ir_actions_subreport_tree" model="ir.ui.view">
|
||||
<field name="name">ir.actions.report.subreport.tree</field>
|
||||
<field name="model">ir.actions.report.subreport</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Batch Reports" editable="bottom">
|
||||
<field name="sequence"/>
|
||||
<field name="parent_report_id"/>
|
||||
<field name="model" invisible="1"/>
|
||||
<field name="subreport_id" domain="[('model', '=', model)]"/>
|
||||
<field name="sequence" />
|
||||
<field name="parent_report_id" />
|
||||
<field name="model" invisible="1" />
|
||||
<field name="subreport_id" domain="[('model', '=', model)]" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_ir_actions_subreport" model="ir.actions.act_window">
|
||||
<field name="name">Batch Reports</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
|
@ -41,10 +42,10 @@
|
|||
<field name="view_type">form</field>
|
||||
<field name="help">Allows to add multi QWeb reports in a single batch</field>
|
||||
</record>
|
||||
|
||||
<menuitem action="action_ir_actions_subreport"
|
||||
id="menu_action_ir_actions_subreport"
|
||||
parent="base.menu_users"
|
||||
sequence="10"/>
|
||||
|
||||
<menuitem
|
||||
action="action_ir_actions_subreport"
|
||||
id="menu_action_ir_actions_subreport"
|
||||
parent="base.menu_users"
|
||||
sequence="10"
|
||||
/>
|
||||
</odoo>
|
||||
|
|
Loading…
Reference in New Issue