Add timezone on company to compute today

issue3444
review1411002
This commit is contained in:
Cédric Krier
2013-11-15 02:27:28 +01:00
parent 1f8804e2d9
commit 23b5605c41
5 changed files with 34 additions and 4 deletions
+2
View File
@@ -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)
+1
View File
@@ -16,6 +16,7 @@ def register():
Property,
Sequence,
SequenceStrict,
Date,
CompanyConfigStart,
Cron,
CronCompany,
+24 -2
View File
@@ -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'
+3
View File
@@ -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]
+4 -2
View File
@@ -1,12 +1,14 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<form string="Company">
<form string="Company" col="6">
<label name="party"/>
<field name="party"/>
<label name="currency"/>
<field name="currency"/>
<notebook colspan="4">
<label name="timezone"/>
<field name="timezone"/>
<notebook colspan="6">
<page string="Company" col="2" id="company">
<label name="parent"/>
<field name="parent"/>