Skip to content
Snippets Groups Projects
ur_month_timesheet.py 2.53 KiB
Newer Older
  • Learn to ignore specific revisions
  • # © 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)))
    
    
    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"
    
            return self.env["res.company"]._ur_default_get()
    
            selection=get_years(), string="Année", default=fields.Date.today().year
        )
        month = fields.Selection(selection=MONTHS, string="Mois")
    
            comodel_name="res.company",
            string="Société",
    
            default=lambda self: self.env.company,
    
            "union.regionale",
            string="Union Régionale",
    
            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),
                ],
    
                order="year desc, month desc",
            ).sorted(reverse=False)
    
                "month": month_values.mapped(
                    lambda x: {
                        "year": x.year,
                        "num_month": x.month,
    
                        "month": self._fields["month"].selection[int(x.month) - 1][1],
    
                    }
                ),
                "values": month_values.mapped("working_time"),
                "today": {
                    "year": fields.Date.today().year,
                    "month": fields.Date.today().month,
                },