Skip to Content
Menu
This question has been flagged
1 Reply
5539 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,

Avatar
Discard
Best Answer

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

Avatar
Discard
Author

So simple, thanks!!

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

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.

post your error log

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 :)

Related Posts Replies Views Activity
1
Oct 15
4182
2
Oct 22
26716
0
Aug 16
2596
3
Nov 15
4140
7
Oct 15
11803