diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/hr_timesheet/models/res_company.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/hr_timesheet/models/res_company.py')
| -rw-r--r-- | addons/hr_timesheet/models/res_company.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/addons/hr_timesheet/models/res_company.py b/addons/hr_timesheet/models/res_company.py new file mode 100644 index 00000000..429799ec --- /dev/null +++ b/addons/hr_timesheet/models/res_company.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, _ + + +class ResCompany(models.Model): + _inherit = 'res.company' + + @api.model + def _default_project_time_mode_id(self): + uom = self.env.ref('uom.product_uom_hour', raise_if_not_found=False) + wtime = self.env.ref('uom.uom_categ_wtime') + if not uom: + uom = self.env['uom.uom'].search([('category_id', '=', wtime.id), ('uom_type', '=', 'reference')], limit=1) + if not uom: + uom = self.env['uom.uom'].search([('category_id', '=', wtime.id)], limit=1) + return uom + + @api.model + def _default_timesheet_encode_uom_id(self): + uom = self.env.ref('uom.product_uom_hour', raise_if_not_found=False) + wtime = self.env.ref('uom.uom_categ_wtime') + if not uom: + uom = self.env['uom.uom'].search([('category_id', '=', wtime.id), ('uom_type', '=', 'reference')], limit=1) + if not uom: + uom = self.env['uom.uom'].search([('category_id', '=', wtime.id)], limit=1) + return uom + + project_time_mode_id = fields.Many2one('uom.uom', string='Project Time Unit', + default=_default_project_time_mode_id, + help="This will set the unit of measure used in projects and tasks.\n" + "If you use the timesheet linked to projects, don't " + "forget to setup the right unit of measure in your employees.") + timesheet_encode_uom_id = fields.Many2one('uom.uom', string="Timesheet Encoding Unit", + default=_default_timesheet_encode_uom_id, domain=lambda self: [('category_id', '=', self.env.ref('uom.uom_categ_wtime').id)], + help="""This will set the unit of measure used to encode timesheet. This will simply provide tools + and widgets to help the encoding. All reporting will still be expressed in hours (default value).""") + + @api.model_create_multi + def create(self, values): + company = super(ResCompany, self).create(values) + # use sudo as the user could have the right to create a company + # but not to create a project. On the other hand, when the company + # is created, it is not in the allowed_company_ids on the env + company.sudo()._create_internal_project_task() + return company + + def _create_internal_project_task(self): + results = [] + for company in self: + company = company.with_company(company) + internal_project = company.env['project.project'].sudo().create({ + 'name': _('Internal'), + 'allow_timesheets': True, + 'company_id': company.id, + }) + + company.env['project.task'].sudo().create([{ + 'name': _('Training'), + 'project_id': internal_project.id, + 'company_id': company.id, + }, { + 'name': _('Meeting'), + 'project_id': internal_project.id, + 'company_id': company.id, + }]) + results.append(internal_project) + return results |
