Merge lp:~vauxoo/addons-vauxoo/7.0-addons-vauxoo-imp-datetime-dev-ernesto into lp:addons-vauxoo/7.0

Status: Merged
Merged at revision: 1161
Proposed branch: lp:~vauxoo/addons-vauxoo/7.0-addons-vauxoo-imp-datetime-dev-ernesto
Merge into: lp:addons-vauxoo/7.0
Diff against target: 520 lines (+264/-85)
6 files modified
invoice_datetime/__init__.py (+2/-2)
invoice_datetime/__openerp__.py (+22/-20)
invoice_datetime/invoice.py (+98/-53)
invoice_datetime/res_config.py (+26/-10)
invoice_datetime/tests/__init__.py (+27/-0)
invoice_datetime/tests/test_invoice_datetime.py (+89/-0)
To merge this branch: bzr merge lp:~vauxoo/addons-vauxoo/7.0-addons-vauxoo-imp-datetime-dev-ernesto

Description of the change

Se cambia el tipo de campo de function a datetime, se aplica la zona horaria del usuario antes de escribir o crear nuevo registro

To post a comment you must log in.
1116. By Luis Ernesto García Medina - http://www.vauxoo.com

[IMP][invoice_datetime] the time difference is improved by applying the time zone minutes

Revision history for this message
Jorge Angel Naranjo Rogel - http://www.vauxoo.com (jorge-nr) wrote :

@Wicho

De la linea 51-58 y de la 63-71 estamos repitiendo el código, lo mejor sería crear una función que reciba el datetime y si no viene sea False, y retorne el datetime en base al tz del usuario, este cambio nos puede ayudar a utilizar esa función para otros modelos y no solo para invoice.

Realiza ese ajuste y me informas cuando quede para poder generar los test yaml

review: Needs Fixing
1117. By Luis Ernesto García Medina - http://www.vauxoo.com

[IMP][invoice_datetime] use function _get_datetime_with_user_tz to get datetime of any field with user time zone

Revision history for this message
Jose Antonio Morales Ponce(vauxoo) - - http://www.vauxoo.com (josemoralesp) :
Revision history for this message
Jose Antonio Morales Ponce(vauxoo) - - http://www.vauxoo.com (josemoralesp) wrote :

The create method has an error because, you try to call a method and send the ids field and this field is not defined in our method

review: Needs Fixing
1118. By Luis Ernesto García Medina - http://www.vauxoo.com

[FIX][invoice_datetime] fixed error with "ids" variable is not available on function create

1119. By Luis Ernesto García Medina - http://www.vauxoo.com

[REF][invoice_datetime] validated that when field date is False, the function return False

1120. By Luis Ernesto García Medina - http://www.vauxoo.com

[REF][invoice_datetime] tests are added to validate that the date stored in the invoice corresponds to the date calculated in _get_datetime_with_user_tz function.

1121. By Luis Ernesto García Medina - http://www.vauxoo.com

[REF][invoice_datetime] change test to validate datetime with two time zones

1122. By Luis Ernesto García Medina - http://www.vauxoo.com

[Merge] merge with lp:addons-vauxoo/7.0

1123. By Jorge Angel Naranjo Rogel - http://www.vauxoo.com

[MERGE] Merge from lp:addons-vauxoo/7.0

1124. By Luis Ernesto García Medina - http://www.vauxoo.com

[MERGE] merge with lp:~vauxoo/addons-vauxoo/7.0-addons-vauxoo-pylint-datetime-dev-alan to apply pylint and flake8

1125. By Luis Ernesto García Medina - http://www.vauxoo.com

[FIX][invoice_datetime] fix errors with merge with parent

1126. By Luis Ernesto García Medina - http://www.vauxoo.com

[autopep8, pylint][invoice_datetime]

1127. By Luis Ernesto García Medina - http://www.vauxoo.com

[FIX][invoice_datetime] fix error with time of invoice

1128. By Luis Ernesto García Medina - http://www.vauxoo.com

