我编写了打印报告的方法,但我得到了空数据。请检查以下代码并帮助我。
def birthday_report(self,context=None):
rec = self.env['hr.employee'].search([('birthday','like',date.today().strftime("%____%-%m-%d"))])
print rec,'*************'
data = {}
data['form'] = rec.read(['name', 'birthday', 'work_email','mobile_phone','age'])
print data['form'],"*************************"
return self.env['report'].get_action(rec, 'hr_birthdays.report_contributionregister_birthdays',data=data)
报告代码为:
<tbody>
<tr t-foreach="data" t-as="o">
<td class="td-lrbotborder">
<span t-esc="o['name']" style=" font-size:13px;" />
</td>
<td class="td-botborder">
<span t-esc="o['birthday']" style=" font-size:13px;" />
</td>
<td class="td-botborder">
<span t-esc="o['age']" style=" font-size:13px;" />
</td>
<td class="td-botborder">
<span t-esc="o['mobile_phone']" style=" font-size:13px;" />
</td>
<td class="td-botborder">
<span t-esc="o['work_email']" style=" font-size:13px;" />
</td>
</tr>
</tbody>
答案 0 :(得分:0)
class TodayBirthdayReport(models.AbstractModel):
_name = 'report.hr_birthdays.report_birthdays'
@api.model
def render_html(self, docids, data=None):
if not data.get('form'):
raise UserError(_("Form content is missing, this report cannot be printed."))
register_ids = self.env.context.get('active_ids', [])
contrib_registers = self.env['hr.employee'].browse(register_ids)
docs = self.env['hr.employee'].browse(self.env.context.get('active_id'))
rec = self.env['hr.employee'].search([('birthday','like',date.today().strftime("%____%-%m-%d"))])
data1 = {}
data1['form'] = rec.read(['name', 'birthday', 'work_email','mobile_phone','age','image_medium'])
lines_data = data1['form']
docargs = {
'doc_ids': register_ids,
'doc_model': 'hr.dashboard',
'docs': contrib_registers,
'data': data,
'lines_data': lines_data,
}
return self.env['report'].render('hr_birthdays.report_birthdays', docargs)