需要安装模块【Email Manual Send】
定时任务代码:
ttoday=datetime.date.today()
if today.weekday()==4:
start_date = (today + dateutil.relativedelta.relativedelta(days=3))
end_date = (start_date + dateutil.relativedelta.relativedelta(days=6)).strftime('%Y-%m-%d')
start_date = start_date.strftime('%Y-%m-%d')
pre_hires = env['pre.hire'].search([('estimated_hire_date','>=',start_date),('estimated_hire_date','<',end_date),('active','=',True),('hire_status','=','not_employed')])
mail_emps = set([i.supervisor_id for i in pre_hires])
it_emps = env['uc.authorization.group.user.relation'].search([('authorization_group_code','=','IT001')])
ad_emps = env['uc.authorization.group.user.relation'].search([('authorization_group_code','=','AM001')])
list_itad_emp = [[4,it_emp.employee_id] for it_emp in it_emps]
list_itad_emp.extend([[4,ad_emp.employee_id] for ad_emp in ad_emps])
parent_template_id = env['reminder.template'].search([('code','=','R710')]).id
idad_template_id = env['reminder.template'].search([('code','=','R838')]).id
for mail_emp in mail_emps:
emp_list = [[4, mail_emp.id]]
env['email.manual.send'].create({
'name': '预入职提醒汇报上级{}'.format(mail_emp.name),
'scenes':'template',
'template_id':parent_template_id,
'send_to': 'employee',
'employee_ids':emp_list
}).action_send()
env['email.manual.send'].create(
{
'name': '预入职提醒it和行政',
'scenes':'template',
'template_id':idad_template_id,
'send_to': 'employee',
'employee_ids':list_itad_emp
}
).action_send()
两个占位符:
today=datetime.date.today()
start_date = today + datetime.timedelta(days=7)
end_date = (start_date + datetime.timedelta(days=6)).strftime('%Y-%m-%d')
start_date = start_date.strftime('%Y-%m-%d')
to_hires = env['pre.hire'].search([('estimated_hire_date','>=',start_date),('estimated_hire_date','<=',end_date),('active','=',True),('hire_status','=','not_employed'),('supervisor_id','=',record.id)])
result = generate_table(to_hires,
headers=['工号','姓名','部门全称','职级','入职地点','直接上级','部门经理','部门总监','预计入职日期'],
columns=[
'employee_number',
'name',
'department_id.display_name',
'job_level_id.name',
'x_hire_location_id.name',
'supervisor_id.name',
'x_dep_manager_id.name',
'x_dep_director_id.name',
'estimated_hire_date'
])
=============
today=datetime.date.today()
start_date = today + datetime.timedelta(days=7)
end_date = (start_date + datetime.timedelta(days=6)).strftime('%Y-%m-%d')
start_date = start_date.strftime('%Y-%m-%d')
to_hires = env['pre.hire'].search([('estimated_hire_date','>=',start_date),('estimated_hire_date','<=',end_date),('active','=',True),('hire_status','=','not_employed')])
result = generate_table(to_hires,
headers=['工号','姓名','部门全称','职级','入职地点','直接上级','部门经理','部门总监','预计入职日期'],
columns=[
'employee_number',
'name',
'department_id.display_name',
'job_level_id.name',
'x_hire_location_id.name',
'supervisor_id.name',
'x_dep_manager_id.name',
'x_dep_director_id.name',
'estimated_hire_date'
])