diff --git a/__manifest__.py b/__manifest__.py index 6f5230c3378b8ad780052e18b3f8ede080e5c8bf..2a28761a974bc0ac440263dcc4f28db7ebedee3a 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -1,7 +1,7 @@ { "name": "CG SCOP - Feuille de temps", "summary": "CG SCOP - Feuille de temps", - "version": "12.0.1.2.0", + "version": "13.0.1.0.0", "development_status": "Production/Stable", "author": "Le Filament", "license": "AGPL-3", @@ -11,7 +11,7 @@ "analytic", "project", "cgscop_partner", - 'cgscop_fullcalendar', + "cgscop_fullcalendar", ], "data": [ "security/ir.model.access.csv", @@ -29,9 +29,9 @@ "report/report_hr_timesheet.xml", "datas/cgscop_timesheet_code_data.xml", ], - 'qweb': [ - 'static/src/xml/*.xml', + "qweb": [ + "static/src/xml/*.xml", ], "installable": True, - 'auto_install': False, + "auto_install": False, } diff --git a/models/__init__.py b/models/__init__.py index 92cffcb6e6c253460b413c48e7f75802c9ca0e6d..bbbee8bfda2c2be7af093135c0835b421804d753 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -10,4 +10,3 @@ from . import res_partner from . import ur_financial_system from . import ur_month_timesheet from . import ur_regional_convention - diff --git a/models/cgscop_timesheet_code.py b/models/cgscop_timesheet_code.py index 5a8a5185453567f4cf97452f5ae1c2a2bcfff66f..3d0437cb5b17cccaea6c1a9c21a37ad139177864 100644 --- a/models/cgscop_timesheet_code.py +++ b/models/cgscop_timesheet_code.py @@ -7,13 +7,16 @@ from odoo import models, fields class ScopTimesheetCode(models.Model): _name = "cgscop.timesheet.code" _description = "Code activité National" - _order = 'name' + _order = "name" - name = fields.Char('Nom') + name = fields.Char("Nom") domain = fields.Selection( - [('A', "Accompagnement"), - ('D', "Développement"), - ('F', "Formation"), - ('R', "Révision"), - ('Z', "Autre")], - string='Domaine') + [ + ("A", "Accompagnement"), + ("D", "Développement"), + ("F", "Formation"), + ("R", "Révision"), + ("Z", "Autre"), + ], + string="Domaine", + ) diff --git a/models/hr_timesheet.py b/models/hr_timesheet.py index c41b24719abe5704f7b2fa608005e4d15b97ae5e..e9a46ed292a15ea743ccdc9aec58f8571036e0b9 100644 --- a/models/hr_timesheet.py +++ b/models/hr_timesheet.py @@ -11,83 +11,89 @@ class ScopHrTimesheet(models.Model): _inherit = "account.analytic.line" def _default_ur(self): - return self.env['res.company']._ur_default_get() + return self.env["res.company"]._ur_default_get() # Inherited fields name = fields.Char(required=False) partner_id = fields.Many2one(required=True) - + # New fields cgscop_timesheet_code_id = fields.Many2one( - related='project_id.cgscop_timesheet_code_id', - string='Code Activité National', - store=True) + related="project_id.cgscop_timesheet_code_id", + string="Code Activité National", + store=True, + ) ur_financial_system_id = fields.Many2one( - comodel_name='ur.financial.system', - string='Dispositif Financier') + comodel_name="ur.financial.system", string="Dispositif Financier" + ) ur_regional_convention_id = fields.Many2one( - comodel_name='ur.regional.convention', - string='Convention Régionale') + comodel_name="ur.regional.convention", string="Convention Régionale" + ) ur_id = fields.Many2one( - 'union.regionale', - string='Union Régionale', + "union.regionale", + string="Union Régionale", index=True, - ondelete='restrict', - default=_default_ur) + ondelete="restrict", + default=_default_ur, + ) sheet_id = fields.Many2one( - comodel_name='cgscop.timesheet.sheet', + comodel_name="cgscop.timesheet.sheet", string="Feuille de temps", readonly=True, - copy=False) - state = fields.Selection([ - ('to_report', 'A rapporter'), - ('draft', 'Brouillon'), - ('submit', 'Soumis'), - ('valid', 'Validé')], - compute='_compute_state', - string='Statut', + copy=False, + ) + state = fields.Selection( + [ + ("to_report", "A rapporter"), + ("draft", "Brouillon"), + ("submit", "Soumis"), + ("valid", "Validé"), + ], + compute="_compute_state", + string="Statut", copy=False, index=True, readonly=True, - store=True,) + store=True, + ) ur_financial_system_nb = fields.Integer( - string="Nb Dispositifs Financiers", - compute="_compute_ur_system_nb") + string="Nb Dispositifs Financiers", compute="_compute_ur_system_nb" + ) ur_regional_convention_nb = fields.Integer( - string="Nb conventions régionales", - compute="_compute_ur_system_nb") + string="Nb conventions régionales", compute="_compute_ur_system_nb" + ) is_present = fields.Boolean("Présentiel") - justificatifs = fields.Char( - string="Justificatifs", - required=False) + justificatifs = fields.Char(string="Justificatifs", required=False) calendar_l1 = fields.Char( - string='Ligne 1 calendrier', - compute='_compute_calendar_l1', - store=False) + string="Ligne 1 calendrier", + compute="_compute_calendar_l1", + store=False, + ) calendar_l2 = fields.Char( - string='Ligne 2 calendrier', - compute='_compute_calendar_l2', - store=False) + string="Ligne 2 calendrier", + compute="_compute_calendar_l2", + store=False, + ) # ------------------------------------------------------ # Compute Functions # ------------------------------------------------------ - @api.depends('ur_id') + @api.depends("ur_id") def _compute_ur_system_nb(self): for timesheet in self: # Calcul nombre de dispositifs financiers - financial_system = timesheet.env['ur.financial.system'].search([ - ('ur_id', '=', timesheet.ur_id.id)]) - timesheet.ur_financial_system_nb = len( - financial_system) + financial_system = timesheet.env["ur.financial.system"].search( + [("ur_id", "=", timesheet.ur_id.id)] + ) + timesheet.ur_financial_system_nb = len(financial_system) # Calcul nombre de conventions - regional_convention = timesheet.env['ur.regional.convention'].search([ - ('ur_id', '=', timesheet.ur_id.id)]) - timesheet.ur_regional_convention_nb = len( - regional_convention) + regional_convention = timesheet.env[ + "ur.regional.convention" + ].search([("ur_id", "=", timesheet.ur_id.id)]) + timesheet.ur_regional_convention_nb = len(regional_convention) - @api.depends('sheet_id', 'sheet_id.state') + @api.depends("sheet_id", "sheet_id.state") def _compute_state(self): for timesheet in self: if not timesheet.sheet_id: @@ -95,16 +101,16 @@ class ScopHrTimesheet(models.Model): else: timesheet.state = timesheet.sheet_id.state - @api.depends('project_id', 'partner_id') + @api.depends("project_id", "partner_id") def _compute_calendar_l1(self): for ts in self: ts.calendar_l1 = "" if ts.project_id: - ts.calendar_l1 += ts.project_id.name + ', ' + ts.calendar_l1 += ts.project_id.name + ", " if ts.partner_id: ts.calendar_l1 += ts.partner_id.name - @api.depends('unit_amount') + @api.depends("unit_amount") def _compute_calendar_l2(self): for ts in self: ts.calendar_l2 = "Durée : " + str(ts.unit_amount) + " heure(s)" @@ -112,8 +118,7 @@ class ScopHrTimesheet(models.Model): # ------------------------------------------------------ # Override le _rec_name # ------------------------------------------------------ - @api.multi - @api.depends('project_id', 'partner_id') + @api.depends("project_id", "partner_id") def name_get(self): result = [] for ts in self: @@ -124,96 +129,116 @@ class ScopHrTimesheet(models.Model): # ------------------------------------------------------ # OnChange Functions # ------------------------------------------------------ - @api.onchange('project_id') + @api.onchange("project_id") def onchange_project_id(self): self.partner_id = self.project_id.partner_id - @api.onchange('partner_id') + @api.onchange("partner_id") def onchange_partner_id(self): # affiche le Dispositif Financier par défaut sur la LdT # si il n'y a pas de date limite du dispositif # ou si la date de la Ldt est inférieure à la date limite du dispositif - if not self.partner_id.ur_financial_system_date or \ - self.date <= self.partner_id.ur_financial_system_date: - self.ur_financial_system_id = self.partner_id.ur_financial_system_id + if ( + not self.partner_id.ur_financial_system_date + or self.date <= self.partner_id.ur_financial_system_date + ): + self.ur_financial_system_id = ( + self.partner_id.ur_financial_system_id + ) # affiche la Convention par défaut sur la LdT # si il n'y a pas de date limite de la convention # ou si la date de la LdT est inférieure à la date limite de la convention - if not self.partner_id.ur_regional_convention_date or \ - self.date <= self.partner_id.ur_regional_convention_date: - self.ur_regional_convention_id = self.partner_id.\ - ur_regional_convention_id + if ( + not self.partner_id.ur_regional_convention_date + or self.date <= self.partner_id.ur_regional_convention_date + ): + self.ur_regional_convention_id = ( + self.partner_id.ur_regional_convention_id + ) # ------------------------------------------------------ # Contrains # ------------------------------------------------------ - @api.constrains('unit_amount', 'date') + @api.constrains("unit_amount", "date") def _check_hours(self): for record in self: - lines = self.search([ - ('date', '=', record.date), - ('employee_id', '=', record.employee_id.id)]) - total = sum(lines.mapped('unit_amount')) - if (not self.env.user.company_id.day_working - and total > self.env.user.company_id.day_duration): + lines = self.search( + [ + ("date", "=", record.date), + ("employee_id", "=", record.employee_id.id), + ] + ) + total = sum(lines.mapped("unit_amount")) + if ( + not self.env.user.company_id.day_working + and total > self.env.user.company_id.day_duration + ): raise ValidationError( "Vous ne pouvez imputer plus de %sh sur la même journée.\n" - "Journée du %s" % ( + "Journée du %s" + % ( self.env.user.company_id.day_duration, - record.date.strftime("%d/%m/%Y"))) + record.date.strftime("%d/%m/%Y"), + ) + ) - @api.constrains('date') + @api.constrains("date") def _check_weekday(self): for line in self: dt = datetime.combine(line.date, time(12, 00)) - holiday = self.env['resource.calendar.leaves'].search([ - '|', - ('company_id', '=', False), - ('company_id', '=', self.env.user.company_id.id), - ('date_from', '<=', dt), - ('date_to', '>=', dt), - ]) + holiday = self.env["resource.calendar.leaves"].search( + [ + "|", + ("company_id", "=", False), + ("company_id", "=", self.env.user.company_id.id), + ("date_from", "<=", dt), + ("date_to", ">=", dt), + ] + ) if line.date.weekday() in (5, 6) or holiday: raise ValidationError( "Vous ne pouvez imputer du temps sur un weekend " - "ou un jour férié.") + "ou un jour férié." + ) # ------------------------------------------------------ # Override ORM # ------------------------------------------------------ - @api.multi def unlink(self): for timesheet in self: - if timesheet.state in ['submit', 'valid']: - raise UserError('Vous ne pouvez pas supprimer une ' - 'ligne de temps soumise ou validée') + if timesheet.state in ["submit", "valid"]: + raise UserError( + "Vous ne pouvez pas supprimer une " + "ligne de temps soumise ou validée" + ) super(ScopHrTimesheet, self).unlink() # ------------------------------------------------------ # Actions # ------------------------------------------------------ - @api.multi def action_submit_timesheet_lines(self): """ - Crée une feuille de temps avec les lignes sélectionnées + Crée une feuille de temps avec les lignes sélectionnées """ - if any(time.state != 'to_report' or time.sheet_id for time in self): + if any(time.state != "to_report" or time.sheet_id for time in self): raise UserError( - "Vous ne pouvez pas insérer 2 fois la même ligne !") - if len(self.mapped('employee_id')) != 1: + "Vous ne pouvez pas insérer 2 fois la même ligne !" + ) + if len(self.mapped("employee_id")) != 1: raise UserError( "Il ne peut y avoir plusieurs employés dans une " - "même feuille de temps.") + "même feuille de temps." + ) return { - 'name': 'New Expense Report', - 'type': 'ir.actions.act_window', - 'view_mode': 'form', - 'res_model': 'cgscop.timesheet.sheet', - 'target': 'current', - 'context': { - 'default_timesheet_line_ids': self.ids, - 'default_employee_id': self[0].employee_id.id, - 'default_name': self[0].name if len(self) == 1 else '' - } + "name": "New Expense Report", + "type": "ir.actions.act_window", + "view_mode": "form", + "res_model": "cgscop.timesheet.sheet", + "target": "current", + "context": { + "default_timesheet_line_ids": self.ids, + "default_employee_id": self[0].employee_id.id, + "default_name": self[0].name if len(self) == 1 else "", + }, } diff --git a/models/project.py b/models/project.py index d3850c72a8319fee6d6e2a634f6bb141d2ba65dc..e8e9fd818aaae2e67c25eec1d0764e21095b372c 100644 --- a/models/project.py +++ b/models/project.py @@ -8,23 +8,26 @@ class ScopProjectTimesheet(models.Model): _inherit = "project.project" def _default_ur(self): - return self.env['res.company']._ur_default_get() + return self.env["res.company"]._ur_default_get() cgscop_timesheet_code_id = fields.Many2one( - comodel_name='cgscop.timesheet.code', - string='Code Activité National') + comodel_name="cgscop.timesheet.code", string="Code Activité National" + ) privacy_visibility = fields.Selection(default="employees") ur_id = fields.Many2one( - 'union.regionale', - string='Union Régionale', + "union.regionale", + string="Union Régionale", index=True, - on_delete='restrict', - default=_default_ur) + on_delete="restrict", + default=_default_ur, + ) - @api.onchange('name') + @api.onchange("name") def onchange_name(self): analytic = self.analytic_account_id if analytic and analytic.ensure_one(): - self.analytic_account_id.sudo().write({ - 'name': self.name, - }) + self.analytic_account_id.sudo().write( + { + "name": self.name, + } + ) diff --git a/models/res_partner.py b/models/res_partner.py index 848ce9956b2edb580d4fe58c6b6641cc1d4d0afb..1322cb907053ecf7fa5f2393122bb6efdc738455 100644 --- a/models/res_partner.py +++ b/models/res_partner.py @@ -8,23 +8,23 @@ class ScopPartnerTimesheet(models.Model): _inherit = "res.partner" ur_financial_system_id = fields.Many2one( - comodel_name='ur.financial.system', - string='Dispositif Financier', - ondelete='set null') - ur_financial_system_date = fields.Date( - "Date de fin de dispositif") + comodel_name="ur.financial.system", + string="Dispositif Financier", + ondelete="set null", + ) + ur_financial_system_date = fields.Date("Date de fin de dispositif") ur_regional_convention_id = fields.Many2one( - comodel_name='ur.regional.convention', - string='Convention Régionale', - ondelete='set null') - ur_regional_convention_date = fields.Date( - "Date de fin de convention") + comodel_name="ur.regional.convention", + string="Convention Régionale", + ondelete="set null", + ) + ur_regional_convention_date = fields.Date("Date de fin de convention") ur_financial_system_nb = fields.Integer( - string="Nb Dispositifs Financiers", - compute="_compute_ur_system_nb") + string="Nb Dispositifs Financiers", compute="_compute_ur_system_nb" + ) ur_regional_convention_nb = fields.Integer( - string="Nb conventions régionales", - compute="_compute_ur_system_nb") + string="Nb conventions régionales", compute="_compute_ur_system_nb" + ) # ------------------------------------------------------ # Compute Functions @@ -32,12 +32,12 @@ class ScopPartnerTimesheet(models.Model): def _compute_ur_system_nb(self): for partner in self: # Calcul nombre de dispositifs financiers - financial_system = partner.env['ur.financial.system'].search([ - ('ur_id', '=', self.env.user.ur_id.id)]) - partner.ur_financial_system_nb = len( - financial_system) + financial_system = partner.env["ur.financial.system"].search( + [("ur_id", "=", self.env.user.ur_id.id)] + ) + partner.ur_financial_system_nb = len(financial_system) # Calcul nombre de conventions - regional_convention = partner.env['ur.regional.convention'].search([ - ('ur_id', '=', self.env.user.ur_id.id)]) - partner.ur_regional_convention_nb = len( - regional_convention) + regional_convention = partner.env["ur.regional.convention"].search( + [("ur_id", "=", self.env.user.ur_id.id)] + ) + partner.ur_regional_convention_nb = len(regional_convention) diff --git a/models/ur_financial_system.py b/models/ur_financial_system.py index a608e520916af59fdec01920f501f0b43bf70ef3..273e1257bdef980929883e404b446726e8db759b 100644 --- a/models/ur_financial_system.py +++ b/models/ur_financial_system.py @@ -9,16 +9,18 @@ class ScopTimesheetCode(models.Model): _description = "Dispositif financier UR" def _default_ur(self): - return self.env['res.company']._ur_default_get() + return self.env["res.company"]._ur_default_get() - name = fields.Char('Nom') + name = fields.Char("Nom") company_id = fields.Many2one( - comodel_name='res.company', - string='Société', - default=lambda self: self.env.user.company_id) + comodel_name="res.company", + string="Société", + default=lambda self: self.env.user.company_id, + ) ur_id = fields.Many2one( - 'union.regionale', - string='Union Régionale', + "union.regionale", + string="Union Régionale", index=True, - on_delete='restrict', - default=_default_ur) + on_delete="restrict", + default=_default_ur, + ) diff --git a/models/ur_month_timesheet.py b/models/ur_month_timesheet.py index 11f9c4df6392a0be2e8b31ddf6227692c67fa306..0dcf723be81f765164a0ec24d9582b136bccfcec 100644 --- a/models/ur_month_timesheet.py +++ b/models/ur_month_timesheet.py @@ -10,64 +10,85 @@ def get_years(): year_list.append((i, str(i))) return year_list -MONTHS = [(1, 'Janv'), (2, 'Fév'), (3, 'Mars'), (4, 'Avr'), - (5, 'Mai'), (6, 'Juin'), (7, 'Juil'), (8, 'Août'), - (9, 'Sept'), (10, 'Oct'), (11, 'Nov'), (12, 'Dec')] + +MONTHS = [ + (1, "Janv"), + (2, "Fév"), + (3, "Mars"), + (4, "Avr"), + (5, "Mai"), + (6, "Juin"), + (7, "Juil"), + (8, "Août"), + (9, "Sept"), + (10, "Oct"), + (11, "Nov"), + (12, "Dec"), +] class ScopMonthTimesheet(models.Model): _name = "ur.month.timesheet" _description = "Heures theoriques mensuelles" - _order = 'year, month' + _order = "year, month" def _default_ur(self): - return self.env['res.company']._ur_default_get() + return self.env["res.company"]._ur_default_get() year = fields.Selection( - selection=get_years(), - string='Année', - default=fields.Date.today().year) - month = fields.Selection( - selection=MONTHS, - string='Année') + selection=get_years(), string="Année", default=fields.Date.today().year + ) + month = fields.Selection(selection=MONTHS, string="Année") company_id = fields.Many2one( - comodel_name='res.company', - string='Société', - default=lambda self: self.env.user.company_id) + comodel_name="res.company", + string="Société", + default=lambda self: self.env.user.company_id, + ) ur_id = fields.Many2one( - 'union.regionale', - string='Union Régionale', + "union.regionale", + string="Union Régionale", index=True, - on_delete='restrict', - default=_default_ur) - working_time = fields.Integer('Heures théoriques') + on_delete="restrict", + default=_default_ur, + ) + working_time = fields.Integer("Heures théoriques") - _sql_constraints = [( - 'month_year_uniq', - 'UNIQUE (year, month, ur_id)', - 'Cette date a déjà été renseignée.' - )] + _sql_constraints = [ + ( + "month_year_uniq", + "UNIQUE (year, month, ur_id)", + "Cette date a déjà été renseignée.", + ) + ] @api.model def get_month_values(self): - month_values = self.search([ - '&', '|', '&', - ('year', '<', fields.Date.today().year), - ('month', '>', fields.Date.today().month), - '&', - ('year', '<', fields.Date.today().year + 1), - ('month', '<=', fields.Date.today().month + 1), - ('ur_id', '=', self.env.user.ur_id.id)], + month_values = self.search( + [ + "&", + "|", + "&", + ("year", "<", fields.Date.today().year), + ("month", ">", fields.Date.today().month), + "&", + ("year", "<", fields.Date.today().year + 1), + ("month", "<=", fields.Date.today().month + 1), + ("ur_id", "=", self.env.user.ur_id.id), + ], limit=12, - order='year desc, month desc').sorted(reverse=False) + order="year desc, month desc", + ).sorted(reverse=False) return { - 'month': month_values.mapped(lambda x: { - 'year': x.year, - 'num_month': x.month, - 'month': self._fields['month'].selection[x.month-1][1]}), - 'values': month_values.mapped('working_time'), - 'today': { - 'year': fields.Date.today().year, - 'month': fields.Date.today().month - } + "month": month_values.mapped( + lambda x: { + "year": x.year, + "num_month": x.month, + "month": self._fields["month"].selection[x.month - 1][1], + } + ), + "values": month_values.mapped("working_time"), + "today": { + "year": fields.Date.today().year, + "month": fields.Date.today().month, + }, } diff --git a/models/ur_regional_convention.py b/models/ur_regional_convention.py index 04a986cc5412335d8a67cf989e764ce2748c1763..3168d0d91952fe87666b413703d431c333fdd81d 100644 --- a/models/ur_regional_convention.py +++ b/models/ur_regional_convention.py @@ -9,16 +9,18 @@ class ScopRegionalConvention(models.Model): _description = "Convention Régionale UR" def _default_ur(self): - return self.env['res.company']._ur_default_get() + return self.env["res.company"]._ur_default_get() - name = fields.Char('Nom') + name = fields.Char("Nom") company_id = fields.Many2one( - comodel_name='res.company', - string='Société', - default=lambda self: self.env.user.company_id) + comodel_name="res.company", + string="Société", + default=lambda self: self.env.user.company_id, + ) ur_id = fields.Many2one( - 'union.regionale', - string='Union Régionale', + "union.regionale", + string="Union Régionale", index=True, - on_delete='restrict', - default=_default_ur) + on_delete="restrict", + default=_default_ur, + ) diff --git a/security/security_rules.xml b/security/security_rules.xml index 7a6b6382aefdac34edf78143f6ed7a7d0807b58f..c60f6013fe09e7b8dc036039ae489fc1c9eda877 100644 --- a/security/security_rules.xml +++ b/security/security_rules.xml @@ -3,7 +3,7 @@ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> <odoo> - <data noupdate="0"> + <data> <record id="ur_financial_system_rule_ur" model="ir.rule"> <field name="name">ur financial system rule per ur</field> diff --git a/views/hr_timesheet.xml b/views/hr_timesheet.xml index 1cffd342be4bedf1356a23e1e68b873b2e8c29d3..57b1f410ec42a50bcc98cd03f6932571f27e3fb2 100644 --- a/views/hr_timesheet.xml +++ b/views/hr_timesheet.xml @@ -3,7 +3,7 @@ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> <odoo> - <data noupdate="0"> + <data> <!-- Vues diff --git a/views/hr_timesheet_cgscop.xml b/views/hr_timesheet_cgscop.xml index 3a6aa23db8fb3608f0e7796f5d4917f6f9252d61..e2eeceb8996e2f85ca237d47e47ff625d59844f9 100644 --- a/views/hr_timesheet_cgscop.xml +++ b/views/hr_timesheet_cgscop.xml @@ -131,7 +131,6 @@ <record id="act_cgscop_project_timesheet" model="ir.actions.act_window"> <field name="name">Codes activités UR</field> <field name="res_model">project.project</field> - <field name="view_type">form</field> <field name="domain">[]</field> <field name="view_mode">tree,kanban,form</field> <field name="view_ids" eval="[(5, 0, 0),