Odoo Help

0

How to register a parser for a qweb report

By
E.M.
on 9/26/15, 2:02 PM 1,346 views

Hi,

I have the following report defined:

 <report
id="report_invoice_custom"
model="account.invoice"
string="Custom invoice report"
report_type="qweb-pdf"
name="custom_reports.invoice_custom"
attachment_use="False"
file="custom_reports.invoice_custom"
attachment = "(object.state in ('open','paid')) and ('F_'+(object.number or '').replace('/','')+'.pdf')"
/>

And I am defining a new parser for it:

from openerp.report import report_sxw
from openerp.osv import osv
from openerp import api

class invoice_parser(report_sxw.rml_parse):

def __init__(self, cr, uid, name, context):
super(invoice_parser, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'select_value': self._selection_value,
})

def _selection_value(self, value):
if value:
tax_pool = self.pool.get('account.tax')
tax_ids = tax_pool.search(self.cr, self.uid, [('name', '=', value)])
if tax_ids:
tax_id = tax_pool.browse(self.cr, self.uid, tax_ids[0])
return self._translate(tax_id.description)
return value

class report_custom_invoice_parser(osv.AbstractModel):
_name = 'report.module.invoice.wrapper'
_inherit = 'report.abstract_report'
_template = 'custom_reports.invoice_custom'
_wrapped_report_class = invoice_parser

If I understood how parsers work, I guess I have to add something similar to the following code to register the parser:

report_sxw.report_sxw(
'custom_reports.invoice_custom',
'account.invoice',
'custom/custom_reports/xml/custom_reports.xml',
parser= select_value )

Could someone help me to understand how to register the parser?

Thanks,

2
Axel Mendoza
On 9/26/15, 3:39 PM

In order for the parser to be picked by Odoo and according for your example you need to define it like this:

class report_custom_invoice_parser(osv.AbstractModel):
_name = 'report.custom_reports.invoice_custom'
_inherit = 'report.abstract_report'
_template = 'custom_reports.invoice_custom'
_wrapped_report_class = invoice_parser

So simple, thanks!!

E.M.
on 9/27/15, 7:30 AM

I write a more extensive explanation of qweb report parsers at:
https://www.odoo.com/es_ES/forum/help-1/question/how-to-define-a-custom-methods-functions-to-be-used-in-a-qweb-report-how-to-define-and-use-a-report-parser-92244

Axel Mendoza
on 10/15/15, 5:50 AM

Hi Sir @Axel, why I always got an error that the _name attrbiute is invalid wherein that's the name I defines in my report? But when I remove the module name, dont have an error but the function I created is not callable.

Samantha Cruz
on 3/4/16, 12:54 AM

post your error log

Axel Mendoza
on 3/7/16, 4:21 AM

Hi Sir @Axel, it was already solved, the problem is the name of the module. I have a question Sir, please refer to this link https://www.odoo.com/es_ES/forum/ayuda-1/question/batch-report-using-report-parser-98789, Your suggestions will be highly appreciated :)

Samantha Cruz
on 3/7/16, 7:18 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: 9/26/15, 2:02 PM
Seen: 1346 times
Last updated: 9/27/15, 7:30 AM