mirror of
https://gitlab.com/sonalarora/tra_backend.git
synced 2025-12-23 21:25:31 +02:00
add new module
This commit is contained in:
24
hr_reward_warning/models/__init__.py
Executable file
24
hr_reward_warning/models/__init__.py
Executable file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###################################################################################
|
||||
# A part of OpenHRMS Project <https://www.openhrms.com>
|
||||
#
|
||||
# Cybrosys Technologies Pvt. Ltd.
|
||||
# Copyright (C) 2018-TODAY Cybrosys Technologies (<https://www.cybrosys.com>).
|
||||
# Author: Jesni Banu (<https://www.cybrosys.com>)
|
||||
#
|
||||
# This program is free software: you can modify
|
||||
# it under the terms of the GNU Affero General Public License (AGPL) as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
###################################################################################
|
||||
from . import hr_warning
|
||||
from . import hr_employee
|
||||
107
hr_reward_warning/models/hr_employee.py
Executable file
107
hr_reward_warning/models/hr_employee.py
Executable file
@@ -0,0 +1,107 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###################################################################################
|
||||
# A part of OpenHRMS Project <https://www.openhrms.com>
|
||||
#
|
||||
# Cybrosys Technologies Pvt. Ltd.
|
||||
# Copyright (C) 2018-TODAY Cybrosys Technologies (<https://www.cybrosys.com>).
|
||||
# Author: Jesni Banu (<https://www.cybrosys.com>)
|
||||
#
|
||||
# This program is free software: you can modify
|
||||
# it under the terms of the GNU Affero General Public License (AGPL) as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
###################################################################################
|
||||
from datetime import datetime
|
||||
from odoo import models, fields, api, _
|
||||
|
||||
|
||||
class HrAnnouncements(models.Model):
|
||||
_inherit = 'hr.employee'
|
||||
|
||||
def _announcement_count(self):
|
||||
now = datetime.now()
|
||||
now_date = now.date()
|
||||
for rec in self:
|
||||
ann_ids_general = self.env['hr.announcement'].sudo().search([('is_announcement', '=', True),
|
||||
('state', 'in', ('approved', 'done')),
|
||||
('date_start', '<=', now_date),
|
||||
('date_end', '>=', now_date)])
|
||||
ann_ids_emp = self.env['hr.announcement'].search([('employee_ids', 'in', [rec.id]),
|
||||
('announcement_type', '=', 'employee'),
|
||||
('state', 'in', ('approved', 'done')),
|
||||
('date_start', '<=', now_date),
|
||||
('date_end', '>=', now_date)])
|
||||
ann_ids_dep = self.env['hr.announcement'].sudo().search([('department_ids', 'in', [rec.department_id.id]),
|
||||
('announcement_type', '=', 'department'),
|
||||
('state', 'in', ('approved', 'done')),
|
||||
('date_start', '<=', now_date),
|
||||
('date_end', '>=', now_date)])
|
||||
ann_ids_job = self.env['hr.announcement'].sudo().search([('position_ids', 'in', [rec.job_id.id]),
|
||||
('announcement_type', '=', 'job_position'),
|
||||
('state', 'in', ('approved', 'done')),
|
||||
('date_start', '<=', now_date),
|
||||
('date_end', '>=', now_date)])
|
||||
rec.announcement_count = len(ann_ids_general) + len(ann_ids_emp) + len(ann_ids_dep) + len(ann_ids_job)
|
||||
|
||||
def announcement_view(self):
|
||||
now = datetime.now()
|
||||
now_date = now.date()
|
||||
for rec in self:
|
||||
ann_ids_general = self.env['hr.announcement'].sudo().search([('is_announcement', '=', True),
|
||||
('state', 'in', ('approved', 'done')),
|
||||
('date_start', '<=', now_date),
|
||||
('date_end', '>=', now_date)])
|
||||
ann_ids_emp = self.env['hr.announcement'].sudo().search([('announcement_type', '=', 'employee'),
|
||||
('employee_ids', 'in', [rec.id]),
|
||||
('state', 'in', ('approved', 'done')),
|
||||
('date_start', '<=', now_date),
|
||||
('date_end', '>=', now_date)])
|
||||
ann_ids_dep = self.env['hr.announcement'].sudo().search([('announcement_type', '=', 'department'),
|
||||
('department_ids', 'in', [rec.department_id.id]),
|
||||
('state', 'in', ('approved', 'done')),
|
||||
('date_start', '<=', now_date),
|
||||
('date_end', '>=', now_date)])
|
||||
ann_ids_job = self.env['hr.announcement'].sudo().search([('announcement_type', '=', 'job_position'),
|
||||
('position_ids', 'in', [rec.job_id.id]),
|
||||
('state', 'in', ('approved', 'done')),
|
||||
('date_start', '<=', now_date),
|
||||
('date_end', '>=', now_date)])
|
||||
|
||||
ann_obj = ann_ids_general.ids + ann_ids_emp.ids + ann_ids_job.ids + ann_ids_dep.ids
|
||||
ann_ids = []
|
||||
for each in ann_obj:
|
||||
ann_ids.append(each)
|
||||
view_id = self.env.ref('hr_reward_warning.view_hr_announcement_form').id
|
||||
if ann_ids:
|
||||
if len(ann_ids) > 1:
|
||||
value = {
|
||||
'domain': str([('id', 'in', ann_ids)]),
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'hr.announcement',
|
||||
'view_id': False,
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Announcements'),
|
||||
'res_id': ann_ids
|
||||
}
|
||||
else:
|
||||
value = {
|
||||
'view_mode': 'form',
|
||||
'res_model': 'hr.announcement',
|
||||
'view_id': view_id,
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Announcements'),
|
||||
'res_id': ann_ids and ann_ids[0]
|
||||
}
|
||||
return value
|
||||
|
||||
announcement_count = fields.Integer(compute='_announcement_count', string='# Announcements',
|
||||
help="Count of Announcement's")
|
||||
98
hr_reward_warning/models/hr_warning.py
Executable file
98
hr_reward_warning/models/hr_warning.py
Executable file
@@ -0,0 +1,98 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###################################################################################
|
||||
# A part of OpenHRMS Project <https://www.openhrms.com>
|
||||
#
|
||||
# Cybrosys Technologies Pvt. Ltd.
|
||||
# Copyright (C) 2018-TODAY Cybrosys Technologies (<https://www.cybrosys.com>).
|
||||
# Author: Jesni Banu (<https://www.cybrosys.com>)
|
||||
#
|
||||
# This program is free software: you can modify
|
||||
# it under the terms of the GNU Affero General Public License (AGPL) as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
###################################################################################
|
||||
from datetime import datetime
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class HrAnnouncementTable(models.Model):
|
||||
_name = 'hr.announcement'
|
||||
_description = 'HR Announcement'
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin']
|
||||
|
||||
name = fields.Char(string='Code No:', help="Sequence Number of the Announcement")
|
||||
announcement_reason = fields.Text(string='Title', states={'draft': [('readonly', False)]}, required=True,
|
||||
readonly=True, help="Announcement Subject")
|
||||
state = fields.Selection([('draft', 'Draft'), ('to_approve', 'Waiting For Approval'),
|
||||
('approved', 'Approved'), ('rejected', 'Refused'), ('expired', 'Expired')],
|
||||
string='Status', default='draft',
|
||||
track_visibility='always')
|
||||
requested_date = fields.Date(string='Requested Date', default=datetime.now().strftime('%Y-%m-%d'),
|
||||
help="Create Date of Record")
|
||||
attachment_id = fields.Many2many('ir.attachment', 'doc_warning_rel', 'doc_id', 'attach_id4',
|
||||
string="Attachment", help='You can attach the copy of your Letter')
|
||||
company_id = fields.Many2one('res.company', string='Company',
|
||||
default=lambda self: self.env.user.company_id, readonly=True, help="Login user Company")
|
||||
is_announcement = fields.Boolean(string='Is general Announcement?', help="To set Announcement as general announcement")
|
||||
announcement_type = fields.Selection([('employee', 'By Employee'), ('department', 'By Department'), ('job_position', 'By Job Position')])
|
||||
employee_ids = fields.Many2many('hr.employee', 'hr_employee_announcements', 'announcement', 'employee',
|
||||
string='Employees', help="Employee's which want to see this announcement")
|
||||
department_ids = fields.Many2many('hr.department', 'hr_department_announcements', 'announcement', 'department',
|
||||
string='Departments', help="Department's which want to see this announcement")
|
||||
position_ids = fields.Many2many('hr.job', 'hr_job_position_announcements', 'announcement', 'job_position',
|
||||
string='Job Positions',help="Job Position's which want to see this announcement")
|
||||
announcement = fields.Html(string='Letter', states={'draft': [('readonly', False)]}, readonly=True, help="Announcement Content")
|
||||
date_start = fields.Date(string='Start Date', default=fields.Date.today(), required=True, help="Start date of "
|
||||
"announcement want"
|
||||
" to see")
|
||||
date_end = fields.Date(string='End Date', default=fields.Date.today(), required=True, help="End date of "
|
||||
"announcement want too"
|
||||
" see")
|
||||
|
||||
def reject(self):
|
||||
self.state = 'rejected'
|
||||
|
||||
def approve(self):
|
||||
self.state = 'approved'
|
||||
|
||||
def sent(self):
|
||||
self.state = 'to_approve'
|
||||
|
||||
@api.constrains('date_start', 'date_end')
|
||||
def validation(self):
|
||||
if self.date_start > self.date_end:
|
||||
raise ValidationError("Start date must be less than End Date")
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get('is_announcement'):
|
||||
vals['name'] = self.env['ir.sequence'].next_by_code('hr.announcement.general')
|
||||
else:
|
||||
vals['name'] = self.env['ir.sequence'].next_by_code('hr.announcement')
|
||||
return super(HrAnnouncementTable, self).create(vals)
|
||||
|
||||
def get_expiry_state(self):
|
||||
"""
|
||||
Function is used for Expiring Announcement based on expiry date
|
||||
it activate from the crone job.
|
||||
|
||||
"""
|
||||
now = datetime.now()
|
||||
now_date = now.date()
|
||||
ann_obj = self.search([('state', '!=', 'rejected')])
|
||||
for recd in ann_obj:
|
||||
if recd.date_end < now_date:
|
||||
recd.write({
|
||||
'state': 'expired'
|
||||
})
|
||||
Reference in New Issue
Block a user