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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/timesheet_block/wizard/__init__.py b/timesheet_block/wizard/__init__.py
new file mode 100755
index 0000000..e77c014
--- /dev/null
+++ b/timesheet_block/wizard/__init__.py
@@ -0,0 +1,4 @@
+from . import date_assign
+
+
+
diff --git a/timesheet_block/wizard/date_assign.py b/timesheet_block/wizard/date_assign.py
new file mode 100755
index 0000000..a885f80
--- /dev/null
+++ b/timesheet_block/wizard/date_assign.py
@@ -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})
diff --git a/timesheet_block/wizard/date_assign.xml b/timesheet_block/wizard/date_assign.xml
new file mode 100755
index 0000000..0506e37
--- /dev/null
+++ b/timesheet_block/wizard/date_assign.xml
@@ -0,0 +1,38 @@
+
+
+
+
+ back.date.assign.from
+ back.date.assign
+
+
+
+
+
+
+ Timesheet Date Assign
+
+ back.date.assign
+
+ form
+ new
+
+
+
+
\ No newline at end of file