Hi Team,
I have created a scheduler action for timesheet reminder for the next day morning at 8 am if user forget to enter the working hours .
python code:
from datetime import datetime, timedelta
from odoo import api, fields, models
class TimesheetReminder(models.TransientModel):
_name = 'timesheet.reminder'
@api.model
def send_timesheet_reminder(self):
# Find employees with missing timesheets for the previous day
today = fields.Date.today()
yesterday = today - timedelta(days=1)
employees_with_missing_timesheets = self.env['hr.employee'].search([
('user_id', '!=', False),
('timesheet_ids.date', '=', yesterday),
('timesheet_ids.state', '!=', 'done'),
])
# Send reminder emails
for employee in employees_with_missing_timesheets:
template = self.env.ref('your_module.email_template_id')
template.send_mail(employee.user_id.id, force_send=True)
while unbale to find the module.email_template_id ..
Getting below error : forbidden opcode(s) in "# Available variables:\n# - env: Odoo Environment on which the action is triggered\n# - model: Odoo Model of the record on which the action is triggered; is a void recordset\n# - record: record on which the action is triggered; may be void\n# - records: recordset of all records on which the action is triggered in multi-mode; may be void\n# - time, datetime, dateutil, timezone: useful Python libraries\n# - float_compare: Odoo function to compare floats based on specific precisions\n# - log: log(message, level='info'): logging function to record debug information in ir.logging table\n# - UserError: Warning Exception to use with raise\n# - Command: x2Many commands namespace\n# To return an action, assign: action = {...}\n\nfrom datetime import datetime, timedelta\nfrom odoo import api, fields, models\nclass TimesheetReminder(models.TransientModel):\n _name = 'timesheet.reminder'\n\n @api.model\n def send_timesheet_reminder(self):\n # Find employees with missing timesheets for the previous day\n today = fields.Date.today()\n yesterday = today - timedelta(days=1)\n\n employees_with_missing_timesheets = self.env['hr.employee'].search([\n ('user_id', '!=', False),\n ('timesheet_ids.date', '=', yesterday),\n ('timesheet_ids.state', '!=', 'done'),\n ])\n\n # Send reminder emails\n for employee in employees_with_missing_timesheets:\n template = self.env.ref('your_module.email_template_id')\n template.send_mail(employee.user_id.id, force_send=True)\n\n# Add this function to the Scheduled Action": IMPORT_NAME, IMPORT_FROM, LOAD_BUILD_CLASS
Thanks and Regards
Vijay Yadav