add timesheet block module with basic structure

This commit is contained in:
pawan.sharma 2022-08-10 18:51:08 +05:30
parent 31ecdc8863
commit 78c1eb8721
12 changed files with 286 additions and 0 deletions

2
timesheet_block/__init__.py Executable file
View File

@ -0,0 +1,2 @@
from . import models
from . import wizard

View File

@ -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,
}

View File

@ -0,0 +1,2 @@
from . import timesheet
from . import res_config_settings

View File

@ -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')

View File

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

View File

@ -0,0 +1 @@
,sunarcmanish,sunarcmanish,20.07.2020 23:42,file:///home/sunarcmanish/.config/libreoffice/4;

View File

@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_timesheet_permission_history_user access.timesheet.block.history.user model_timesheet_block_history 1 1 0 0

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="res_config_settings_view_form_inherit_timesheet_block" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.timesheet.block</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="hr_timesheet.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='section_leaves']" position="after">
<div name="timesheet_block_limit" groups="base.group_no_one">
<h2>Timesheet Create/Edit Configuration </h2>
<div class="row mt16 o_settings_container" name="timesheet_control">
<div class="col-12 col-lg-6 o_setting_box" id="timesheet_block_validation_setting">
<div class="o_setting_right_pane">
<label for="timesheet_edit_create_limit"/>
<div >
<field name="timesheet_edit_create_limit"/>
</div>
</div>
<div class="o_setting_right_pane">
<label for="timesheet_edit_create_months"/>
<div >
<field name="timesheet_edit_create_months"/>
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
<record id="timesheet_block_settings_action" model="ir.actions.act_window">
<field name="name">Timesheet Block Configuration</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.config.settings</field>
<field name="view_id" ref="timesheet_block.res_config_settings_view_form_inherit_timesheet_block"/>
<field name="view_mode">form</field>
<field name="target">inline</field>
<field name="context">{'module' : 'timesheet_block', 'bin_size': False}</field>
</record>
</odoo>

View File

@ -0,0 +1,58 @@
<!-- Inherit Form View to Modify it -->
<odoo>
<record id="view_employee_form_timehseet_block" model="ir.ui.view">
<field name="name">hr.employee.timesheet.block.inherit</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='personal_information']" position="after">
<page name="'timehseet_block" string="Timesheet Block">
<group groups="hr.group_hr_manager">
<group>
<field name="allow_to_edit"/>
</group>
<group>
<field name="allow_to_create"/>
</group>
</group>
<button name="%(timesheet_block.action_back_date_assign)d" string="Assign Date"
type="action" groups="hr.group_hr_manager"
class="oe_highlight"/>
<group/>
<field name="permission_history" readonly="1">
<tree editable="bottom">
<field name="date"/>
<field name="reason"/>
<field name="permission_type"/>
<field name="user_id"
options="{'no_create': True, 'no_create_edit':True, 'no_open': True}"/>
<field name="employee_id" invisible="1"
options="{'no_create': True, 'no_create_edit':True, 'no_open': True}"/>
</tree>
<form>
<sheet>
<group>
<group>
<field name="date"/>
<field name="user_id"
options="{'no_create': True, 'no_create_edit':True, 'no_open': True}"/>
</group>
<group>
<field name="permission_type"/>
<field name="employee_id"
options="{'no_create': True, 'no_create_edit':True, 'no_open': True}"/>
</group>
</group>
<group>
<field name="reason"/>
</group>
</sheet>
</form>
</field>
</page>
</xpath>
</field>
</record>
</odoo>

View File

@ -0,0 +1,4 @@
from . import date_assign

View File

@ -0,0 +1,22 @@
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class ProjectCloseDate(models.TransientModel):
_name = "back.date.assign"
_description = "Timesheet Back Date Assign"
date = fields.Date('Date')
reason = fields.Text('Reason', required=True)
permission_type = fields.Selection(string="Permission Type", selection=[('edit', 'Edit'), ('create', 'Create')],
required=True)
def action_compute_project_close(self):
employee_obj = self.env['hr.employee'].browse(self._context.get('active_ids', []))
print("employee_obj", employee_obj)
employee_obj.permission_history.create({'employee_id': employee_obj.id,
'date': self.date,
'permission_type': self.permission_type,
'reason': self.reason,
'user_id': self.env.uid})

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_back_date_assign" model="ir.ui.view">
<field name="name">back.date.assign.from</field>
<field name="model">back.date.assign</field>
<field name="arch" type="xml">
<form string="Project Close">
<group>
<group>
<field name="date" required="1"/>
</group>
<group>
<field name="permission_type" required="1"/>
</group>
</group>
<group>
<field name="reason"/>
</group>
<footer>
<button string="OK" type="object" name="action_compute_project_close" class="btn-primary"/>
<button string="Cancel" class="btn-default" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_back_date_assign" model="ir.actions.act_window">
<field name="name">Timesheet Date Assign</field>
<!-- <field name="type">ir.actions.act_window</field>-->
<field name="res_model">back.date.assign</field>
<!-- <field name="view_type">form</field>-->
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>