From 23b5605c414171a41a0ccfb7be8aefbb968d33e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 15 Nov 2013 02:27:28 +0100 Subject: [PATCH] Add timezone on company to compute today issue3444 review1411002 --- CHANGELOG | 2 ++ __init__.py | 1 + company.py | 26 ++++++++++++++++++++++++-- setup.py | 3 +++ view/company_form.xml | 6 ++++-- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b97ad05707..1a90f8bc88 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Add timezone on company to compute today + Version 3.0.0 - 2013-10-21 * Bug fixes (see mercurial logs for details) diff --git a/__init__.py b/__init__.py index 294bc15c1e..16ad20cc08 100644 --- a/__init__.py +++ b/__init__.py @@ -16,6 +16,7 @@ def register(): Property, Sequence, SequenceStrict, + Date, CompanyConfigStart, Cron, CronCompany, diff --git a/company.py b/company.py index a39897a531..4db74bcd65 100644 --- a/company.py +++ b/company.py @@ -8,9 +8,16 @@ from trytond.pyson import Eval, If from trytond.transaction import Transaction from trytond.pool import Pool, PoolMeta +try: + import pytz + TIMEZONES = [(x, x) for x in pytz.common_timezones] +except ImportError: + TIMEZONES = [] +TIMEZONES += [(None, '')] + __all__ = ['Company', 'Employee', 'UserEmployee', 'User', 'Property', - 'Sequence', 'SequenceStrict', 'CompanyConfigStart', 'CompanyConfig', - 'CompanyReport', 'LetterReport'] + 'Sequence', 'SequenceStrict', 'Date', 'CompanyConfigStart', + 'CompanyConfig', 'CompanyReport', 'LetterReport'] __metaclass__ = PoolMeta @@ -25,6 +32,7 @@ class Company(ModelSQL, ModelView): header = fields.Text('Header') footer = fields.Text('Footer') currency = fields.Many2One('currency.currency', 'Currency', required=True) + timezone = fields.Selection(TIMEZONES, 'Timezone', translate=False) employees = fields.One2Many('company.employee', 'company', 'Employees') @classmethod @@ -275,6 +283,20 @@ class SequenceStrict(Sequence): __name__ = 'ir.sequence.strict' +class Date: + __name__ = 'ir.date' + + @classmethod + def today(cls, timezone=None): + pool = Pool() + Company = pool.get('company.company') + company_id = Transaction().context.get('company') + if timezone is None and company_id: + company = Company(company_id) + timezone = pytz.timezone(company.timezone) + return super(Date, cls).today(timezone=timezone) + + class CompanyConfigStart(ModelView): 'Company Config' __name__ = 'company.company.config.start' diff --git a/setup.py b/setup.py index 750b6fd77a..2bda2394d6 100644 --- a/setup.py +++ b/setup.py @@ -74,6 +74,9 @@ setup(name='trytond_company', ], license='GPL-3', install_requires=requires, + extras_require={ + 'timezone': ['pytz'], + }, zip_safe=False, entry_points=""" [trytond.modules] diff --git a/view/company_form.xml b/view/company_form.xml index 8d93a26559..01b3858c47 100644 --- a/view/company_form.xml +++ b/view/company_form.xml @@ -1,12 +1,14 @@ -
+