DEV: Probation Tracking

This commit is contained in:
Bhagya-K 2026-06-22 15:01:12 +05:30
parent e2c8a25c7b
commit d448713449
8 changed files with 251 additions and 50 deletions

View File

@ -0,0 +1,2 @@
from . import discuss_channel_notify
from . import mail_activity

View File

@ -0,0 +1,74 @@
from odoo import models
import logging
import re
_logger = logging.getLogger(__name__)
class MailTemplate(models.Model):
_inherit = "mail.template"
def send_mail(
self,
res_id,
force_send=False,
raise_exception=False,
email_values=None,
):
record = self.env[self.model].browse(res_id)
# determine recipient directly from business object
recipient_user = False
if self.model == "weekly.periodtimesheets":
if "Submitted" in (self.subject or ""):
recipient_user = (
record.employee_id.parent_id.user_id
)
elif (
"Approved" in (self.subject or "")
or "Rejected" in (self.subject or "")
):
recipient_user = (
record.employee_id.user_id
)
mail_id = super().send_mail(
res_id,
force_send=force_send,
raise_exception=raise_exception,
email_values=email_values,
)
try:
if (
recipient_user
and recipient_user.token
):
self.env["firebase.service"].send_notification([
{
"token": recipient_user.token,
"title": self.subject or "Notification",
"body": "You have received a new email notification",
"data": {
"mail_id": str(mail_id),
"model": self.model,
"record_id": str(res_id),
},
}
])
_logger.info(
"Firebase sent to %s",
recipient_user.name,
)
except Exception:
_logger.exception(
"Firebase notification failed"
)
return mail_id

View File

@ -0,0 +1,30 @@
from odoo import models,fields
from ..tools.firebase import send_firebase_notifications
class FirebaseService(models.AbstractModel):
_name = "firebase.service"
_description = "Firebase Service"
def send_notification(self, messages):
return send_firebase_notifications(messages)
class ResUsers(models.Model):
_inherit = "res.users"
token = fields.Char(string="Firebase Token")
def send_push_notification(self, title, body, data=None):
self.ensure_one()
if not self.token:
return False
return self.env['firebase.service'].send_notification([
{
'token': self.token,
'title': title,
'body': body,
'data': data or {},
}
])

View File

@ -1,4 +1,7 @@
from odoo import models, fields, api
from odoo.exceptions import ValidationError
import base64
import os
class RecruitmentAttachments(models.Model):
_name = 'recruitment.attachments'
@ -22,9 +25,30 @@ class EmployeeRecruitmentAttachments(models.Model):
recruitment_attachment_id = fields.Many2one('recruitment.attachments')
recruitment_attachment_type = fields.Selection([('personal','Personal Documents'),('education','Education Documents'),('previous_employer','Previous Employer'),('others','Others')],related='recruitment_attachment_id.attachment_type')
file = fields.Binary(string='File', required=True)
file_name = fields.Char(string='Filename')
review_status = fields.Selection([('draft','Under Review'),('pass','PASS'),('fail','FAIL')], default='draft')
review_comments = fields.Char()
@api.constrains('file', 'file_name')
def _check_file_validation(self):
allowed_extensions = ['pdf', 'doc', 'jpg', 'jpeg']
for rec in self:
if rec.file and rec.file_name:
extension = os.path.splitext(rec.file_name)[1].lower().replace('.', '')
if extension not in allowed_extensions:
raise ValidationError(
"Only PDF, DOC and JPG files are allowed."
)
file_size = len(base64.b64decode(rec.file))
if file_size > 5 * 1024 * 1024:
raise ValidationError(
"File size cannot exceed 5 MB."
)
def action_preview_file(self):
""" Returns a URL to preview the attachment in a popup """
for record in self:

View File

@ -29,7 +29,7 @@
<list editable="top">
<field name="name"/>
<field name="applicant_id"/>
<field name="file" widget="binary" filename="name" options="{'preview_image': 'file','download': true}" />
<field name="file" widget="binary" filename="file_name" options="{'preview_image': 'file','download': true}" />
</list>
</field>
</group>
@ -51,7 +51,8 @@
<field name="recruitment_attachment_id"/>
<field name="name"/>
<field name="recruitment_attachment_type"/>
<field name="file" widget="binary" options="{'download':true}"/>
<field name="file" widget="binary" filename="file_name" options="{'download':true}"/>
<field name="file_name" column_invisible="1"/>
</list>
</field>
</group>

View File

