Debian Codegraph @

addons/hr_timesheet/models/res_config_settings.py

raw
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 from odoo import api, fields, models
5
6
7 class ResConfigSettings(models.TransientModel):
8 _inherit = 'res.config.settings'
9
10 module_project_timesheet_holidays = fields.Boolean("Time Off",
11 compute="_compute_timesheet_modules", store=True, readonly=False)
12 reminder_user_allow = fields.Boolean(string="Employee Reminder")
13 reminder_allow = fields.Boolean(string="Approver Reminder")
14 project_time_mode_id = fields.Many2one(
15 'uom.uom', related='company_id.project_time_mode_id', string='Project Time Unit', readonly=False,
16 help="This will set the unit of measure used in projects and tasks.\n"
17 "If you use the timesheet linked to projects, don't "
18 "forget to setup the right unit of measure in your employees.")
19 is_encode_uom_days = fields.Boolean(compute='_compute_is_encode_uom_days', export_string_translation=False)
20 timesheet_encode_method = fields.Selection([
21 ('hours', 'Hours / Minutes'),
22 ('days', 'Days / Half-Days'),
23 ], string='Encoding Method', compute="_compute_timesheet_encode_method", inverse="_inverse_timesheet_encode_method", required=True)
24
25 @api.depends('company_id')
26 def _compute_timesheet_encode_method(self):
27 uom_day = self.env.ref('uom.product_uom_day', raise_if_not_found=False)
28 for settings in self:
29 settings.timesheet_encode_method = 'days' if settings.company_id.timesheet_encode_uom_id == uom_day else 'hours'
30
31 def _inverse_timesheet_encode_method(self):
32 uom_day = self.env.ref('uom.product_uom_day', raise_if_not_found=False)
33 uom_hour = self.env.ref('uom.product_uom_hour', raise_if_not_found=False)
34 for settings in self:
35 settings.company_id.timesheet_encode_uom_id = uom_day if settings.timesheet_encode_method == 'days' else uom_hour
36
37 @api.depends('timesheet_encode_method')
38 def _compute_is_encode_uom_days(self):
39 for settings in self:
40 settings.is_encode_uom_days = settings.timesheet_encode_method == 'days'
41
42 @api.depends('module_hr_timesheet')
43 def _compute_timesheet_modules(self):
44 self.filtered(lambda config: not config.module_hr_timesheet).update({
45 'module_project_timesheet_holidays': False,
46 })