Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements on multi-record reports #4

Open
wants to merge 3 commits into
base: 10.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Aeroo Reports for Odoo v10.0
- Install libreoffice
- apt-get install libreoffice, libreoffice-writer, openjdk-7-jre

- Install PDFtk
- apt-get install pdftk

## Translations

Expand Down
19 changes: 19 additions & 0 deletions report_aeroo/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ msgstr "Société"
msgid "Company Evaluation"
msgstr "Évaluation de la société"

#. module: report_aeroo
#: model:ir.model.fields,field_description:report_aeroo.field_ir_act_report_xml_process_separately
msgid "Process Separately"
msgstr "Traiter séparément"

#. module: report_aeroo
#: model:ir.model.fields,field_description:report_aeroo.field_report_mimetypes_compatible_types
msgid "Compatible Mime-Types"
Expand Down Expand Up @@ -232,6 +237,20 @@ msgstr "Groupes"
msgid "ID"
msgstr "ID"

#. module: report_aeroo
#: model:ir.model.fields,help:report_aeroo.field_ir_act_report_xml_process_separately
msgid ""
"If checked the report template will be processed separately "
"with each record's data and the whole will be merged afterwards "
"if the output format is PDF. Otherwise, the template will be "
"processed with all records data at once."
msgstr ""
"Si cette case est cochée, le modèle de rapport sera traité "
"séparément avec les données de chacun des enregistrement et "
"le tout sera fusionné ensuite si le format de sortie est PDF."
"Dans le cas contraire, le modèle de rapport sera traité avec "
"les données de tous les enregistrements."

#. module: report_aeroo
#: model:ir.ui.view,arch_db:report_aeroo.act_aeroo_report_xml_search_view
msgid "Inactive"
Expand Down
15 changes: 11 additions & 4 deletions report_aeroo/models/ir_actions_report_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys

from odoo import models, fields, api, tools, _
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError
from odoo.report import interface
from odoo.report.report_sxw import rml_parse
from openerp.tools.safe_eval import safe_eval
Expand Down Expand Up @@ -66,6 +66,13 @@ def _get_default_outformat(self):
help="Python expression used to determine the company "
"of the record being printed in the report.",
default="o.company_id")
process_separately = fields.Boolean(
'Process Separately', default=True,
help="If checked the report template will be processed separately "
"with each record's data and the whole will be merged afterwards "
"if the output format is PDF. Otherwise, the template will be "
"processed with all records data at once."
)

@api.multi
def get_template(self, record, lang, company):
Expand All @@ -81,7 +88,7 @@ def get_template(self, record, lang, company):
), None)

