From 90d7ac5a7a72f65d595b81bc4201cc62c64ec193 Mon Sep 17 00:00:00 2001 From: Benjamin <benjamin@le-filament.com> Date: Tue, 21 Apr 2020 18:06:36 +0200 Subject: [PATCH] [add] gestion du temps max d'imputation par UR --- __manifest__.py | 1 + models/__init__.py | 1 + models/hr_timesheet.py | 9 ++++++--- models/res_company.py | 18 ++++++++++++++++++ views/res_company.xml | 25 +++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 models/res_company.py create mode 100644 views/res_company.xml diff --git a/__manifest__.py b/__manifest__.py index 853bbdd..4549e14 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -22,6 +22,7 @@ "views/cgscop_timesheet_sheet.xml", "views/hr_timesheet.xml", "views/hr_timesheet_cgscop.xml", + "views/res_company.xml", "views/res_partner.xml", "views/ur_financial_system.xml", "views/ur_regional_convention.xml", diff --git a/models/__init__.py b/models/__init__.py index 15e2aa4..035a9fe 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -5,6 +5,7 @@ from . import cgscop_timesheet_code from . import cgscop_timesheet_sheet from . import hr_timesheet from . import project +from . import res_company from . import res_partner from . import ur_financial_system from . import ur_regional_convention diff --git a/models/hr_timesheet.py b/models/hr_timesheet.py index f9566a4..45ced85 100644 --- a/models/hr_timesheet.py +++ b/models/hr_timesheet.py @@ -105,10 +105,13 @@ class ScopHrTimesheet(models.Model): ('date', '=', record.date), ('employee_id', '=', record.employee_id.id)]) total = sum(lines.mapped('unit_amount')) - if total > 8: + if (not self.env.user.company_id.day_working + and total > self.env.user.company_id.day_duration): raise ValidationError( - "Vous ne pourvez imputer plus de 8h sur la même journée.\n" - "Journée du %s" % record.date.strftime("%d/%m/%Y")) + "Vous ne pourvez imputer plus de %sh sur la même journée.\n" + "Journée du %s" % ( + self.env.user.company_id.day_duration, + record.date.strftime("%d/%m/%Y"))) @api.constrains('date') def _check_weekday(self): diff --git a/models/res_company.py b/models/res_company.py new file mode 100644 index 0000000..7151932 --- /dev/null +++ b/models/res_company.py @@ -0,0 +1,18 @@ +# © 2019 Le Filament (<http://www.le-filament.com>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ResCompanyTmesheet(models.Model): + _inherit = "res.company" + + day_duration = fields.Float( + string='Nb Heures/Jour', + default=8, + help="Nombre d'heures max pour imputation") + day_working = fields.Boolean( + string='Forfait Jour', + default=False, + help='Si cette option est cochée, un employé peut imputer sans limite' + ' de temps sur une journée') diff --git a/views/res_company.xml b/views/res_company.xml new file mode 100644 index 0000000..6e353fe --- /dev/null +++ b/views/res_company.xml @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<!-- Copyright 2019 Le Filament + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> + +<odoo> + <data> + <record id="company_form_with_ur" model="ir.ui.view"> + <field name="name">scop.res.company.timesheet.form</field> + <field name="model">res.company</field> + <field name="inherit_id" ref="base.view_company_form"/> + <field name="arch" type="xml"> + <xpath expr="//notebook/page" position="after"> + <page name="company_timesheet" string="Feuilles de temps"> + <group> + <group string="Condiguration Imputations"> + <field name="day_working" widget="boolean_toggle"/> + <field name="day_duration" attrs="{'invisible': [('day_working', '=', True)]}"/> + </group> + </group> + </page> + </xpath> + </field> + </record> + </data> +</odoo> -- GitLab