Reputation: 487
I can pass context to another class of models.Model but in models.AbstractModel it return none.
Here is my code.
class PrintWizard(models.TransientModel):
_name = 'print.report.wizard'
start_date = fields.Date()
end_date = fields.Date()
@api.multi
def print_report(self):
ctx = self.env.context.copy()
ctx.update({'start': self.start_date, 'end': self.end_date})
return self.env['report'].with_context(ctx).get_action('erp.report_id')
class ReportClass(models.AbstractModel):
_name = 'report.erp.report_id'
@api.multi
def render_html(self, data):
report_obj = self.env['report']
report = report_obj._get_report_from_name('erp.report_id')
start = self.env.context.get('start')
end = self.env.context.get('end')
docs = self.env['erp.account'].search([('start_date','>=',start),('end_date', '<=', end)])
docargs = {
'doc_model': report.model,
'docs': docs
}
return report_obj.render('erp.report_id', docargs)
i tried to print the start and end, it return none i think i am passing the context to absractmodel in a improper way.
Upvotes: 1
Views: 1207
Reputation: 3378
Try this as an alternative to context (but it pretty well is context)
@api.multi
def print_report(self):
return {
'type':'ir.actions.report.xml',
'report_name': 'erp.report_id',
'datas': 'start': self.start_date, 'end': self.end_date}
}
@api.multi
def render_html(self, data):
report_obj = self.env['report']
report = report_obj._get_report_from_name('erp.report_id')
start = data.get('start')
end = data.get('end')
docs = self.env['erp.account'].search([('start_date','>=',start),('end_date', '<=', end)])
docargs = {
'doc_model': report.model,
'docs': docs
}
return report_obj.render('erp.report_id', docargs)
Upvotes: 2