From 78c1eb8721cad6f238486df6e4e67f21e278bca1 Mon Sep 17 00:00:00 2001 From: "pawan.sharma" Date: Wed, 10 Aug 2022 18:51:08 +0530 Subject: [PATCH] add timesheet block module with basic structure --- timesheet_block/__init__.py | 2 + timesheet_block/__manifest__.py | 20 +++++ timesheet_block/models/__init__.py | 2 + timesheet_block/models/res_config_settings.py | 11 +++ timesheet_block/models/timesheet.py | 81 +++++++++++++++++++ .../security/.~lock.ir.model.access.csv# | 1 + timesheet_block/security/ir.model.access.csv | 2 + timesheet_block/views/res_config_settings.xml | 45 +++++++++++ timesheet_block/views/timesheet.xml | 58 +++++++++++++ timesheet_block/wizard/__init__.py | 4 + timesheet_block/wizard/date_assign.py | 22 +++++ timesheet_block/wizard/date_assign.xml | 38 +++++++++ 12 files changed, 286 insertions(+) create mode 100755 timesheet_block/__init__.py create mode 100644 timesheet_block/__manifest__.py create mode 100755 timesheet_block/models/__init__.py create mode 100644 timesheet_block/models/res_config_settings.py create mode 100755 timesheet_block/models/timesheet.py create mode 100755 timesheet_block/security/.~lock.ir.model.access.csv# create mode 100755 timesheet_block/security/ir.model.access.csv create mode 100644 timesheet_block/views/res_config_settings.xml create mode 100755 timesheet_block/views/timesheet.xml create mode 100755 timesheet_block/wizard/__init__.py create mode 100755 timesheet_block/wizard/date_assign.py create mode 100755 timesheet_block/wizard/date_assign.xml diff --git a/timesheet_block/__init__.py b/timesheet_block/__init__.py new file mode 100755 index 0000000..c536983 --- /dev/null +++ b/timesheet_block/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard \ No newline at end of file diff --git a/timesheet_block/__manifest__.py b/timesheet_block/__manifest__.py new file mode 100644 index 0000000..f1baf81 --- /dev/null +++ b/timesheet_block/__manifest__.py @@ -0,0 +1,20 @@ +{ + 'name': 'Timesheet Block', + 'version': '1.0.1', + 'summary': 'This module is block to users to fill old timehseet entry', + 'description': 'This module is block to users to fill old timehseet entry', + 'category': 'Employee', + 'author': 'SunArc Technologies(Manish Bohra)', + 'website': 'www.sunarctechnologies.com', + 'license': 'LGPL-3', + 'depends': ['base','hr','hr_timesheet','project'], + 'data': [ + 'security/ir.model.access.csv', + 'wizard/date_assign.xml', + 'views/timesheet.xml', + 'views/res_config_settings.xml', + ], + 'installable': True, + 'auto_install': False, + +} \ No newline at end of file diff --git a/timesheet_block/models/__init__.py b/timesheet_block/models/__init__.py new file mode 100755 index 0000000..d357e7e --- /dev/null +++ b/timesheet_block/models/__init__.py @@ -0,0 +1,2 @@ +from . import timesheet +from . import res_config_settings \ No newline at end of file diff --git a/timesheet_block/models/res_config_settings.py b/timesheet_block/models/res_config_settings.py new file mode 100644 index 0000000..4ab38b0 --- /dev/null +++ b/timesheet_block/models/res_config_settings.py @@ -0,0 +1,11 @@ +from odoo import api, fields, models + +class ResConfigSettingsTimesheet(models.TransientModel): + _inherit = 'res.config.settings' + + timesheet_edit_create_limit = fields.Integer('No. of days',default=0, config_parameter='timesheet_block.timesheet_edit_create_limit') + + timesheet_edit_create_months = fields.Integer('No. of months',default=1, config_parameter='timesheet_block.timesheet_edit_create_months') + + + diff --git a/timesheet_block/models/timesheet.py b/timesheet_block/models/timesheet.py new file mode 100755 index 0000000..ea6c667 --- /dev/null +++ b/timesheet_block/models/timesheet.py @@ -0,0 +1,81 @@ +from odoo import api, fields, models +from odoo.exceptions import UserError, AccessError, ValidationError +from datetime import datetime +from dateutil import relativedelta + + +class EmployeeInherit(models.Model): + _inherit = 'hr.employee' + + allow_to_edit = fields.Selection(selection=[('always', 'Always'), ('specific', 'Specific')],string="Allow to edit",store=True) + allow_to_create = fields.Selection(selection=[('always', 'Always'), ('specific', 'Specific')] , store=True) + permission_history = fields.One2many(comodel_name="timesheet.block.history", inverse_name="employee_id", + string="History", required=False ) + + +class TimesheetBlock(models.Model): + _name = 'timesheet.block.history' + + date = fields.Date('Date') + permission_type = fields.Selection(string="Permission Type", selection=[('edit', 'Edit'), ('create', 'Create')], + required=False) + reason = fields.Text('Reason') + user_id = fields.Many2one('res.users', string='Given By') + employee_id = fields.Many2one(comodel_name="hr.employee", string="Employee", required=False) + + +class TimehseetBlock(models.Model): + _inherit = 'account.analytic.line' + + @api.model + def create(self, values): + current_date = datetime.today().date() + entry_date = datetime.strptime(values['date'], "%Y-%m-%d").date() + months_diff = current_date.month - entry_date.month + employee_object = self.env['hr.employee'].sudo().search([('user_id', '=', self.env.uid)]) + project_manager_group = self.env.ref('hr_timesheet.group_timesheet_manager') + config = self.env['ir.config_parameter'].sudo() + config_days_limit = float(config.get_param('timesheet_block.timesheet_edit_create_limit')) + if entry_date <= current_date: + if self.env.uid not in project_manager_group.users.ids: + if months_diff == 0: + res = super(TimehseetBlock, self).create(values) + elif months_diff == 1: + if employee_object.allow_to_create == 'always' and current_date.day <= config_days_limit: + res = super(TimehseetBlock, self).create(values) + else: + raise AccessError('You can not create your backdate entry please connect to Hr/Department Head') + else: + raise AccessError('You can not create your backdate entry please connect to Hr/Department Head') + else: + res = super(TimehseetBlock, self).create(values) + else: + raise AccessError('You can not create future entry') + return res + + + def write(self, values): + current_date = datetime.today().date() + if 'date' in values: + entry_date = datetime.strptime(values['date'], "%Y-%m-%d").date() + else: + res_date = str(self.date).split('.', 1)[0] + entry_date = datetime.strptime(str(res_date), '%Y-%m-%d %H:%M:%S').date() + months_diff = current_date.month - entry_date.month + employee_object = self.env['hr.employee'].sudo().search([('user_id', '=', self.env.uid)]) + project_manager_group = self.env.ref('hr_timesheet.group_timesheet_manager') + config = self.env['ir.config_parameter'].sudo() + config_days_limit = float(config.get_param('timesheet_block.timesheet_edit_create_limit')) + if self.env.uid not in project_manager_group.users.ids: + if months_diff == 0: + res = super(TimehseetBlock, self).write(values) + elif months_diff == 1: + if employee_object.allow_to_edit == 'always' and current_date.day <= config_days_limit: + res = super(TimehseetBlock, self).write(values) + else: + raise AccessError('You can not edit your backdate entry please connect to Hr/Department Head') + else: + raise AccessError('You can not edit your backdate entry please connect to Hr/Department Head') + else: + res = super(TimehseetBlock, self).write(values) + return res diff --git a/timesheet_block/security/.~lock.ir.model.access.csv# b/timesheet_block/security/.~lock.ir.model.access.csv# new file mode 100755 index 0000000..2c4b2d7 --- /dev/null +++ b/timesheet_block/security/.~lock.ir.model.access.csv# @@ -0,0 +1 @@ +,sunarcmanish,sunarcmanish,20.07.2020 23:42,file:///home/sunarcmanish/.config/libreoffice/4; \ No newline at end of file diff --git a/timesheet_block/security/ir.model.access.csv b/timesheet_block/security/ir.model.access.csv new file mode 100755 index 0000000..956ddad --- /dev/null +++ b/timesheet_block/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_timesheet_permission_history_user,access.timesheet.block.history.user,model_timesheet_block_history,,1,1,0,0 diff --git a/timesheet_block/views/res_config_settings.xml b/timesheet_block/views/res_config_settings.xml new file mode 100644 index 0000000..cc83bd6 --- /dev/null +++ b/timesheet_block/views/res_config_settings.xml @@ -0,0 +1,45 @@ + + + + res.config.settings.view.form.inherit.timesheet.block + res.config.settings + + + +
+

Timesheet Create/Edit Configuration

+
+
+ +
+
+
+
+
+
+
+
+
+
+ + + Timesheet Block Configuration + ir.actions.act_window + res.config.settings + + form + inline + {'module' : 'timesheet_block', 'bin_size': False} + + + + +
\ No newline at end of file diff --git a/timesheet_block/views/timesheet.xml b/timesheet_block/views/timesheet.xml new file mode 100755 index 0000000..72abff0 --- /dev/null +++ b/timesheet_block/views/timesheet.xml @@ -0,0 +1,58 @@ + + + + hr.employee.timesheet.block.inherit + hr.employee + + + + + + + + + + + + + +