@ -51,6 +51,7 @@ class WeeklyPeriodTimesheets(models.Model):
('draft', 'Draft'),
('submitted', 'Submitted'),
('approved', 'Approved'),
('rejected', 'Rejected'),
], string="Status", default='draft')
def action_submit(self):
@ -92,6 +93,39 @@ class WeeklyPeriodTimesheets(models.Model):
force_send=True
)
def action_reject(self):
for rec in self:
analytic_lines = self.env[
'account.analytic.line'
].search([
('employee_id', '=', rec.employee_id.id),
('date', '>=', rec.week_line_id.date_from),
('date', '<=', rec.week_line_id.date_to),
])
for line in analytic_lines:
vals = {
'weekly_submitted': True
}
if not line.pm_approval_required:
vals['approval_state'] = 'rejected'
line.write(vals)
rec.state = 'rejected'
template = self.env.ref(
'weekly_timesheets.email_template_weekly_timesheet_reject'
)
if template:
template.send_mail(
rec.id,
force_send=True
)
def action_approve(self):
for rec in self:
@ -133,6 +167,35 @@ class WeeklyPeriodTimesheets(models.Model):
)
rec.state = 'approved'
template = self.env.ref(
'weekly_timesheets.email_template_weekly_timesheet_approve'
)
if template:
template.send_mail(
rec.id,
force_send=True
)
employee_user = rec.employee_id.user_id
if employee_user and employee_user.token:
self.env['firebase.service'].send_notification([
{
'token': employee_user.token,
'title': 'Timesheet Approved',
'body': (
f'Your timesheet for '
f'{rec.week_line_id.date_from} '
f'to '
f'{rec.week_line_id.date_to} '
f'has been approved.'
),
'data': {
'type': 'timesheet_approved',
'timesheet_id': str(rec.id),
}
}
])
def action_reset_to_draft(self):
for rec in self:

View File

@ -1,59 +1,61 @@
<odoo>
<record id="email_template_weekly_timesheet_submit"
model="mail.template">
<field name="name">
Weekly Timesheet Submitted
</field>
<field name="model_id"
ref="model_weekly_periodtimesheets"/>
<field name="subject">
Weekly Timesheet Submitted - ${object.employee_id.name}
</field>
<field name="email_from">
${user.email | safe}
</field>
<field name="email_to">
${object.employee_id.parent_id.work_email}
</field>
<record id="email_template_weekly_timesheet_submit" model="mail.template">
<field name="name">Weekly Timesheet Submitted</field>
<field name="model_id" ref="model_weekly_periodtimesheets"/>
<field name="subject">Weekly Timesheet Submitted - ${object.employee_id.name}</field>
<field name="email_from">${user.email | safe}</field>
<field name="email_to">${object.employee_id.parent_id.work_email}</field>
<field name="body_html" type="html">
<div>
<p>Hello,</p>
<p>
Employee
<strong>${object.employee_id.name}</strong>
has submitted the weekly timesheet.
</p>
<p>
Week:
${object.week_line_id.name}
</p>
<p>
Total Hours:
${object.total_hours}
</p>
<p>
Please review and approve.
</p>
<p>Employee<strong>${object.employee_id.name}</strong> has submitted the weekly timesheet.</p>
<p>Week: ${object.week_line_id.name}</p>
<p>Total Hours: ${object.total_hours}</p>
<p>Please review and approve.</p>
<br/>
<p>Thank You</p>
</div>
</field>
</record>
<record id="email_template_weekly_timesheet_reject" model="mail.template">
<field name="name">Weekly Timesheet Rejected</field>
<field name="model_id" ref="model_weekly_periodtimesheets"/>
<field name="subject">Weekly Timesheet Rejected - ${object.employee_id.name}</field>
<field name="email_from">${user.email | safe}</field>
<field name="email_to">${object.employee_id.work_email}</field>
<field name="body_html" type="html">
<div>
<p>Hello,</p>
<p>Employee<strong>${object.employee_id.name}</strong>has rejected the weekly timesheet.</p>
<p>Week: ${object.week_line_id.name}</p>
<p>Total Hours: ${object.total_hours}</p>
<br/>
<p>Thank You</p>
</div>
</field>
</record>
<record id="email_template_weekly_timesheet_approve" model="mail.template">
<field name="name">Weekly Timesheet Approved</field>
<field name="model_id" ref="model_weekly_periodtimesheets"/>
<field name="subject">Weekly Timesheet Approved - ${object.employee_id.name}</field>
<field name="email_from">${user.email | safe}</field>
<field name="email_to">${object.employee_id.work_email}</field>
<field name="body_html" type="html">
<div>
<p>Hello,</p>
<p>
Employee<strong>${object.employee_id.name}</strong>has approved the weekly timesheet.
</p>
<p>
Week: ${object.week_line_id.name}
</p>
<p>
Total Hours: ${object.total_hours}
</p>
<br/>
<p>Thank You</p>
</div>
</field>
</record>
</odoo>

View File

@ -13,6 +13,11 @@
type="object"
class="btn-primary"
invisible="state != 'draft'"/>
<button name="action_reject"
string="Reject"
type="object"
class="btn-primary"
invisible="state != 'submitted'"/>
<button name="action_approve"
string="Approve"
type="object"