[REF][invoice_datetime] applied flake8 and pylint

Revision history for this message
Jorge Angel Naranjo Rogel - http://www.vauxoo.com (jorge-nr) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'invoice_datetime/__init__.py'
--- invoice_datetime/__init__.py 2014-10-03 00:28:23 +0000
+++ invoice_datetime/__init__.py 2014-11-18 22:23:17 +0000
@@ -7,7 +7,8 @@
7# info Vauxoo (info@vauxoo.com)7# info Vauxoo (info@vauxoo.com)
8############################################################################8############################################################################
9# Coded by: moylop260 (moylop260@vauxoo.com)9# Coded by: moylop260 (moylop260@vauxoo.com)
10# Launchpad Project Manager for Publication: Nhomar Hernandez - nhomar@vauxoo.com10# Launchpad Project Manager for Publication:
11# Nhomar Hernandez - nhomar@vauxoo.com
11############################################################################12############################################################################
12#13#
13# This program is free software: you can redistribute it and/or modify14# This program is free software: you can redistribute it and/or modify
@@ -27,4 +28,3 @@
2728
28from . import invoice29from . import invoice
29from . import res_config30from . import res_config
30
3131
=== modified file 'invoice_datetime/__openerp__.py'
--- invoice_datetime/__openerp__.py 2014-10-03 08:22:36 +0000
+++ invoice_datetime/__openerp__.py 2014-11-18 22:23:17 +0000
@@ -6,8 +6,10 @@
6# All Rights Reserved.6# All Rights Reserved.
7# info Vauxoo (info@vauxoo.com)7# info Vauxoo (info@vauxoo.com)
8############################################################################8############################################################################
9# Coded by: moylop260 (moylop260@vauxoo.com) modified by carlosecv74@gmail.com9# Coded by: moylop260 (moylop260@vauxoo.com)
10# Launchpad Project Manager for Publication: Nhomar Hernandez - nhomar@vauxoo.com10# modified by carlosecv74@gmail.com
11# Launchpad Project Manager for Publication:
12# Nhomar Hernandez - nhomar@vauxoo.com
11############################################################################13############################################################################
12#14#
13# This program is free software: you can redistribute it and/or modify15# This program is free software: you can redistribute it and/or modify
@@ -25,28 +27,28 @@
25#27#
26##############################################################################28##############################################################################
27{29{
28 "name": "invoice_datetime", 30 "name": "invoice_datetime",
29 "version": "1.0", 31 "version": "1.0",
30 "author": "Vauxoo", 32 "author": "Vauxoo",
31 "category": "Localization/Mexico", 33 "category": "Localization/Mexico",
32 "description": """Add new field invoice_datetime for electronic invoice data34 "description": """Add new field invoice_datetime for electronic invoice data
33 and add hour & minute to field date_invoice35 and add hour & minute to field date_invoice
34 """, 36 """,
35 "website": "http://www.vauxoo.com/", 37 "website": "http://www.vauxoo.com/",
36 "license": "AGPL-3", 38 "license": "AGPL-3",
37 "depends": [39 "depends": [
38 "account"40 "account"
39 ], 41 ],
40 "demo": [], 42 "demo": [],
41 "data": [43 "data": [
42 "account_invoice_view.xml", 44 "account_invoice_view.xml",
43 "res_config_acc_view.xml"45 "res_config_acc_view.xml"
44 ], 46 ],
45 "test": [], 47 "test": [],
46 "js": [], 48 "js": [],
47 "css": [], 49 "css": [],
48 "qweb": [], 50 "qweb": [],
49 "installable": True, 51 "installable": True,
50 "auto_install": False, 52 "auto_install": False,
51 "active": False53 "active": False
52}
53\ No newline at end of file54\ No newline at end of file
55}
5456
=== modified file 'invoice_datetime/invoice.py'
--- invoice_datetime/invoice.py 2014-11-05 16:41:06 +0000
+++ invoice_datetime/invoice.py 2014-11-18 22:23:17 +0000
@@ -7,7 +7,8 @@
7# info Vauxoo (info@vauxoo.com)7# info Vauxoo (info@vauxoo.com)
8############################################################################8############################################################################
9# Coded by: moylop260 (moylop260@vauxoo.com)9# Coded by: moylop260 (moylop260@vauxoo.com)
10# Launchpad Project Manager for Publication: Nhomar Hernandez - nhomar@vauxoo.com10# Launchpad Project Manager for Publication:
11# * Nhomar Hernandez - nhomar@vauxoo.com
11############################################################################12############################################################################
12#13#
13# This program is free software: you can redistribute it and/or modify14# This program is free software: you can redistribute it and/or modify
@@ -28,8 +29,8 @@
28from openerp.osv import fields, osv29from openerp.osv import fields, osv
29from openerp.tools.translate import _30from openerp.tools.translate import _
30from openerp import tools31from openerp import tools
31from openerp import release
32import datetime32import datetime
33from datetime import timedelta
33from pytz import timezone34from pytz import timezone
34import pytz35import pytz
35import time36import time
@@ -47,61 +48,94 @@
47 date_ref, '%Y-%m-%d %H:%M:%S'))48 date_ref, '%Y-%m-%d %H:%M:%S'))
48 except BaseException:49 except BaseException:
49 pass50 pass
50 return super(account_payment_term, self).compute(cr, uid, ids, value,51 return super(account_payment_term, self).compute(
51 date_ref, context=context)52 cr, uid, ids, value, date_ref, context=context)
5253
5354
54class account_invoice(osv.Model):55class account_invoice(osv.Model):
55 _inherit = 'account.invoice'56 _inherit = 'account.invoice'
56 #_order = 'invoice_datetime asc'57 # _order = 'invoice_datetime asc'
57
58 def _get_date_invoice_tz(self, cr, uid, ids, field_names=None, arg=False, context=None):
59 if context is None:
60 context = {}
61 res = {}
62 if release.version >= '6':
63 tz = self.pool.get('res.users').browse(cr, uid, uid).tz
64 for invoice in self.browse(cr, uid, ids, context=context):
65 res[invoice.id] = invoice.invoice_datetime and tools.\
66 server_to_local_timestamp(invoice.invoice_datetime,
67 tools.DEFAULT_SERVER_DATETIME_FORMAT,
68 tools.DEFAULT_SERVER_DATETIME_FORMAT, tz) or False
69 elif release.version < '6':
70 # TODO: tz change for openerp5
71 for invoice in self.browse(cr, uid, ids, context=context):
72 res[invoice.id] = invoice.date_invoice
73 return res
7458
75 def _get_field_params(self, cr, uid, ids, name, unknow_none, context=None):59 def _get_field_params(self, cr, uid, ids, name, unknow_none, context=None):
76 if context is None:60 if context is None:
77 context = {}61 context = {}
62 account_setting_obj = self.pool.get("account.config.settings")
78 ids = isinstance(ids, (int, long)) and [ids] or ids63 ids = isinstance(ids, (int, long)) and [ids] or ids
79 res = {}64 res = {}
80 key_by_company_id = "acc_invoice.date_invoice_type_" + str(self.pool.get("account.config.settings")._default_company(cr, uid))65 key_by_company_id = "acc_invoice.date_invoice_type_" + \
81 res[ids[0]] = self.pool.get("ir.config_parameter").get_param(cr, uid, key_by_company_id, default='date', context=context)66 str(account_setting_obj._default_company(cr, uid))
67 res[ids[0]] = self.pool.get("ir.config_parameter").get_param(
68 cr, uid, key_by_company_id, default='date', context=context)
82 return res69 return res
8370
84 _columns = {71 _columns = {
85 # Extract date_invoice from original, but add datetime72 # Extract date_invoice from original, but add datetime
86 #'date_invoice': fields.datetime('Date Invoiced', states={'open':[73 # 'date_invoice': fields.datetime('Date Invoiced', states={'open':[
87 #('readonly',True)],'close':[('readonly',True)]},74 # ('readonly',True)],'close':[('readonly',True)]},
88 # help="Keep empty to use the current date"),75 # help="Keep empty to use the current date"),
89 'invoice_datetime': fields.datetime('Date time of invoice',76 'invoice_datetime': fields.datetime(
90 states={'open': [('readonly', True)], 'close': [('readonly', True)]},77 'Date time of invoice',
78 states={
79 'open': [('readonly', True)],
80 'close': [('readonly', True)]},
91 help="Keep empty to use the current date"),81 help="Keep empty to use the current date"),
92 'date_invoice_tz': fields.function(_get_date_invoice_tz, method=True,82 'date_invoice_tz': fields.datetime(
93 type='datetime', string='Date Invoiced with TZ', store=True,83 string='Date Invoiced with TZ',
94 help='Date of Invoice with Time Zone'),84 help='Date of Invoice with Time Zone'),
95 'date_type': fields.function(_get_field_params, storage=False, type='char', string="Date type")85 'date_type': fields.function(_get_field_params, storage=False,
86 type='char', string="Date type")
96 }87 }
9788
89 def _get_datetime_with_user_tz(self, cr, uid, datetime_invoice=False,
90 context=None):
91 datetime_inv_tz = False
92 if datetime_invoice:
93 time_tz = self.pool.get("res.users").read(
94 cr, uid, uid, ["tz_offset"], context=context).get("tz_offset")
95 hours_tz = int(time_tz[:-2])
96 minut_tz = int(time_tz[-2:])
97 if time_tz[0] == '-':
98 minut_tz = minut_tz * -1
99 datetime_inv_tz = (
100 datetime_invoice + timedelta(
101 hours=hours_tz,
102 minutes=minut_tz)).strftime('%Y-%m-%d %H:%M:%S')
103 return datetime_inv_tz
104
105 def create(self, cr, uid, vals, context=None):
106 if 'invoice_datetime' in vals.keys():
107 datetime_inv = vals.get("invoice_datetime") and \
108 datetime.datetime.strptime(
109 vals.get("invoice_datetime"), "%Y-%m-%d %H:%M:%S") or False
110 if datetime_inv:
111 vals.update(
112 {'date_invoice_tz': self._get_datetime_with_user_tz(
113 cr, uid, datetime_inv)})
114 return super(account_invoice, self).create(
115 cr, uid, vals, context=context)
116
117 def write(self, cr, uid, ids, vals, context=None):
118 for invoice in self.browse(cr, uid, ids, context=context):
119 datetime_inv = invoice.invoice_datetime and \
120 datetime.datetime.strptime(invoice.invoice_datetime,
121 "%Y-%m-%d %H:%M:%S") or False
122 if datetime_inv:
123 vals.update(
124 {'date_invoice_tz': self._get_datetime_with_user_tz(
125 cr, uid, datetime_inv)})
126 return super(account_invoice, self).write(
127 cr, uid, ids, vals, context=context)
128
98 def _get_default_type(self, cr, uid, ids):129 def _get_default_type(self, cr, uid, ids):
99 key_by_company_id = "acc_invoice.date_invoice_type_" + str(self.pool.get("account.config.settings")._default_company(cr, uid))130 account_setting_obj = self.pool.get("account.config.settings")
100 type_show_date = self.pool.get("ir.config_parameter").get_param(cr, uid, key_by_company_id, default='date')131 key_by_company_id = "acc_invoice.date_invoice_type_" + \
132 str(account_setting_obj._default_company(cr, uid))
133 type_show_date = self.pool.get("ir.config_parameter").get_param(
134 cr, uid, key_by_company_id, default='date')
101 return type_show_date135 return type_show_date
102136
103 _defaults = {137 _defaults = {
104 #'date_invoice': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),138 # 'date_invoice': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
105 "date_type": _get_default_type139 "date_type": _get_default_type
106 }140 }
107141
@@ -111,7 +145,8 @@
111 if default is None:145 if default is None:
112 default = {}146 default = {}
113 default.update({'invoice_datetime': False, 'date_invoice': False})147 default.update({'invoice_datetime': False, 'date_invoice': False})
114 return super(account_invoice, self).copy(cr, uid, ids, default, context)148 return super(account_invoice, self).copy(
149 cr, uid, ids, default, context)
115150
116 def _get_time_zone(self, cr, uid, invoice_id, context=None):151 def _get_time_zone(self, cr, uid, invoice_id, context=None):
117 if context is None:152 if context is None:
@@ -123,8 +158,9 @@
123 hours = timezone(userstz)158 hours = timezone(userstz)
124 fmt = '%Y-%m-%d %H:%M:%S %Z%z'159 fmt = '%Y-%m-%d %H:%M:%S %Z%z'
125 now = datetime.datetime.now()160 now = datetime.datetime.now()
126 loc_dt = hours.localize(datetime.datetime(now.year, now.month, now.day,161 loc_dt = hours.localize(datetime.datetime(now.year, now.month,
127 now.hour, now.minute, now.second))162 now.day, now.hour,
163 now.minute, now.second))
128 timezone_loc = (loc_dt.strftime(fmt))164 timezone_loc = (loc_dt.strftime(fmt))
129 diff_timezone_original = timezone_loc[-5:-2]165 diff_timezone_original = timezone_loc[-5:-2]
130 timezone_original = int(diff_timezone_original)166 timezone_original = int(diff_timezone_original)
@@ -155,9 +191,10 @@
155191
156 if values.get('invoice_datetime', False) and not\192 if values.get('invoice_datetime', False) and not\
157 values.get('date_invoice', False):193 values.get('date_invoice', False):
158 date_invoice = fields.datetime.context_timestamp(cr, uid,194 date_invoice = fields.datetime.context_timestamp(
159 datetime.datetime.strptime(values['invoice_datetime'],195 cr, uid, datetime.datetime.strptime(
160 tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context)196 values['invoice_datetime'],
197 tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context)
161 res['date_invoice'] = date_invoice198 res['date_invoice'] = date_invoice
162 res['invoice_datetime'] = values['invoice_datetime']199 res['invoice_datetime'] = values['invoice_datetime']
163200
@@ -168,31 +205,39 @@
168 '%Y-%m-%d %H:%M:%S').date().strftime('%Y-%m-%d')205 '%Y-%m-%d %H:%M:%S').date().strftime('%Y-%m-%d')
169 if date_invoice != values['date_invoice']:206 if date_invoice != values['date_invoice']:
170 if self.browse(cr, uid, ids)[0].date_type == 'datetime':207 if self.browse(cr, uid, ids)[0].date_type == 'datetime':
171 date_invoice = fields.datetime.context_timestamp(cr, uid,208 date_invoice = fields.datetime.context_timestamp(
172 datetime.datetime.strptime(values['invoice_datetime'],209 cr, uid, datetime.datetime.strptime(
173 tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context)210 values['invoice_datetime'],
211 tools.DEFAULT_SERVER_DATETIME_FORMAT),
212 context=context)
174 res['date_invoice'] = date_invoice213 res['date_invoice'] = date_invoice
175 res['invoice_datetime'] = values['invoice_datetime']214 res['invoice_datetime'] = values['invoice_datetime']
176 elif self.browse(cr, uid, ids)[0].date_type == 'date':215 elif self.browse(cr, uid, ids)[0].date_type == 'date':
177 user_hour = self._get_time_zone(cr, uid, [], context=context)216 user_hour = self._get_time_zone(
217 cr, uid, [], context=context)
178 time_invoice = datetime.time(abs(user_hour), 0, 0)218 time_invoice = datetime.time(abs(user_hour), 0, 0)
179219
180 date_invoice = datetime.datetime.strptime(220 date_invoice = datetime.datetime.strptime(
181 values['date_invoice'], '%Y-%m-%d').date()221 values['date_invoice'], '%Y-%m-%d').date()
182222
183 dt_invoice = datetime.datetime.combine(223 dt_invoice = datetime.datetime.combine(
184 date_invoice, time_invoice).strftime('%Y-%m-%d %H:%M:%S')224 date_invoice,
225 time_invoice).strftime('%Y-%m-%d %H:%M:%S')
185226
186 res['invoice_datetime'] = dt_invoice227 res['invoice_datetime'] = dt_invoice
187 res['date_invoice'] = values['date_invoice']228 res['date_invoice'] = values['date_invoice']
188 else:229 else:
189 raise osv.except_osv(_('Warning!'), _('Invoice dates should be equal'))230 raise osv.except_osv(
190 #~ else:231 _('Warning!'),
191 #~ raise osv.except_osv(_('Warning!'), _('Invoice dates should be equal'))232 _('Invoice dates should be equal'))
233 # ~ else:
234 # ~ raise osv.except_osv(_('Warning!'),
235 # _('Invoice dates should be equal'))
192236
193 if not values.get('invoice_datetime', False) and\237 if not values.get('invoice_datetime', False) and\
194 not values.get('date_invoice', False):238 not values.get('date_invoice', False):
195 res['date_invoice'] = fields.date.context_today(self, cr, uid, context=context)239 res['date_invoice'] = fields.date.context_today(
240 self, cr, uid, context=context)
196 res['invoice_datetime'] = fields.datetime.now()241 res['invoice_datetime'] = fields.datetime.now()
197242
198 return res243 return res
@@ -200,9 +245,9 @@
200 def action_move_create(self, cr, uid, ids, context=None):245 def action_move_create(self, cr, uid, ids, context=None):
201 for inv in self.browse(cr, uid, ids, context=context):246 for inv in self.browse(cr, uid, ids, context=context):
202 if inv.type in ('out_invoice', 'out_refund'):247 if inv.type in ('out_invoice', 'out_refund'):
203 vals_date = self.assigned_datetime(cr, uid, ids,248 vals_date = self.assigned_datetime(
204 {'invoice_datetime': inv.invoice_datetime,249 cr, uid, ids, {'invoice_datetime': inv.invoice_datetime,
205 'date_invoice': inv.date_invoice},250 'date_invoice': inv.date_invoice},
206 context=context)251 context=context)
207 self.write(cr, uid, ids, vals_date, context=context)252 self.write(cr, uid, ids, vals_date, context=context)
208 return super(account_invoice,253 return super(account_invoice,
209254
=== modified file 'invoice_datetime/res_config.py'
--- invoice_datetime/res_config.py 2014-10-03 07:19:35 +0000
+++ invoice_datetime/res_config.py 2014-11-18 22:23:17 +0000
@@ -31,29 +31,45 @@
3131
32 _columns = {32 _columns = {
33 'groups_id': fields.many2one('res.groups', 'Category',),33 'groups_id': fields.many2one('res.groups', 'Category',),
34 'select_date': fields.selection([('date', 'Date'), ('datetime', 'Datetime')], string="Default date of invoices", help="Select the field you want to displayed in the invoice for the selected company."),34 'select_date': fields.selection([('date', 'Date'), (
35 'datetime', 'Datetime')],
36 string="Default date of invoices",
37 help="Select the field you want to displayed in the \
38 invoice for the selected company."),
35 }39 }
3640
37 def get_default_select_date(self, cr, uid, fields_name, context=None):41 def get_default_select_date(self, cr, uid, fields_name, context=None):
38 key_by_company_id = "acc_invoice.date_invoice_type_" + str(self._default_company(cr, uid))42 key_by_company_id = "acc_invoice.date_invoice_type_" + str(
39 type_show_date = self.pool.get("ir.config_parameter").get_param(cr, uid, key_by_company_id, default='date', context=context)43 self._default_company(cr, uid))
44 type_show_date = self.pool.get("ir.config_parameter").get_param(
45 cr, uid, key_by_company_id, default='date', context=context)
40 return {'select_date': type_show_date}46 return {'select_date': type_show_date}
4147
42 def set_default_select_date(self, cr, uid, ids, context=None):48 def set_default_select_date(self, cr, uid, ids, context=None):
43 """ set default sale and purchase taxes for products """49 """ set default sale and purchase taxes for products """
44 if uid != SUPERUSER_ID and not self.pool['res.users'].has_group(cr, uid, 'base.group_erp_manager'):50 if uid != SUPERUSER_ID and not self.pool['res.users'].has_group(
45 raise openerp.exceptions.AccessError(_("Only administrators can change the settings"))51 cr, uid, 'base.group_erp_manager'):
52 raise openerp.exceptions.AccessError(
53 _("Only administrators can change the settings"))
46 config_parameters = self.pool.get("ir.config_parameter")54 config_parameters = self.pool.get("ir.config_parameter")
47 for record in self.browse(cr, uid, ids, context=context):55 for record in self.browse(cr, uid, ids, context=context):
48 company_id = str(record.company_id and record.company_id.id or self._default_company(cr, uid))56 company_id = str(record.company_id and
57 record.company_id.id or
58 self._default_company(cr, uid))
49 key_by_company_id = "acc_invoice.date_invoice_type_" + company_id59 key_by_company_id = "acc_invoice.date_invoice_type_" + company_id
50 config_parameters.set_param(cr, uid, key_by_company_id, record.select_date or '', context=context)60 config_parameters.set_param(
61 cr, uid, key_by_company_id, record.select_date or '',
62 context=context)
5163
52 def onchange_company_id(self, cr, uid, ids, company_id, context=None):64 def onchange_company_id(self, cr, uid, ids, company_id, context=None):
53 result = super(account_config_settings, self).onchange_company_id(cr, uid, ids, company_id, context=context)65 result = super(account_config_settings, self).onchange_company_id(
66 cr, uid, ids, company_id, context=context)
54 type_date = False67 type_date = False
55 type_date = result.get('value', {})68 type_date = result.get('value', {})
56 key_by_company_id = "acc_invoice.date_invoice_type_" + str(company_id or self._default_company(cr, uid))69 key_by_company_id = "acc_invoice.date_invoice_type_" + str(
57 type_date['select_date'] = self.pool.get("ir.config_parameter").get_param(cr, uid, key_by_company_id, default='date', context=context)70 company_id or self._default_company(cr, uid))
71 type_date['select_date'] = self.pool.get(
72 "ir.config_parameter").get_param(
73 cr, uid, key_by_company_id, default='date', context=context)
58 result.update({'value': type_date})74 result.update({'value': type_date})
59 return result75 return result
6076
=== added directory 'invoice_datetime/tests'
=== added file 'invoice_datetime/tests/__init__.py'
--- invoice_datetime/tests/__init__.py 1970-01-01 00:00:00 +0000
+++ invoice_datetime/tests/__init__.py 2014-11-18 22:23:17 +0000
@@ -0,0 +1,27 @@
1#!/usr/bin/python
2# -*- encoding: utf-8 -*-
3#
4# Module Writen to OpenERP, Open Source Management Solution
5#
6# Copyright (c) 2014 Vauxoo - http://www.vauxoo.com/
7# All Rights Reserved.
8# info Vauxoo (info@vauxoo.com)
9#
10# Coded by: vauxoo consultores (info@vauxoo.com)
11#
12#
13# This program is free software: you can redistribute it and/or modify
14# it under the terms of the GNU Affero General Public License as
15# published by the Free Software Foundation, either version 3 of the
16# License, or (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU Affero General Public License for more details.
22#
23# You should have received a copy of the GNU Affero General Public License
24# along with this program. If not, see <http://www.gnu.org/licenses/>.
25#
26
27from . import test_invoice_datetime
028
=== added file 'invoice_datetime/tests/test_invoice_datetime.py'
--- invoice_datetime/tests/test_invoice_datetime.py 1970-01-01 00:00:00 +0000
+++ invoice_datetime/tests/test_invoice_datetime.py 2014-11-18 22:23:17 +0000
@@ -0,0 +1,89 @@
1#!/usr/bin/python
2# -*- encoding: utf-8 -*-
3#
4# Module Writen to OpenERP, Open Source Management Solution
5#
6# Copyright (c) 2014 Vauxoo - http://www.vauxoo.com/
7# All Rights Reserved.
8# info Vauxoo (info@vauxoo.com)
9#
10# Coded by: vauxoo consultores (info@vauxoo.com)
11#
12#
13# This program is free software: you can redistribute it and/or modify
14# it under the terms of the GNU Affero General Public License as
15# published by the Free Software Foundation, either version 3 of the
16# License, or (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU Affero General Public License for more details.
22#
23# You should have received a copy of the GNU Affero General Public License
24# along with this program. If not, see <http://www.gnu.org/licenses/>.
25#
26
27from openerp.tests.common import TransactionCase
28from openerp.tools import mute_logger
29import time
30import datetime
31import logging
32_logger = logging.getLogger(__name__)
33
34
35class TestInvoiceDatetime(TransactionCase):
36 def setUp(self):
37 super(TestInvoiceDatetime, self).setUp()
38 self.user = self.registry('res.users')
39 self.data = self.registry('ir.model.data')
40 self.invoice = self.registry('account.invoice')
41
42 @mute_logger('openerp.addons.base.ir.ir_model', 'openerp.osv.orm')
43 def test_get_datetime(self):
44 cr, uid = self.cr, self.uid
45 # get datetime of server in string
46 dt_server = time.strftime('%Y-%m-%d %H:%M:%S')
47 # I generate object of type datetime
48 # to send at function _get_datetime_with_user_tz
49 datetime_object = datetime.datetime.strptime(dt_server,
50 '%Y-%m-%d %H:%M:%S')
51 # create list with tz to apply in datetime
52 self.user.write(cr, uid, uid, {'tz': 'Europe/Rome'})
53 # Assign tz to user
54 # call the function _get_datetime_with_user_tz
55 # to get the date with tz applied
56 datetime_tz_rome = self.invoice._get_datetime_with_user_tz(
57 cr, uid, datetime_object)
58 # Create an invoice with last tz of cycle America/Mexico_City
59 invoice_tz_rome_id = self.invoice.create(
60 cr, uid,
61 {'partner_id': 1,
62 'account_id': 1,
63 'invoice_datetime': dt_server})
64 self.user.write(cr, uid, uid, {'tz': 'America/Mexico_City'})
65 # Assign tz to user
66 datetime_tz_mx = self.invoice._get_datetime_with_user_tz(
67 cr, uid, datetime_object)
68 invoice_tz_mx_id = self.invoice.create(
69 cr, uid,
70 {'partner_id': 1,
71 'account_id': 1,
72 'invoice_datetime': dt_server})
73 dt_inv_tz_rome = self.invoice.read(
74 cr, uid, invoice_tz_rome_id, []).get('date_invoice_tz')
75 dt_inv_tz_mx = self.invoice.read(
76 cr, uid, invoice_tz_mx_id, []).get('date_invoice_tz')
77 _logger.info("Validate datetime of function, for Rome-Mexico_City TZ")
78 self.assertNotEqual(
79 datetime_tz_rome,
80 datetime_tz_mx, 'Dates are equal, should be different')
81 _logger.info("Validate datetime of function versus invoice datetime")
82 self.assertEquals(datetime_tz_rome, dt_inv_tz_rome,
83 'Date calculated and date of invoice are not equals')
84 self.assertEquals(datetime_tz_mx, dt_inv_tz_mx,
85 'Date calculated and date of invoice are not equals')
86 _logger.info("Validate invoice datetime, for Rome-Mexico_City TZ")
87 self.assertNotEqual(
88 dt_inv_tz_rome,
89 dt_inv_tz_mx, 'Dates are equal, must be different on invoices')