diff --git a/addons_extensions/cwf_timesheet/__manifest__.py b/addons_extensions/cwf_timesheet/__manifest__.py index 9eb7bbd88..64a474cf9 100644 --- a/addons_extensions/cwf_timesheet/__manifest__.py +++ b/addons_extensions/cwf_timesheet/__manifest__.py @@ -7,6 +7,7 @@ 'depends': ['hr_attendance_extended','web', 'mail', 'base','hr_emp_dashboard','hr_employee_extended'], 'data': [ # 'views/timesheet_form.xml', + 'security/security.xml', 'security/ir.model.access.csv', 'views/timesheet_view.xml', 'views/timesheet_weekly_view.xml', diff --git a/addons_extensions/cwf_timesheet/data/email_template.xml b/addons_extensions/cwf_timesheet/data/email_template.xml index 96df0acd9..807927766 100644 --- a/addons_extensions/cwf_timesheet/data/email_template.xml +++ b/addons_extensions/cwf_timesheet/data/email_template.xml @@ -1,109 +1,45 @@ - - Timesheet Update Reminder - ${(user.email or '')} - Reminder: Update Your Weekly Timesheet - - - - - - - + + Timesheet Update Reminder + + {{ user.email_formatted }} + {{ object.employee_id.user_id.email }} + Reminder: Update Your Weekly Timesheet + + Reminder to employee to update their weekly timesheet. + + +

+ Dear Employee, +
+
+ I hope this message finds you in good spirits. I would like to remind you to please update your weekly timesheet for the period from + + + + to + + + . + Timely updates are crucial for maintaining accurate records and ensuring smooth processing. +
+
+ To make things easier, you can use the link below to update your timesheet: +
+ Update Timesheet +
+
+ Thank you for your attention. +
+ Best regards, +
+ Fast Track Project Pvt Ltd. +
+
+ Visit our site for more information. +

+
+
diff --git a/addons_extensions/cwf_timesheet/models/timesheet.py b/addons_extensions/cwf_timesheet/models/timesheet.py index d71d8614e..021ca6943 100644 --- a/addons_extensions/cwf_timesheet/models/timesheet.py +++ b/addons_extensions/cwf_timesheet/models/timesheet.py @@ -68,8 +68,14 @@ class CwfTimesheet(models.Model): lines = fields.One2many('cwf.timesheet.line','week_id') cwf_calendar_id = fields.Many2one('cwf.timesheet.calendar') + @api.depends('name','week_start_date','week_end_date') + def _compute_display_name(self): + for rec in self: + rec.display_name = rec.name if not rec.week_start_date and rec.week_end_date else "%s (%s - %s)"%(rec.name,rec.week_start_date.strftime('%-d %b'), rec.week_end_date.strftime('%-d %b') ) + + def send_timesheet_update_email(self): - template = self.env.ref('cwf_timesheet.email_template_timesheet_update') + template = self.env.ref('cwf_timesheet.email_template_timesheet_weekly_update') # Ensure that we have a valid employee email current_date = fields.Date.from_string(self.week_start_date) end_date = fields.Date.from_string(self.week_end_date) @@ -85,12 +91,12 @@ class CwfTimesheet(models.Model): # Loop through each day of the week and create timesheet lines for each employee while current_date <= end_date: for employee in employees: - existing_record = self.env['cwf.weekly.timesheet'].search([ + existing_record = self.env['cwf.weekly.timesheet'].sudo().search([ ('week_id', '=', self.id), ('employee_id', '=', employee.id) ], limit=1) if not existing_record: - self.env['cwf.timesheet.line'].create({ + self.env['cwf.timesheet.line'].sudo().create({ 'week_id': self.id, 'employee_id': employee.id, 'week_day':current_date, @@ -106,24 +112,27 @@ class CwfTimesheet(models.Model): 'employee_id': employee.id, 'status': 'draft' }) + else: + weekly_timesheet = weekly_timesheet_exists # Generate the URL for the newly created weekly_timesheet base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') record_url = f"{base_url}/web#id={weekly_timesheet.id}&view_type=form&model=cwf.weekly.timesheet" weekly_timesheet.update_attendance() - - if employee.work_email: + if employee.work_email and weekly_timesheet: email_values = { - 'email_to': employee.work_email, - 'body_html': template.body_html.replace( - 'https://ftprotech.in/odoo/action-261', - record_url - ), # Email body from template + 'email_to': employee.work_email, # Email body from template 'subject': 'Timesheet Update Notification', } + body_html = template.body_html.replace( + 'https://ftprotech.in/odoo/action-261', + record_url + ), + render_ctx = {'employee_name':weekly_timesheet.employee_id.name,'week_from':weekly_timesheet.week_id.week_start_date,'week_to':weekly_timesheet.week_id.week_end_date} - template.send_mail(self.id, email_values=email_values, force_send=True) + + template.with_context(default_body_html=body_html,**render_ctx).send_mail(weekly_timesheet.id, email_values=email_values, force_send=True) class CwfWeeklyTimesheet(models.Model): @@ -131,7 +140,16 @@ class CwfWeeklyTimesheet(models.Model): _description = "CWF Weekly Timesheet" _rec_name = 'employee_id' - week_id = fields.Many2one('cwf.timesheet', 'Week') + + def _default_week_id(self): + timesheet = False + current_date = fields.Date.today() + timesheet = self.env['cwf.timesheet'].sudo().search([('week_start_date','<=',current_date),('week_end_date','>=',current_date)],limit=1) + if timesheet: + return timesheet.id + return timesheet + + week_id = fields.Many2one('cwf.timesheet', 'Week', default=lambda self: self._default_week_id()) employee_id = fields.Many2one('hr.employee', default=lambda self: self.env.user.employee_id.id) cwf_timesheet_lines = fields.One2many('cwf.timesheet.line' ,'weekly_timesheet') status = fields.Selection([('draft','Draft'),('submitted','Submitted')], default='draft') @@ -141,6 +159,8 @@ class CwfWeeklyTimesheet(models.Model): @api.constrains('week_id', 'employee_id') def _check_unique_week_employee(self): for record in self: + if record.week_id.week_start_date > fields.Date.today(): + raise ValidationError(_("You Can't select future week period")) # Search for existing records with the same week_id and employee_id existing_record = self.env['cwf.weekly.timesheet'].search([ ('week_id', '=', record.week_id.id), diff --git a/addons_extensions/cwf_timesheet/security/ir.model.access.csv b/addons_extensions/cwf_timesheet/security/ir.model.access.csv index c40c06f17..e72bcf01c 100644 --- a/addons_extensions/cwf_timesheet/security/ir.model.access.csv +++ b/addons_extensions/cwf_timesheet/security/ir.model.access.csv @@ -7,6 +7,9 @@ access_cwf_timesheet_calendar,cwf_timesheet_calendar,model_cwf_timesheet_calenda access_cwf_timesheet_calendar_user,cwf_timesheet_calendar_user,model_cwf_timesheet_calendar,base.group_user,1,0,0,0 -access_cwf_timesheet_line_user,access.cwf.timesheet.line,model_cwf_timesheet_line,,1,1,1,1 +access_cwf_timesheet_line_manager,access.cwf.timesheet.line.manager,model_cwf_timesheet_line,hr_attendance.group_hr_attendance_manager,1,1,1,1 +access_cwf_timesheet_line_user,access.cwf.timesheet.line,model_cwf_timesheet_line,hr_employee_extended.group_external_user,1,1,1,1 -access_cwf_weekly_timesheet_user,cwf.weekly.timesheet access,model_cwf_weekly_timesheet,,1,1,1,1 + +access_cwf_weekly_timesheet_manager,cwf.weekly.timesheet.manager access,model_cwf_weekly_timesheet,hr_attendance.group_hr_attendance_manager,1,1,1,1 +access_cwf_weekly_timesheet_user,cwf.weekly.timesheet access,model_cwf_weekly_timesheet,hr_employee_extended.group_external_user,1,1,1,0 diff --git a/addons_extensions/cwf_timesheet/security/security.xml b/addons_extensions/cwf_timesheet/security/security.xml new file mode 100644 index 000000000..3d18c8786 --- /dev/null +++ b/addons_extensions/cwf_timesheet/security/security.xml @@ -0,0 +1,36 @@ + + + + + CWF Weekly Timesheet User Rule + + [('employee_id.user_id.id','=',user.id)] + + + + + CWF Timesheet Line User Rule + + [('employee_id.user_id.id','=',user.id)] + + + + + CWF Weekly Timesheet manager Rule + + ['|',('employee_id.user_id.id','!=',user.id),('employee_id.user_id.id','=',user.id)] + + + + + CWF Timesheet Line manager Rule + + ['|',('employee_id.user_id.id','!=',user.id),('employee_id.user_id.id','=',user.id)] + + + + + + + + \ No newline at end of file diff --git a/addons_extensions/cwf_timesheet/views/timesheet_view.xml b/addons_extensions/cwf_timesheet/views/timesheet_view.xml index 4e812f8bb..bd9956e27 100644 --- a/addons_extensions/cwf_timesheet/views/timesheet_view.xml +++ b/addons_extensions/cwf_timesheet/views/timesheet_view.xml @@ -43,7 +43,7 @@ list,form - + @@ -71,7 +71,17 @@ - + + cwf.timesheet.list + cwf.timesheet + + + + + + + + CWF Timesheet cwf.timesheet diff --git a/addons_extensions/cwf_timesheet/views/timesheet_weekly_view.xml b/addons_extensions/cwf_timesheet/views/timesheet_weekly_view.xml index 91f224105..2572b2b02 100644 --- a/addons_extensions/cwf_timesheet/views/timesheet_weekly_view.xml +++ b/addons_extensions/cwf_timesheet/views/timesheet_weekly_view.xml @@ -4,7 +4,7 @@ cwf.weekly.timesheet.form cwf.weekly.timesheet -
+
- +