Skip to content

Conversation

@jjscarafia
Copy link
Contributor

No description provided.

Copy link
Contributor Author

@jjscarafia jjscarafia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sraps can you please take a look at this PR?

parser = self._custom_aeroo_parser(model_data)
parser._build_model(self.pool, cr)

if 'report_aeroo' in self.pool._init_modules:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid error on module install

"""
Instantiates custom parsers for Aeroo Reports "dynamic" reports
"""
expected_class = 'Parser'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used

### Fields
charset = fields.Selection('_get_encodings', string='Charset',
required=True, default='utf_8')
content_fname = fields.Char('Override Extension',size=64,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use new odoo field "print_report_name"

string='Template Mime-type', default='oo-odt')
out_format = fields.Many2one('report.mimetypes', 'Output Mime-type',
default=_get_default_outformat)
active = fields.Boolean('Active', help='Disables the report if unchecked.',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is not necessary, keep it simpler

rep_model.with_context(_force_unlink=True).unlink()


@api.multi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use odoo api.multi capabilities

'gettext': self._translate_text,
'test': self.test,
}
'fields': fields,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useful for date/datetime methods (for eg. fields.Date.today())

var aeroo_url = 'report/aeroo/' + c_action.report_name;
if(c_action.context.active_ids){
aeroo_url += '/' + c_action.context.active_ids.join(',');
if (_.isUndefined(action.data) || _.isNull(action.data) || (_.isObject(action.data) && _.isEmpty(action.data))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more similar as odoo does. Without this changes context and data where lost and not reaching the controller

if (action.context.active_ids) {
aeroo_url += '/' + c_action.context.active_ids.join(',');
// odoo does not send context if no data, but I find it quite useful to send it regardless data or no data
aeroo_url += '?context=' + encodeURIComponent(JSON.stringify(c_action.context));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the main difference with odoo. I've added for compatibility with v8/v9 where you could send values on the context to the report.
I don't see any reason why if there is not data you should not preserve the context.

from odoo import api, models

class ReportSampleParser(models.AbstractModel):
class Parser(models.AbstractModel):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of this it must be named "Parser"

git+https://github.com/aeroo/aeroolib.git
git+https://github.com/aeroo/currency2text.git
# use this genshi version to fix error when, for eg, you send arguments like "date=True" check this https://genshi.edgewall.org/ticket/600
git+https://github.com/edgewall/genshi@stable/0.7.x
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newer version to fix ror with genshi if, for eg. you call "formatlang(o.date, date=True)" (the issue was with date=True)

@CasVissers-360ERP
Copy link

I get two errors when printing:

File "/usr/local/lib/python3.5/dist-packages/aeroolib/plugins/opendocument.py", line 390, in _aeroo_statements error_stm = open_stm_by_type[stm][check_opening[stm]-1] IndexError: list index out of range 

File "/usr/local/lib/python3.5/dist-packages/aeroolib/plugins/opendocument.py", line 394, in _aeroo_statements raise Exception("Statement has no opening tag. <%s>" % error_stm) Exception: Statement has no opening tag. 

The first one might be a user error.

@jjscarafia
Copy link
Contributor Author

Hi @CasVissers ! Thanks for the review.
Can you attach the report you are using to get that error?
I've try it on runbot (line 115) with sample report and it works ok (also in local with many odt/ods reports)

Thanks!

@CasVissers-360ERP
Copy link

@jjscarafia
I added the report (ID = 111) and e-mailed it to you.

@jjscarafia
Copy link
Contributor Author

Hi! The error with that report is that you have an small /if (without an if that starts the conditional). I've deleted locally and it works ok.

@CasVissers-360ERP
Copy link

image

Tracebacks are not always catched correctly. Not a must but would be cleaner.

@CasVissers-360ERP
Copy link

CasVissers-360ERP commented Jun 28, 2018

@jjscarafia Runbot is not working correctly for me.
I still get an error with the report:
File "/odoo/dcp/community/report_aeroo/controllers/main.py", line 58, in report_routes ('Content-Length', len(rset[0])) TypeError: object of type 'bool' has no len()

I downloaded your report, still get the error:
File "/usr/local/lib/python3.5/dist-packages/aeroolib/plugins/opendocument.py", line 415, in _handle_aeroo_tags r_statements, closing_tags = self._aeroo_statements(tree) File "/usr/local/lib/python3.5/dist-packages/aeroolib/plugins/opendocument.py", line 394, in _aeroo_statements raise Exception("Statement has no opening tag. <%s>" % error_stm) Exception: Statement has no opening tag.

In runbot I get a server overload.

@CasVissers-360ERP
Copy link

@jjscarafia some more info I get the TypeError: object of type 'bool' has no len() error only when I export to PDF, ODT works. If I try to reproduce on runbot. The PDF export doesn't work at all.

@jjscarafia
Copy link
Contributor Author

hi @CasVissers

  1. I've check your report and it has fields that doesn't exists in database (street_name and street_number). I've fix the report, uploaded it again and it works ok (yes, Tracebacks are not always catched correctly)

  2. Aeroo docs connection (to allow conversion to pdf) is no set up automatically (neither on runbot), I've configured it on runbot and test the report with pdf option, it works ok.

@CasVissers-360ERP
Copy link

@jjscarafia
I downloaded your changed report, for ODT it works perfectly. For PDF and Word I still get the same error. On runbot everything works fine. So it must be something in my local env.

Complete traceback:

Traceback (most recent call last):
  File "/odoo/odoo-server/odoo/addons/base/ir/ir_http.py", line 208, in _dispatch
    result = request.dispatch()
  File "/odoo/odoo-server/odoo/http.py", line 829, in dispatch
    r = self._call_function(**self.params)
  File "/odoo/odoo-server/odoo/http.py", line 342, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/odoo/odoo-server/odoo/service/model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "/odoo/odoo-server/odoo/http.py", line 335, in checked_call
    result = self.endpoint(*a, **kw)
  File "/odoo/odoo-server/odoo/http.py", line 936, in __call__
    return self.method(*args, **kw)
  File "/odoo/odoo-server/odoo/http.py", line 515, in response_wrap
    response = f(*args, **kw)
  File "/odoo/dcp/community/report_aeroo/controllers/main.py", line 58, in report_routes
    ('Content-Length', len(rset[0]))
TypeError: object of type 'bool' has no len()

You have any idea where to search?

@jsmith3885
Copy link

Hi @jjscarafia @CasVissers , I have tested Sample report and it is working perfectly, i just added one method in sample report.odt (get_data()) and trying to call it through parser file, but it is giving me errors. i am not sure if parser file code is already done in this commit. please help me out.

@jjscarafia
Copy link
Contributor Author

Hi @jsmith3885 . Actually I haven't test parsers, I don't use the. I think that what is missing is a call to a method that can be extended on parser to modify data and/or context.

@jsmith3885
Copy link

jsmith3885 commented Jun 28, 2018

@jjscarafia Thanks for your quick response. For some complex reports parsers are very important. Can you please test then tell me which method i should call on parser?

@sraps
Copy link
Contributor

sraps commented Jun 29, 2018

@jsmith3885
# -*- coding: utf-8 -*- from odoo import api, models class TestAerooReport(models.AbstractModel): _inherit = 'report.report_aeroo.abstract' _name = 'report.product_template_printer' #=============================================================================== @api.model def get_report_values(self, docids, data=None): report = self.env['ir.actions.report']._get_report_from_name(self._name) selected_companies = self.env['res.company'].browse(docids) return { 'doc_ids': docids, 'doc_model': report.model, 'docs': selected_companies, }

@jsmith3885
Copy link

@sraps , with using this method, I am getting following error

2018-06-29 14:57:34,309 6426 ERROR db_test_aeroo werkzeug: Error on request:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 270, in run_wsgi
execute(self.server.app)
File "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 258, in execute
application_iter = app(environ, start_response)
File "/home/erp/workspace11/odoo/odoo/service/server.py", line 250, in app
return self.app(e, s)
File "/home/erp/workspace11/odoo/odoo/service/wsgi_server.py", line 166, in application
return application_unproxied(environ, start_response)
File "/home/erp/workspace11/odoo/odoo/service/wsgi_server.py", line 154, in application_unproxied
result = handler(environ, start_response)
File "/home/erp/workspace11/odoo/odoo/http.py", line 1318, in call
return self.dispatch(environ, start_response)
File "/home/erp/workspace11/odoo/odoo/http.py", line 1292, in call
return self.app(environ, start_wrapped)
File "/usr/local/lib/python3.6/dist-packages/werkzeug/wsgi.py", line 766, in call
return self.app(environ, start_response)
File "/home/erp/workspace11/odoo/odoo/http.py", line 1490, in dispatch
result = ir_http._dispatch()
File "/home/erp/workspace11/odoo/addons/auth_signup/models/ir_http.py", line 19, in _dispatch
return super(Http, cls)._dispatch()
File "/home/erp/workspace11/odoo/addons/web_editor/models/ir_http.py", line 22, in _dispatch
return super(IrHttp, cls)._dispatch()
File "/home/erp/workspace11/odoo/addons/http_routing/models/ir_http.py", line 393, in _dispatch
result = super(IrHttp, cls)._dispatch()
File "/home/erp/workspace11/odoo/odoo/addons/base/ir/ir_http.py", line 212, in _dispatch
return cls._handle_exception(e)
File "/home/erp/workspace11/odoo/odoo/addons/base/ir/ir_http.py", line 182, in _handle_exception
return request._handle_exception(exception)
File "/home/erp/workspace11/odoo/odoo/http.py", line 770, in _handle_exception
return super(HttpRequest, self)._handle_exception(exception)
File "/home/erp/workspace11/odoo/odoo/http.py", line 310, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/home/erp/workspace11/odoo/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/home/erp/workspace11/odoo/odoo/addons/base/ir/ir_http.py", line 208, in _dispatch
result = request.dispatch()
File "/home/erp/workspace11/odoo/odoo/http.py", line 829, in dispatch
r = self._call_function(**self.params)
File "/home/erp/workspace11/odoo/odoo/http.py", line 342, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/erp/workspace11/odoo/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/home/erp/workspace11/odoo/odoo/http.py", line 335, in checked_call
result = self.endpoint(*a, **kw)
File "/home/erp/workspace11/odoo/odoo/http.py", line 936, in call
return self.method(*args, **kw)
File "/home/erp/workspace11/odoo/odoo/http.py", line 515, in response_wrap
response = f(*args, **kw)
File "/home/erp/workspace11/aeroo_test/report_aeroo/controllers/main.py", line 53, in report_routes
rset = report.with_context(context).render_aeroo(docids, data=data)
File "/home/erp/workspace11/aeroo_test/report_aeroo/models/report.py", line 87, in render_aeroo
return report_parser.with_context(context).aeroo_report(docids, data)
File "/home/erp/workspace11/aeroo_test/report_aeroo/report_parser.py", line 455, in aeroo_report
res = self.assemble_tasks(ids, data, report, ctx)
File "/home/erp/workspace11/aeroo_test/report_aeroo/report_parser.py", line 405, in assemble_tasks
result = self.single_report(ids, data, report, ctx)
File "/home/erp/workspace11/aeroo_test/report_aeroo/report_parser.py", line 399, in single_report
return self.complex_report(ids, data, report, ctx)
File "/home/erp/workspace11/aeroo_test/report_aeroo/report_parser.py", line 385, in complex_report
file_data = basic.generate(**self.localcontext).render().getvalue()
File "/usr/local/lib/python3.6/dist-packages/aeroolib-1.3.0-py3.6.egg/aeroolib/plugins/base.py", line 51, in render
return self.serializer(self.events)
File "/usr/local/lib/python3.6/dist-packages/aeroolib-1.3.0-py3.6.egg/aeroolib/plugins/opendocument.py", line 1206, in call
for kind, data, pos in stream:
File "/usr/local/lib/python3.6/dist-packages/Genshi-0.7-py3.6-linux-x86_64.egg/genshi/template/base.py", line 617, in _include
for event in stream:
File "/usr/local/lib/python3.6/dist-packages/Genshi-0.7-py3.6-linux-x86_64.egg/genshi/template/markup.py", line 326, in _match
for event in stream:
File "/usr/local/lib/python3.6/dist-packages/Genshi-0.7-py3.6-linux-x86_64.egg/genshi/template/base.py", line 577, in _flatten
result = _eval_expr(data, ctxt, vars)
File "/usr/local/lib/python3.6/dist-packages/Genshi-0.7-py3.6-linux-x86_64.egg/genshi/template/base.py", line 289, in _eval_expr
retval = expr.evaluate(ctxt)
File "/usr/local/lib/python3.6/dist-packages/Genshi-0.7-py3.6-linux-x86_64.egg/genshi/template/eval.py", line 177, in evaluate
return eval(self.code, _globals, {'data': data})
File "", line 1, in <Expression '__filter(get_data())'>

File "/usr/local/lib/python3.6/dist-packages/Genshi-0.7-py3.6-linux-x86_64.egg/genshi/template/eval.py", line 310, in lookup_name
val = cls.undefined(name)
File "/usr/local/lib/python3.6/dist-packages/Genshi-0.7-py3.6-linux-x86_64.egg/genshi/template/eval.py", line 413, in undefined
raise UndefinedError(key, owner=owner)
genshi.template.eval.UndefinedError: "get_data" not defined

@jsmith3885
Copy link

@sraps @jjscarafia any hint on this. or i should try with different methods like
@api.model
def render_aeroo(self, docids, data):
@api.model
ded aeroo_report(self, docids, data):

@jsmith3885
Copy link

@sraps @jjscarafia @FreeDoo2018 please help me out.

@jjscarafia
Copy link
Contributor Author

Hi @jsmith3885
As far as I understand get_report_values won't work directly on aeroo reports for v11 because it's is only called by odoo "render_qweb_html" method (that is not used by aeroo)

I 've make this new PR #116 where I show on report sample how parser can be used on report sample

hope it helps

@sraps what do you think about it?

@sraps sraps merged commit c5d3a36 into aeroo:11.0 Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants