Hi everybody,
I got stuck when I tried to get data from 2 models.
The query I want to run is simple. I have 3 models, there are plan_email_contract, hr_contract and hr_employee.
I want to get a list of contracts that some conditions. My query is:
list_contract =self.sudo().env['hr.contract'].search(['&', ('type_id','=', record.contract_type_id.id), ('employee_id.active','=',True), ('date_end','=', fields.Date.add(fields.Date.today(), days=record.plan_date))])
And then, I want to send email for each contract
iflen(list_contract)>0:
template_id = record.template_mail_id template_id.send_mail(record.id,force_send=False)
But maybe the returned list_contract is null, because it doesn't send the email.
When I remove condition ('employee_id.active','=',True)
It works.
Is my code correct? And, ('employee_id.active','=',True) can get 'active' field from hr_employee model which has id = employee_id in hr_contract model?
Thank you for help!