1
使用NETSVC服務添加在電子郵件模板附件進行自定義模塊這顯示了錯誤無法在郵件添加附件
(result, format) = service.create(AttributeError: 'unicode' object has no attribute 'create'
這是蟒蛇odoo
def custom_send_email (self, cr, uid, ids, context=None):
email_obj = self.pool.get('mail.template')
template_id = self.pool.get('mail.template').search(cr, uid,
[('name', '=', 'Sales Order - Send by Email')], context=context)[0]
email = email_obj.browse(cr, uid, template_id)
attachment_obj = self.pool.get('ir.attachment')
ir_actions_report = self.pool.get('ir.actions.report.xml')
matching_reports = ir_actions_report.search(
cr, uid, [('name', '=', 'Overtime Report')])
print "Matching report "
print matching_reports
if matching_reports:
report = ir_actions_report.browse(cr, uid, matching_reports[0])
report_service = 'report.' + report.report_name
service = netsvc.LocalService(report_service)
(result, format) = service.create(
cr, uid, [1], {'model': self._name, 'start_date': datetime.now(), 'end_date': datetime.now()}, context=context)
if not report.attachment:
result = base64.b64encode(result)
file_name = "Overtime Report " + datetime.strftime(datetime.now().date(), "%Y-%m-%d") + ".pdf"
attachment_id = attachment_obj.create(cr, uid,
{
'name': file_name,
'datas': result,
'datas_fname': file_name,
'type': 'binary'
}, context=context)
email_obj.write(cr, uid, template_id,
{
'email_from': "${(object.user_id.email or '[email protected]')|safe}",
'email_to': "[email protected]",
'subject': "Over Time",
'body_html': "Over Time",
'email_recipients': "[email protected]",
'attachment_ids': [(6, 0, [attachment_id])],
})
email_obj.send_mail(cr, uid, template_id, False, True, context=context)
return True
什麼python版本 – mnagel
'report_service ='report。' + report.report_name'聞起來很糟糕。可能是因爲它,下面一行返回一個(unicode)字符串,而不是它應該的任何對象? – SiHa