Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: HR Timesheet Sheet

Entity: hr_timesheet.sheet

Compute Method: _compute_name

Inputs Method Outputs
locale = self.env.context.get("lang") or self.env.user.lang or "en_US"
for sheet in self:
            if not sheet.date_start or not sheet.date_end:
                raise UserError(sheet.env._("Please enter start and end date"))
            if sheet.date_start == sheet.date_end:
                sheet.name = babel.dates.format_skeleton(
                    skeleton="MMMEd",
                    datetime=datetime.combine(sheet.date_start, time.min),
                    locale=locale,
                )
                continue

            period_start = sheet.date_start.strftime("%V, %Y")
            period_end = sheet.date_end.strftime("%V, %Y")

            if sheet.date_end <= sheet.date_start + relativedelta(weekday=SU):
                sheet.name = sheet.env._("Week %(end)s", end=period_end)
            else:
                sheet.name = sheet.env._(
                    "Weeks %(start)s - %(end)s", start=period_start, end=period_end
                )

Back to entity