CWF Timesheet Access rights

This commit is contained in:
Pranay 2025-04-30 16:47:21 +05:30 committed by raman
parent 11066ba9c1
commit 62df996ae4
7 changed files with 132 additions and 126 deletions

View File

@ -7,6 +7,7 @@
'depends': ['hr_attendance_extended','web', 'mail', 'base','hr_emp_dashboard','hr_employee_extended'], 'depends': ['hr_attendance_extended','web', 'mail', 'base','hr_emp_dashboard','hr_employee_extended'],
'data': [ 'data': [
# 'views/timesheet_form.xml', # 'views/timesheet_form.xml',
'security/security.xml',
'security/ir.model.access.csv', 'security/ir.model.access.csv',
'views/timesheet_view.xml', 'views/timesheet_view.xml',
'views/timesheet_weekly_view.xml', 'views/timesheet_weekly_view.xml',

View File

@ -1,109 +1,45 @@
<odoo> <odoo>
<data noupdate="0"> <data noupdate="0">
<record id="email_template_timesheet_update" model="mail.template"> <record id="email_template_timesheet_weekly_update" model="mail.template">
<field name="name">Timesheet Update Reminder</field> <field name="name">Timesheet Update Reminder</field>
<field name="email_from">${(user.email or '')}</field> <field name="model_id" ref="cwf_timesheet.model_cwf_weekly_timesheet"/>
<field name="email_from">{{ user.email_formatted }}</field>
<field name="email_to">{{ object.employee_id.user_id.email }}</field>
<field name="subject">Reminder: Update Your Weekly Timesheet</field> <field name="subject">Reminder: Update Your Weekly Timesheet</field>
<field name="body_html" type="html"> <style> <field name="description">
body { Reminder to employee to update their weekly timesheet.
font-family: Arial, sans-serif; </field>
margin: 0; <field name="body_html" type="html">
padding: 0; <p style="margin: 0px; padding: 0px; font-size: 13px;">
background-color: #f4f6f9; Dear <t t-esc="ctx['employee_name']">Employee</t>,
} <br/>
.email-container { <br/>
width: 100%; 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
background: linear-gradient(45deg, #3498db, #2c3e50); <strong>
padding: 40px 0; <t t-esc="ctx['week_from']"/>
display: flex; </strong>
justify-content: center; to
} <strong>
.email-content { <t t-esc="ctx['week_to']"/>
background-color: white; </strong>.
border-radius: 12px;
width: 80%;
max-width: 700px;
padding: 30px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.header {
text-align: center;
margin-bottom: 20px;
}
.header h1 {
color: #3498db;
font-size: 32px;
margin: 0;
}
.greeting {
font-size: 18px;
color: #2c3e50;
margin-bottom: 20px;
}
.message {
font-size: 16px;
color: #333;
line-height: 1.5;
margin-bottom: 20px;
}
.cta-button {
display: inline-block;
padding: 12px 25px;
background-color: #3498db;
color: white;
font-size: 16px;
text-decoration: none;
border-radius: 6px;
transition: background-color 0.3s;
}
.cta-button:hover {
background-color: #2980b9;
}
.footer {
font-size: 14px;
color: #7f8c8d;
margin-top: 30px;
text-align: center;
}
.footer a {
color: #3498db;
text-decoration: none;
}
</style>
<body>
<div class="email-container">
<div class="email-content">
<div class="header">
<h1>Timesheet Reminder</h1>
</div>
<div class="greeting">
<p>Dear <strong t-out="object.employee_id.name"/> ,</p>
</div>
<div class="message">
<p>
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 <strong t-out="object.week_id.week_start_date"/> to <strong t-out="object.week_id.week_end_date"/>.
Timely updates are crucial for maintaining accurate records and ensuring smooth processing. Timely updates are crucial for maintaining accurate records and ensuring smooth processing.
</p> <br/>
<p> <br/>
To make things easier, you can use the link below to update your timesheet: To make things easier, you can use the link below to update your timesheet:
</p> <br/>
<a href="https://ftprotech.in/odoo/action-261" class="cta-button" target="_blank">Update Timesheet</a> <a href="https://ftprotech.in/odoo/action-261" class="cta-button" target="_blank">Update Timesheet</a>
</div> <br/>
<div class="footer"> <br/>
<p> Thank you for your attention.
Thank you for your attention.<br/> <br/>
Best regards,<br/> Best regards,
<br/>
<strong>Fast Track Project Pvt Ltd.</strong> <strong>Fast Track Project Pvt Ltd.</strong>
</p> <br/>
<p> <br/>
<a href="https://ftprotech.in/" target="_blank">Visit our site</a> for more information. <a href="https://ftprotech.in/" target="_blank">Visit our site</a> for more information.
</p> </p>
</div>
</div>
</div>
</body>
</field> </field>
<field name="model_id" ref="model_cwf_timesheet_line"/> <!-- Ensure this line references the correct model --> </record>
</record>
</data> </data>
</odoo> </odoo>

View File

@ -68,8 +68,14 @@ class CwfTimesheet(models.Model):
lines = fields.One2many('cwf.timesheet.line','week_id') lines = fields.One2many('cwf.timesheet.line','week_id')
cwf_calendar_id = fields.Many2one('cwf.timesheet.calendar') 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): 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 # Ensure that we have a valid employee email
current_date = fields.Date.from_string(self.week_start_date) current_date = fields.Date.from_string(self.week_start_date)
end_date = fields.Date.from_string(self.week_end_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 # Loop through each day of the week and create timesheet lines for each employee
while current_date <= end_date: while current_date <= end_date:
for employee in employees: 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), ('week_id', '=', self.id),
('employee_id', '=', employee.id) ('employee_id', '=', employee.id)
], limit=1) ], limit=1)
if not existing_record: if not existing_record:
self.env['cwf.timesheet.line'].create({ self.env['cwf.timesheet.line'].sudo().create({
'week_id': self.id, 'week_id': self.id,
'employee_id': employee.id, 'employee_id': employee.id,
'week_day':current_date, 'week_day':current_date,
@ -106,24 +112,27 @@ class CwfTimesheet(models.Model):
'employee_id': employee.id, 'employee_id': employee.id,
'status': 'draft' 'status': 'draft'
}) })
else:
weekly_timesheet = weekly_timesheet_exists
# Generate the URL for the newly created weekly_timesheet # Generate the URL for the newly created weekly_timesheet
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') 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" record_url = f"{base_url}/web#id={weekly_timesheet.id}&view_type=form&model=cwf.weekly.timesheet"
weekly_timesheet.update_attendance() weekly_timesheet.update_attendance()
if employee.work_email and weekly_timesheet:
if employee.work_email:
email_values = { email_values = {
'email_to': employee.work_email, 'email_to': employee.work_email, # Email body from template
'body_html': template.body_html.replace(
'https://ftprotech.in/odoo/action-261',
record_url
), # Email body from template
'subject': 'Timesheet Update Notification', '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): class CwfWeeklyTimesheet(models.Model):
@ -131,7 +140,16 @@ class CwfWeeklyTimesheet(models.Model):
_description = "CWF Weekly Timesheet" _description = "CWF Weekly Timesheet"
_rec_name = 'employee_id' _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) 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') cwf_timesheet_lines = fields.One2many('cwf.timesheet.line' ,'weekly_timesheet')
status = fields.Selection([('draft','Draft'),('submitted','Submitted')], default='draft') status = fields.Selection([('draft','Draft'),('submitted','Submitted')], default='draft')
@ -141,6 +159,8 @@ class CwfWeeklyTimesheet(models.Model):
@api.constrains('week_id', 'employee_id') @api.constrains('week_id', 'employee_id')
def _check_unique_week_employee(self): def _check_unique_week_employee(self):
for record in 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 # Search for existing records with the same week_id and employee_id
existing_record = self.env['cwf.weekly.timesheet'].search([ existing_record = self.env['cwf.weekly.timesheet'].search([
('week_id', '=', record.week_id.id), ('week_id', '=', record.week_id.id),

View File

@ -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_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

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
7 access_cwf_weekly_timesheet_user access_cwf_timesheet_line_user cwf.weekly.timesheet access access.cwf.timesheet.line model_cwf_weekly_timesheet model_cwf_timesheet_line hr_employee_extended.group_external_user 1 1 1 1
8 access_cwf_weekly_timesheet_manager cwf.weekly.timesheet.manager access model_cwf_weekly_timesheet hr_attendance.group_hr_attendance_manager 1 1 1 1
9 access_cwf_weekly_timesheet_user cwf.weekly.timesheet access model_cwf_weekly_timesheet hr_employee_extended.group_external_user 1 1 1 0
10
11
12
13
14
15

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data noupdate="0">
<record id="cwf_weekly_timesheet_user_rule" model="ir.rule">
<field name="name">CWF Weekly Timesheet User Rule</field>
<field ref="cwf_timesheet.model_cwf_weekly_timesheet" name="model_id"/>
<field name="domain_force">[('employee_id.user_id.id','=',user.id)]</field>
<field name="groups" eval="[(4, ref('hr_employee_extended.group_external_user'))]"/>
</record>
<record id="cwf_timesheet_line_user_rule" model="ir.rule">
<field name="name">CWF Timesheet Line User Rule</field>
<field ref="cwf_timesheet.model_cwf_timesheet_line" name="model_id"/>
<field name="domain_force">[('employee_id.user_id.id','=',user.id)]</field>
<field name="groups" eval="[(4, ref('hr_employee_extended.group_external_user'))]"/>
</record>
<record id="cwf_weekly_timesheet_manager_rule" model="ir.rule">
<field name="name">CWF Weekly Timesheet manager Rule</field>
<field ref="cwf_timesheet.model_cwf_weekly_timesheet" name="model_id"/>
<field name="domain_force">['|',('employee_id.user_id.id','!=',user.id),('employee_id.user_id.id','=',user.id)]</field>
<field name="groups" eval="[(4, ref('hr_attendance.group_hr_attendance_manager'))]"/>
</record>
<record id="cwf_timesheet_line_manager_rule" model="ir.rule">
<field name="name">CWF Timesheet Line manager Rule</field>
<field ref="cwf_timesheet.model_cwf_timesheet_line" name="model_id"/>
<field name="domain_force">['|',('employee_id.user_id.id','!=',user.id),('employee_id.user_id.id','=',user.id)]</field>
<field name="groups" eval="[(4, ref('hr_attendance.group_hr_attendance_manager'))]"/>
</record>
</data>
</odoo>

View File

@ -43,7 +43,7 @@
<field name="view_mode">list,form</field> <field name="view_mode">list,form</field>
</record> </record>
<menuitem id="menu_timesheet_calendar_form" name="CWF Timesheet Calendar" parent="hr_attendance_extended.menu_attendance_attendance" action="cwf_timesheet.action_cwf_timesheet_calendar"/> <menuitem id="menu_timesheet_calendar_form" name="CWF Timesheet Calendar" parent="hr_attendance_extended.menu_attendance_attendance" action="cwf_timesheet.action_cwf_timesheet_calendar" groups="hr_employee_extended.group_external_user,hr_attendance.group_hr_attendance_manager"/>
@ -71,7 +71,17 @@
</form> </form>
</field> </field>
</record> </record>
<record id="view_timesheet_list" model="ir.ui.view">
<field name="name">cwf.timesheet.list</field>
<field name="model">cwf.timesheet</field>
<field name="arch" type="xml">
<list>
<field name="name"/>
<field name="week_start_date"/>
<field name="week_end_date"/>
</list>
</field>
</record>
<record id="action_cwf_timesheet" model="ir.actions.act_window"> <record id="action_cwf_timesheet" model="ir.actions.act_window">
<field name="name">CWF Timesheet</field> <field name="name">CWF Timesheet</field>
<field name="res_model">cwf.timesheet</field> <field name="res_model">cwf.timesheet</field>

View File

@ -4,7 +4,7 @@
<field name="name">cwf.weekly.timesheet.form</field> <field name="name">cwf.weekly.timesheet.form</field>
<field name="model">cwf.weekly.timesheet</field> <field name="model">cwf.weekly.timesheet</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="CWF Weekly Timesheet" create="0"> <form string="CWF Weekly Timesheet">
<header> <header>
<button name="update_attendance" string="Update" <button name="update_attendance" string="Update"
type="object" class="oe_highlight" invisible="status != 'draft'"/> type="object" class="oe_highlight" invisible="status != 'draft'"/>
@ -14,7 +14,7 @@
</header> </header>
<sheet> <sheet>
<group> <group>
<field name="week_id" readonly="1"/> <field name="week_id" readonly="0"/>
<field name="employee_id" readonly="1"/> <field name="employee_id" readonly="1"/>
<label for="week_start_date" string="Dates"/> <label for="week_start_date" string="Dates"/>
<div class="o_row"> <div class="o_row">
@ -46,7 +46,7 @@
<field name="name">cwf.weekly.timesheet.list</field> <field name="name">cwf.weekly.timesheet.list</field>
<field name="model">cwf.weekly.timesheet</field> <field name="model">cwf.weekly.timesheet</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<list create="0"> <list>
<field name="week_id"/> <field name="week_id"/>
<field name="employee_id"/> <field name="employee_id"/>
<field name="status"/> <field name="status"/>
@ -148,8 +148,8 @@
<menuitem id="menu_timesheet_form" name="CWF Weekly Timesheet " <menuitem id="menu_timesheet_form" name="CWF Weekly Timesheet "
parent="hr_attendance_extended.menu_attendance_attendance" action="action_cwf_weekly_timesheet"/> parent="hr_attendance_extended.menu_attendance_attendance" action="action_cwf_weekly_timesheet" groups="hr_employee_extended.group_external_user,hr_attendance.group_hr_attendance_manager"/>
<menuitem id="menu_timesheet_form_line" name="CWF Timesheet Lines" <menuitem id="menu_timesheet_form_line" name="CWF Timesheet Lines"
parent="hr_attendance_extended.menu_attendance_attendance" action="action_cwf_timesheet_line"/> parent="hr_attendance_extended.menu_attendance_attendance" action="action_cwf_timesheet_line" groups="hr_employee_extended.group_external_user,hr_attendance.group_hr_attendance_manager"/>
</odoo> </odoo>