Field rest_days added.

This commit refs #27907
This commit is contained in:
Jorge Saura 2023-08-10 10:08:50 +02:00 committed by jm.pardo
parent bdcc194eec
commit bd131d7823
4 changed files with 54 additions and 22 deletions

View file

@ -95,9 +95,9 @@ msgctxt "field:staff.calendar,city:"
msgid "City"
msgstr "Ciudad"
msgctxt "field:staff.calendar,rest_day:"
msgid "Rest Day"
msgstr "Día de Descanso"
msgctxt "field:staff.calendar,rest_days:"
msgid "Rest Days"
msgstr "Días de Descanso"
msgctxt "field:staff.calendar,write_date:"
msgid "Write Date"
@ -235,35 +235,35 @@ msgctxt "model:staff.workplace,name:"
msgid "WorkPlace"
msgstr "Centro de empleo"
msgctxt "selection:staff.calendar,rest_day:"
msgctxt "selection:staff.calendar,rest_days:"
msgid "Monday"
msgstr "Lunes"
msgctxt "selection:staff.calendar,rest_day:"
msgctxt "selection:staff.calendar,rest_days:"
msgid "Tuesday"
msgstr "Martes"
msgctxt "selection:staff.calendar,rest_day:"
msgctxt "selection:staff.calendar,rest_days:"
msgid "Wednesday"
msgstr "Miércoles"
msgctxt "selection:staff.calendar,rest_day:"
msgctxt "selection:staff.calendar,rest_days:"
msgid "Thursday"
msgstr "Jueves"
msgctxt "selection:staff.calendar,rest_day:"
msgctxt "selection:staff.calendar,rest_days:"
msgid "Friday"
msgstr "Viernes"
msgctxt "selection:staff.calendar,rest_day:"
msgctxt "selection:staff.calendar,rest_days:"
msgid "Saturday"
msgstr "Sábado"
msgctxt "selection:staff.calendar,rest_day:"
msgctxt "selection:staff.calendar,rest_days:"
msgid "Sunday"
msgstr "Domingo"
msgctxt "selection:staff.calendar,rest_day:"
msgctxt "selection:staff.calendar,rest_days:"
msgid ""
msgstr ""

View file

@ -39,7 +39,7 @@ class StaffWorkplaceTestCase(ModuleTestCase):
party.save()
company = create_company()
calendar = Calendar(name='Calendar 1',
year=2016, rest_day='7')
year=2016, rest_days='7')
calendar.save()
workplace = Workplace(name='Workplace 1', code='WP1')
workplace.calendars = [calendar]

View file

@ -12,8 +12,9 @@
<field name="subdivision"/>
<label name="city"/>
<field name="city"/>
<label name="rest_day"/>
<field name="rest_day"/>
<newline/>
<label name="rest_days"/>
<field name="rest_days" yexpand="0"/>
<notebook>
<page string="Days" id="days" col="2">
<field name="days"/>

View file

@ -1,11 +1,15 @@
# The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from sql import Null
from trytond.model import ModelSQL, ModelView, fields
from trytond.model import Unique, DeactivableMixin
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
from trytond.exceptions import UserError
from trytond.i18n import gettext
from trytond.transaction import Transaction
from trytond import backend
class Calendar(ModelView, ModelSQL):
@ -21,27 +25,50 @@ class Calendar(ModelView, ModelSQL):
city = fields.Char('City')
days = fields.One2Many('staff.calendar.day', 'calendar', 'Days',
order=[('date_', 'ASC')])
rest_day = fields.Selection([
(None, ''),
rest_days = fields.MultiSelection([
('1', 'Monday'),
('2', 'Tuesday'),
('3', 'Wednesday'),
('4', 'Thursday'),
('5', 'Friday'),
('6', 'Saturday'),
('7', 'Sunday')], 'Rest Day', sort=False)
('7', 'Sunday')], 'Rest Days', sort=False)
@classmethod
def __register__(cls, module_name):
exist = backend.TableHandler.table_exist(cls._table)
table_sql = cls.__table_handler__(module_name)
field_exist = table_sql.column_exist('rest_days')
super().__register__(module_name)
table = cls.__table__()
if exist and not field_exist:
cursor = Transaction().connection.cursor()
cursor.execute(*table.select(
table.id,
table.rest_day,
where=(table.rest_day != Null)))
for id_, rest_day in cursor.fetchall():
value = cls.rest_days.sql_format([rest_day])
cursor.execute(*table.update(
columns=[table.rest_days],
values=[value],
where=table.id == id_))
table_sql.drop_column('rest_day')
@staticmethod
def default_rest_days():
return ['7']
def get_rec_name(self, name):
return str(self.name) + ' - ' + str(self.year)
@staticmethod
def default_rest_day():
return '7'
def date_type(self, date):
pool = Pool()
calendarDay = pool.get('staff.calendar.day')
if self.rest_day and date.isoweekday() == int(self.rest_day):
if self.rest_days and date.isoweekday() in self.rest_days_values:
return 'rest'
res = calendarDay.search_read([
('calendar', '=', self),
@ -50,6 +77,10 @@ class Calendar(ModelView, ModelSQL):
return res[0]['day_type']
return 'work'
@property
def rest_days_values(self):
return set(int(day) for day in self.rest_days)
class WorkPlace(DeactivableMixin, ModelView, ModelSQL):
"""WorkPlace"""