From 587669578f49895fe0b4e8d5cde6a5c9905c32cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 1 Jan 2019 15:47:23 +0100 Subject: [PATCH] Add ir.calendar for month and day This allows to replace time_locale and use the translation infrastructure instead. So it can be customized using the translation override or derivative languages. This provides also a standard base to modules that needs calendar month and day. issue7815 review56451002 --- CHANGELOG | 2 ++ recurrence.py | 36 ++++++++++++++++++++++++----------- view/recurrence_rule_form.xml | 4 ++-- view/recurrence_rule_list.xml | 2 +- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f04534b846..7e5f09e6f0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Use ir.calendar.day + Version 5.0.0 - 2018-10-01 * Bug fixes (see mercurial logs for details) * Remove support for Python 2.7 diff --git a/recurrence.py b/recurrence.py index b595e43113..2b7dc324b4 100644 --- a/recurrence.py +++ b/recurrence.py @@ -6,6 +6,7 @@ from dateutil.rrule import rrule, rruleset from trytond.i18n import gettext from trytond.model import ModelSQL, ModelView, fields +from trytond.pool import Pool from trytond.transaction import Transaction from .exceptions import RecurrenceRuleValidationError @@ -90,19 +91,32 @@ class RecurrenceRule(ModelSQL, ModelView): bysetpos = fields.Char( "By Position", help="A comma separated list of integers.") - wkst = fields.Selection([ - (None, ''), - ('0', 'Monday'), - ('1', 'Tuesday'), - ('2', 'Wednesday'), - ('3', 'Thursday'), - ('4', 'Friday'), - ('5', 'Saturday'), - ('6', 'Sunday'), - ], "Week Start Day", sort=False) + week_start_day = fields.Many2One('ir.calendar.day', "Week Start Day") exclusive = fields.Boolean("Exclusive") + @classmethod + def __register__(cls, module_name): + pool = Pool() + Day = pool.get('ir.calendar.day') + day = Day.__table__() + transaction = Transaction() + table = cls.__table__() + + super().__register__(module_name) + table_h = cls.__table_handler__(module_name) + + # Migration from 5.0: replace wkst by week_start_day + if table_h.column_exist('wkst'): + cursor = transaction.connection.cursor() + update = transaction.connection.cursor() + cursor.execute(*day.select([day.id, day.index])) + for day_id, index in cursor: + update.execute(*table.update( + [table.week_start_day], [day_id], + where=table.wkst == str(index))) + table_h.drop_column('wkst') + @classmethod def default_interval(cls): return 1 @@ -125,7 +139,7 @@ class RecurrenceRule(ModelSQL, ModelView): 'byweekno': self._byweekno, 'bymonth': self._bymonth, 'bysetpos': self._bysetpos, - 'wkst': int(self.wkst) if self.wkst else None, + 'wkst': self.week_start_day.index if self.week_start_day else None, } @property diff --git a/view/recurrence_rule_form.xml b/view/recurrence_rule_form.xml index c265bd806b..e634b6ca70 100644 --- a/view/recurrence_rule_form.xml +++ b/view/recurrence_rule_form.xml @@ -24,6 +24,6 @@ this repository contains the full copyright notices and license terms. -->