再配置一个英文模版,并修改定时任务代码如下:
employees = env['hr.employee'].search(cr, 1, [('active', '=', True),('work_activity','=','in_service'),('state','in',['done','waiting','waiting_sign','archived'])])
today = datetime.today()
year_begin = today.replace(day=1,month=1).strftime('%Y-%m-%d')
year_end = today.replace(day=31,month=12).strftime('%Y-%m-%d')
email_template_id = env['mail.template'].search(cr,1,[('active','=',True),('name', '=', '披露声明通知')])
we_chat_template = env['wechat.message.template'].search(cr,1,[('active','=',True),('code', '=', 'WT030')])
we_chat_template_en = env['wechat.message.template'].search(cr,1,[('active','=',True),('code', '=', 'WT032')])
user_id_list = []
for employee in employees:
declear = env['x_af_2020_0005'].search(cr,1,[('employee_id','=',employee),('submit_date','>=',year_begin),('submit_date','<=',year_end)])
if not declear:
employee_instance=env['hr.employee'].browse(cr,1,employee)
user_id_list.append(employee_instance.user_id.id)
env['mail.template'].browse(cr,1,email_template_id).with_context(lang=employee_instance.user_id.lang).send_mail(employee, force_send=False, raise_exception=True)
wechat_message = env['wechat.message'].create(cr,1,
{
'model': employee_instance._model,
'res_id': employee_instance.id,
'template': we_chat_template[0] if employee_instance.user_id.lang=='zh_CN' else we_chat_template_en[0],
'receivers': [(6, 0, [employee_instance.user_id.id])],
'sender': uid,
'content': env['wechat.message.template'].browse(cr,1,we_chat_template[0]).content if employee_instance.user_id.lang=='zh_CN' else env['wechat.message.template'].browse(cr,1,we_chat_template_en[0]).content,
'wechat_application': 2
}
)
wechat_message_instance = env['wechat.message'].browse(cr,1,wechat_message)
wechat_message_instance.send()