if line is None:
raise ValidationError(
raise UserError(
_('Could not render report %s for the company %s in '
'lang %s.') % (
self.name, company.name, lang))
Expand Down Expand Up @@ -126,7 +133,7 @@ def load_from_file(self, path, key):
class_inst = py_mod.Parser
return class_inst

raise ValidationError(_('Parser not found at: %s') % path)
raise UserError(_('Parser not found at: %s') % path)

def _lookup_report(self, name):
if 'report.' + name in interface.report_int._reports:
Expand Down Expand Up @@ -184,7 +191,7 @@ def get_aeroo_report_template(self, record):
else:
template = self.report_sxw_content
if not template:
raise ValidationError(
raise UserError(
_('No template found for report %s' % self.report_name))

if self.tml_source == 'database':
Expand Down
18 changes: 10 additions & 8 deletions report_aeroo/report_aeroo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from odoo.report.report_sxw import report_sxw
from odoo.tools.translate import _
from odoo.tools.safe_eval import safe_eval
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError

from tempfile import NamedTemporaryFile

Expand Down Expand Up @@ -78,7 +78,7 @@ def run_subprocess(self, cr, uid, ids, report_xml, temp_file, cmd):
'report_aeroo.libreoffice_timeout')
)
if not libreoffice_timeout:
raise ValidationError(
raise UserError(
_('Aeroo reports are wrongly configured. '
'The global parameter report_aeroo.libreoffice_timeout '
'must be defined.'))
Expand All @@ -92,7 +92,7 @@ def run_subprocess(self, cr, uid, ids, report_xml, temp_file, cmd):

elif status is not None:
os.remove(temp_file.name)
raise ValidationError(
raise UserError(
_('Could not generate the report %(report)s '
'using the format %(output_format)s.') % {
'report': report_xml.name,
Expand All @@ -105,7 +105,7 @@ def run_subprocess(self, cr, uid, ids, report_xml, temp_file, cmd):
if timetaken > libreoffice_timeout:
proc.kill()
os.remove(temp_file.name)
raise ValidationError(
raise UserError(
_('Could not generate the report %(report)s '
'using the format %(output_format)s. '
'Timeout Exceeded.') % {
Expand Down Expand Up @@ -137,6 +137,8 @@ def create_aeroo_report(
oo_parser.localcontext['data'] = data
oo_parser.localcontext['user_lang'] = context.get('lang', False)
oo_parser.localcontext['o'] = objects[0]
if not report_xml.process_separately:
oo_parser.localcontext['objects'] = objects

xfunc = ExtraFunctions(cr, uid, report_xml.id, oo_parser.localcontext)
oo_parser.localcontext.update(xfunc.functions)
Expand All @@ -162,7 +164,7 @@ def create_aeroo_report(
)

if not libreoffice_location:
raise ValidationError(
raise UserError(
_('Aeroo reports are wrongly configured. '
'The global parameter report_aeroo.libreoffice_location '
'must be defined.'))
Expand Down Expand Up @@ -190,7 +192,7 @@ def create_aeroo_merged_report(
output_format = report_xml.out_format.code[3:]

if output_format != 'pdf':
raise ValidationError(
raise UserError(
_('Aeroo Reports do not support generating non-pdf '
'reports in batch. You must select one record '
'at a time.'))
Expand All @@ -215,7 +217,7 @@ def create_aeroo_merged_report(
)

if not pdftk_location:
raise ValidationError(
raise UserError(
_('Aeroo reports are wrongly configured. '
'The global parameter report_aeroo.pdftk_location '
'must be defined.'))
Expand Down Expand Up @@ -243,7 +245,7 @@ def create(self, cr, uid, ids, data, context=None):
report_xml = env['ir.actions.report.xml'].search(
[('report_name', '=', name)])

if len(ids) > 1:
if report_xml.process_separately and len(ids) > 1:
return self.create_aeroo_merged_report(
cr, uid, ids, data, report_xml, context=context)

Expand Down
1 change: 1 addition & 0 deletions report_aeroo/report_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</group>
<group string="Miscellaneous">
<field name="multi"/>
<field name="process_separately"/>
</group>
</page>
<page string="Security">
Expand Down
16 changes: 8 additions & 8 deletions report_aeroo/tests/test_report_aeroo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
import stat
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError
from odoo.modules import module
from odoo.tests import common

Expand Down Expand Up @@ -107,7 +107,7 @@ def test_04_libreoffice_low_timeout(self):
self.report.out_format = self.env.ref(
'report_aeroo.report_mimetypes_pdf_odt')

with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.partner.print_report('sample_report', {})

def _set_libreoffice_location(self, filename):
Expand All @@ -125,7 +125,7 @@ def test_05_fail_after_10ms(self):
self.report.out_format = self.env.ref(
'report_aeroo.report_mimetypes_pdf_odt')

with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.partner.print_report('sample_report', {})

def test_06_libreoffice_finish_after_100s(self):
Expand All @@ -136,7 +136,7 @@ def test_06_libreoffice_finish_after_100s(self):
self.env['ir.config_parameter'].set_param(
'report_aeroo.libreoffice_timeout', '5')

with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.partner.print_report('sample_report', {})

def test_07_libreoffice_fail(self):
Expand All @@ -147,7 +147,7 @@ def test_07_libreoffice_fail(self):
self.env['ir.config_parameter'].set_param(
'report_aeroo.libreoffice_timeout', '5')

with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.partner.print_report('sample_report', {})

def test_08_multicompany_context(self):
Expand All @@ -157,7 +157,7 @@ def test_08_multicompany_context(self):
def test_09_multicompany_context(self):
self._create_report_line(self.lang_en, self.company.id)
self.partner.write({'company_id': self.company_2.id})
with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.partner.print_report('sample_report', {})

def test_10_multicompany_context(self):
Expand All @@ -166,7 +166,7 @@ def test_10_multicompany_context(self):

def test_11_multicompany_context(self):
self._create_report_line(self.lang_fr)
with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
self.partner.print_report('sample_report', {})

def test_12_sample_report_pdf_with_multiple_export(self):
Expand All @@ -185,5 +185,5 @@ def test_13_pdf_low_timeout(self):
'report_aeroo.report_mimetypes_pdf_odt')
partners = self.partner | self.partner_2

with self.assertRaises(ValidationError):
with self.assertRaises(UserError):
partners.print_report('sample_report', {})