[IMP] report: render report without editable mode
Before this change, the reports were generated in editable mode for branding to be applied. The branding is used to cut the report and add on each selected record for generating the pdf. Applied branding and editing options takes a useless time and branding was also applied by widgets even if branding was not requested.
This commit is contained in:
@@ -179,7 +179,7 @@
|
||||
<div class="clearfix mb8"/>
|
||||
</div>
|
||||
|
||||
<div class="article o_report_layout_background">
|
||||
<div class="article o_report_layout_background" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id">
|
||||
<t t-call="web.address_layout" />
|
||||
<t t-raw="0" />
|
||||
</div>
|
||||
@@ -219,7 +219,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="article o_report_layout_boxed">
|
||||
<div class="article o_report_layout_boxed" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id">
|
||||
<t t-call="web.address_layout" />
|
||||
<t t-raw="0" />
|
||||
</div>
|
||||
@@ -258,7 +258,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="article o_report_layout_clean">
|
||||
<div class="article o_report_layout_clean" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id">
|
||||
<t t-call="web.address_layout" />
|
||||
<t t-raw="0" />
|
||||
</div>
|
||||
@@ -306,7 +306,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="article o_report_layout_standard">
|
||||
<div class="article o_report_layout_standard" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id">
|
||||
<t t-call="web.address_layout" />
|
||||
<t t-raw="0" />
|
||||
</div>
|
||||
@@ -358,6 +358,9 @@
|
||||
<t t-if="not company_id">
|
||||
<t t-set="company" t-value="res_company"/>
|
||||
</t>
|
||||
<t t-if="not o and doc">
|
||||
<t t-set="o" t-value="doc"/>
|
||||
</t>
|
||||
|
||||
<div class="header">
|
||||
<div class="row">
|
||||
@@ -376,14 +379,18 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="article">
|
||||
<div class="article" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id">
|
||||
<t t-raw="0" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="basic_layout">
|
||||
<t t-if="not o and doc">
|
||||
<t t-set="o" t-value="doc"/>
|
||||
</t>
|
||||
|
||||
<t t-call="web.html_container">
|
||||
<div class="article">
|
||||
<div class="article" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id">
|
||||
<t t-raw="0" />
|
||||
</div>
|
||||
</t>
|
||||
|
||||
@@ -146,10 +146,11 @@ class ManyToOne(models.AbstractModel):
|
||||
@api.model
|
||||
def attributes(self, record, field_name, options, values):
|
||||
attrs = super(ManyToOne, self).attributes(record, field_name, options, values)
|
||||
many2one = getattr(record, field_name)
|
||||
if many2one:
|
||||
attrs['data-oe-many2one-id'] = many2one.id
|
||||
attrs['data-oe-many2one-model'] = many2one._name
|
||||
if options.get('inherit_branding'):
|
||||
many2one = getattr(record, field_name)
|
||||
if many2one:
|
||||
attrs['data-oe-many2one-id'] = many2one.id
|
||||
attrs['data-oe-many2one-model'] = many2one._name
|
||||
return attrs
|
||||
|
||||
@api.model
|
||||
@@ -175,8 +176,9 @@ class Contact(models.AbstractModel):
|
||||
@api.model
|
||||
def attributes(self, record, field_name, options, values):
|
||||
attrs = super(Contact, self).attributes(record, field_name, options, values)
|
||||
options.pop('template_options') # remove options not specific to this widget
|
||||
attrs['data-oe-contact-options'] = json.dumps(options)
|
||||
if options.get('inherit_branding'):
|
||||
options.pop('template_options') # remove options not specific to this widget
|
||||
attrs['data-oe-contact-options'] = json.dumps(options)
|
||||
return attrs
|
||||
|
||||
# helper to call the rendering of contact field
|
||||
@@ -192,7 +194,8 @@ class Date(models.AbstractModel):
|
||||
@api.model
|
||||
def attributes(self, record, field_name, options, values):
|
||||
attrs = super(Date, self).attributes(record, field_name, options, values)
|
||||
attrs['data-oe-original'] = record[field_name]
|
||||
if options.get('inherit_branding'):
|
||||
attrs['data-oe-original'] = record[field_name]
|
||||
return attrs
|
||||
|
||||
@api.model
|
||||
@@ -211,14 +214,15 @@ class DateTime(models.AbstractModel):
|
||||
@api.model
|
||||
def attributes(self, record, field_name, options, values):
|
||||
attrs = super(DateTime, self).attributes(record, field_name, options, values)
|
||||
value = record[field_name]
|
||||
if isinstance(value, pycompat.string_types):
|
||||
value = fields.Datetime.from_string(value)
|
||||
if value:
|
||||
# convert from UTC (server timezone) to user timezone
|
||||
value = fields.Datetime.context_timestamp(self, timestamp=value)
|
||||
value = fields.Datetime.to_string(value)
|
||||
attrs['data-oe-original'] = value
|
||||
if options.get('inherit_branding'):
|
||||
value = record[field_name]
|
||||
if isinstance(value, pycompat.string_types):
|
||||
value = fields.Datetime.from_string(value)
|
||||
if value:
|
||||
# convert from UTC (server timezone) to user timezone
|
||||
value = fields.Datetime.context_timestamp(self, timestamp=value)
|
||||
value = fields.Datetime.to_string(value)
|
||||
attrs['data-oe-original'] = value
|
||||
return attrs
|
||||
|
||||
@api.model
|
||||
@@ -398,7 +402,8 @@ class Duration(models.AbstractModel):
|
||||
@api.model
|
||||
def attributes(self, record, field_name, options, values):
|
||||
attrs = super(Duration, self).attributes(record, field_name, options, values)
|
||||
attrs['data-oe-original'] = record[field_name]
|
||||
if options.get('inherit_branding'):
|
||||
attrs['data-oe-original'] = record[field_name]
|
||||
return attrs
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -311,16 +311,17 @@ class IrActionsReport(models.Model):
|
||||
|
||||
# Retrieve bodies
|
||||
for node in root.xpath(match_klass.format('article')):
|
||||
body = layout.render(dict(subst=False, body=lxml.html.tostring(node), base_url=base_url))
|
||||
bodies.append(body)
|
||||
oemodelnode = node.find(".//*[@data-oe-model='%s']" % self.model)
|
||||
if oemodelnode is not None:
|
||||
res_id = oemodelnode.get('data-oe-id')
|
||||
if res_id:
|
||||
res_id = int(res_id)
|
||||
if node.get('data-oe-model') == self.model:
|
||||
body = layout.render(dict(subst=False, body=lxml.html.tostring(node), base_url=base_url))
|
||||
bodies.append(body)
|
||||
res_ids.append(int(node.get('data-oe-id', False)))
|
||||
else:
|
||||
res_id = False
|
||||
res_ids.append(res_id)
|
||||
_logger.warning("The report's template '%s' does not contains the attributes 'data-oe-model' and 'data-oe-id' on the container (with class 'article')", self.name)
|
||||
raise UserError(_("The report's template is wrong, please contact your administrator"))
|
||||
|
||||
if not bodies:
|
||||
_logger.warning("The report's template '%s' does not contains the container with the class 'article'", self.name)
|
||||
raise UserError(_("The report's template is wrong, please contact your administrator"))
|
||||
|
||||
# Get paperformat arguments set in the root html tag. They are prioritized over
|
||||
# paperformat-record arguments.
|
||||
@@ -454,7 +455,7 @@ class IrActionsReport(models.Model):
|
||||
if values is None:
|
||||
values = {}
|
||||
|
||||
context = dict(self.env.context, inherit_branding=True) # Tell QWeb to brand the generated html
|
||||
context = dict(self.env.context, inherit_branding=values.get('enable_editor'))
|
||||
|
||||
# Browse the user instead of using the sudo self.env.user
|
||||
user = self.env['res.users'].browse(self.env.uid)
|
||||
@@ -468,7 +469,7 @@ class IrActionsReport(models.Model):
|
||||
values.update(
|
||||
time=time,
|
||||
context_timestamp=lambda t: fields.Datetime.context_timestamp(self.with_context(tz=user.tz), t),
|
||||
editable=True,
|
||||
editable=values.get('enable_editor'),
|
||||
user=user,
|
||||
res_company=user.company_id,
|
||||
website=website,
|
||||
@@ -568,6 +569,12 @@ class IrActionsReport(models.Model):
|
||||
|
||||
@api.multi
|
||||
def render_qweb_pdf(self, res_ids=None, data=None):
|
||||
if not data:
|
||||
data = {}
|
||||
|
||||
# remove editor feature in pdf generation
|
||||
data.update(enable_editor=False)
|
||||
|
||||
# In case of test environment without enough workers to perform calls to wkhtmltopdf,
|
||||
# fallback to render_html.
|
||||
if tools.config['test_enable']:
|
||||
@@ -675,11 +682,13 @@ class IrActionsReport(models.Model):
|
||||
data = report_model._get_report_values(docids, data=data)
|
||||
else:
|
||||
docs = self.env[self.model].browse(docids)
|
||||
data = {
|
||||
if not data:
|
||||
data = {}
|
||||
data.update({
|
||||
'doc_ids': docids,
|
||||
'doc_model': self.model,
|
||||
'docs': docs,
|
||||
}
|
||||
})
|
||||
return data
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<template id="report_irmodeloverview">
|
||||
<t t-call="web.html_container">
|
||||
<t t-foreach="docs" t-as="o">
|
||||
<div class="article">
|
||||
<div class="article" t-att-data-oe-model="o._name" t-att-data-oe-id="o.id">
|
||||
<table class="table table-bordered mb64">
|
||||
<tr>
|
||||
<td colspan="12">
|
||||
|
||||
Reference in New Issue
Block a user