Odoo Help

2

Is it mandatory to inherit report_sxw.rml_parse for custom report even with odoo 8?

By
Pascal Tremblay
on 2/12/16, 7:41 AM 1,970 views

Hello guys,

I want to create a new custom report in my Odoo 8.

Everywhere on the web, custom reports classes are created with two classes : 

  • One class inherits report_sxw.rml_parse

  • One class inherits models.AbstractModel (the parser)


If I well understand, it is mandatory to inherit report_sxw.rml_parse and after create a parser who inherits models.AbstractModel. Is it the case?

But, is report_sxw.rml_parse model not in the old api?

Could we only create a new report ONLY with models.AbstractModel who seems to be in the new api?

Really not clear in my head...

Thanks for your comment.

Neither in your head, nor in mine... even nor in documentation!

Daniel Blanco
on 8/31/16, 9:50 PM
3
Axel Mendoza
On 2/12/16, 12:11 PM

Hi @Pascal

Very good question, I didn't ask that for myself. 

The real answer is no because we are in python, in other strongly typed programming lang the answer would be yes.

The only thing that we do when we define a parser is inherit from report_sxw.rml_parse to add our methods and values into the localcontext dict value by reimplementing the __init__ method to add our stuffs but Odoo 8 do not anything of that, it's just using report_sxw.rml_parse to build the self.localcontext dict and to call the set_context method. The new report api jus do this with the wrapper_report_class

# Generate the old style report

wrapped_report = self._wrapped_report_class(cr, uid, '', context=context)

wrapped_report.set_context(objects, data, context['active_ids'])

# Rendering self._template with the wrapped report instance localcontext as

# rendering environment

docargs = dict(wrapped_report.localcontext)

So you can do this:

class report_parser(object):
    def __init__(self, cr, uid, name, context):

self.localcontext = {

'next_seq': 'value',

'select_value': self._function,

}

def set_context(self, objects, data, ids, report_type = None):

self.localcontext['data'] = data

self.localcontext['objects'] = objects



class report_test1_parser(models.AbstractModel):

_name = 'report.parser_test_module.report_test1'

_inherit = 'report.abstract_report'

_template = 'parser_test_module.report_test1'

_wrapped_report_class = report_parser

So no need to inherit form the old api report_sxw.rml_parse

You are really a beast. Thanks.

Pascal Tremblay
on 2/12/16, 12:26 PM

Good questions gets good answers

Axel Mendoza
on 2/12/16, 12:27 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 2/12/16, 7:41 AM
Seen: 1970 times
Last updated: 3/1/16, 2:44 AM