Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# © 2019 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields, api
def get_years():
year_list = []
for i in range(2019, 2030):
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')]
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='Année')
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,
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.'
)]
@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
}
}