Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • ba0fd8e3c5953ab13abb3af455447ac61578bbdb
  • 12.0 par défaut protégée
  • 14-RV-20250312
  • 14-RV-20250305
  • 14-RV-20250129
  • 12-RV-Orthographe
6 résultats

ur_month_timesheet.py

Blame
  • Bifurcation depuis Le Filament / Confédération Générale des SCOP / cgscop_timesheet
    Le projet source a une visibilité limitée.
    ur_month_timesheet.py 2,54 Kio
    # © 2019 Le Filament (<http://www.le-filament.com>)
    # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
    
    from odoo import api, fields, models
    
    
    def get_years():
        year_list = []
        for i in range(2019, 2030):
            year_list.append((str(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"),
    ]
    
    
    class ScopMonthTimesheet(models.Model):
        _name = "ur.month.timesheet"
        _description = "Heures theoriques mensuelles"
        _order = "year, month"
    
        def _default_ur(self):
            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="Mois")
        company_id = fields.Many2one(
            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",
            index=True,
            ondelete="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.",
            )
        ]
    
        @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),
                ],
                limit=12,
                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,
                },
            }