Merge lp:~vauxoo/addons-vauxoo/7.0-addons-vauxoo-imp-datetime-dev-ernesto into lp:addons-vauxoo/7.0
- 7.0-addons-vauxoo-imp-datetime-dev-ernesto
- Merge into 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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jorge Angel Naranjo Rogel - http://www.vauxoo.com | Approve | ||
Jose Antonio Morales Ponce(vauxoo) - - http://www.vauxoo.com | Needs Fixing | ||
Moisés López - http://www.vauxoo.com | Pending | ||
Nhomar - Vauxoo | Pending | ||
Luis Ernesto García Medina - http://www.vauxoo.com | Pending | ||
Review via email: mp+231273@code.launchpad.net |
Commit message
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
- 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
Jorge Angel Naranjo Rogel - http://www.vauxoo.com (jorge-nr) wrote : | # |
- 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
Jose Antonio Morales Ponce(vauxoo) - - http://www.vauxoo.com (josemoralesp) : | # |
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
- 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
Jorge Angel Naranjo Rogel - http://www.vauxoo.com (jorge-nr) : | # |
Preview Diff
1 | === modified file 'invoice_datetime/__init__.py' | |||
2 | --- invoice_datetime/__init__.py 2014-10-03 00:28:23 +0000 | |||
3 | +++ invoice_datetime/__init__.py 2014-11-18 22:23:17 +0000 | |||
4 | @@ -7,7 +7,8 @@ | |||
5 | 7 | # info Vauxoo (info@vauxoo.com) | 7 | # info Vauxoo (info@vauxoo.com) |
6 | 8 | ############################################################################ | 8 | ############################################################################ |
7 | 9 | # Coded by: moylop260 (moylop260@vauxoo.com) | 9 | # Coded by: moylop260 (moylop260@vauxoo.com) |
9 | 10 | # Launchpad Project Manager for Publication: Nhomar Hernandez - nhomar@vauxoo.com | 10 | # Launchpad Project Manager for Publication: |
10 | 11 | # Nhomar Hernandez - nhomar@vauxoo.com | ||
11 | 11 | ############################################################################ | 12 | ############################################################################ |
12 | 12 | # | 13 | # |
13 | 13 | # This program is free software: you can redistribute it and/or modify | 14 | # This program is free software: you can redistribute it and/or modify |
14 | @@ -27,4 +28,3 @@ | |||
15 | 27 | 28 | ||
16 | 28 | from . import invoice | 29 | from . import invoice |
17 | 29 | from . import res_config | 30 | from . import res_config |
18 | 30 | |||
19 | 31 | 31 | ||
20 | === modified file 'invoice_datetime/__openerp__.py' | |||
21 | --- invoice_datetime/__openerp__.py 2014-10-03 08:22:36 +0000 | |||
22 | +++ invoice_datetime/__openerp__.py 2014-11-18 22:23:17 +0000 | |||
23 | @@ -6,8 +6,10 @@ | |||
24 | 6 | # All Rights Reserved. | 6 | # All Rights Reserved. |
25 | 7 | # info Vauxoo (info@vauxoo.com) | 7 | # info Vauxoo (info@vauxoo.com) |
26 | 8 | ############################################################################ | 8 | ############################################################################ |
29 | 9 | # Coded by: moylop260 (moylop260@vauxoo.com) modified by carlosecv74@gmail.com | 9 | # Coded by: moylop260 (moylop260@vauxoo.com) |
30 | 10 | # Launchpad Project Manager for Publication: Nhomar Hernandez - nhomar@vauxoo.com | 10 | # modified by carlosecv74@gmail.com |
31 | 11 | # Launchpad Project Manager for Publication: | ||
32 | 12 | # Nhomar Hernandez - nhomar@vauxoo.com | ||
33 | 11 | ############################################################################ | 13 | ############################################################################ |
34 | 12 | # | 14 | # |
35 | 13 | # This program is free software: you can redistribute it and/or modify | 15 | # This program is free software: you can redistribute it and/or modify |
36 | @@ -25,28 +27,28 @@ | |||
37 | 25 | # | 27 | # |
38 | 26 | ############################################################################## | 28 | ############################################################################## |
39 | 27 | { | 29 | { |
44 | 28 | "name": "invoice_datetime", | 30 | "name": "invoice_datetime", |
45 | 29 | "version": "1.0", | 31 | "version": "1.0", |
46 | 30 | "author": "Vauxoo", | 32 | "author": "Vauxoo", |
47 | 31 | "category": "Localization/Mexico", | 33 | "category": "Localization/Mexico", |
48 | 32 | "description": """Add new field invoice_datetime for electronic invoice data | 34 | "description": """Add new field invoice_datetime for electronic invoice data |
49 | 33 | and add hour & minute to field date_invoice | 35 | and add hour & minute to field date_invoice |
53 | 34 | """, | 36 | """, |
54 | 35 | "website": "http://www.vauxoo.com/", | 37 | "website": "http://www.vauxoo.com/", |
55 | 36 | "license": "AGPL-3", | 38 | "license": "AGPL-3", |
56 | 37 | "depends": [ | 39 | "depends": [ |
57 | 38 | "account" | 40 | "account" |
60 | 39 | ], | 41 | ], |
61 | 40 | "demo": [], | 42 | "demo": [], |
62 | 41 | "data": [ | 43 | "data": [ |
64 | 42 | "account_invoice_view.xml", | 44 | "account_invoice_view.xml", |
65 | 43 | "res_config_acc_view.xml" | 45 | "res_config_acc_view.xml" |
73 | 44 | ], | 46 | ], |
74 | 45 | "test": [], | 47 | "test": [], |
75 | 46 | "js": [], | 48 | "js": [], |
76 | 47 | "css": [], | 49 | "css": [], |
77 | 48 | "qweb": [], | 50 | "qweb": [], |
78 | 49 | "installable": True, | 51 | "installable": True, |
79 | 50 | "auto_install": False, | 52 | "auto_install": False, |
80 | 51 | "active": False | 53 | "active": False |
81 | 52 | } | ||
82 | 53 | \ No newline at end of file | 54 | \ No newline at end of file |
83 | 55 | } | ||
84 | 54 | 56 | ||
85 | === modified file 'invoice_datetime/invoice.py' | |||
86 | --- invoice_datetime/invoice.py 2014-11-05 16:41:06 +0000 | |||
87 | +++ invoice_datetime/invoice.py 2014-11-18 22:23:17 +0000 | |||
88 | @@ -7,7 +7,8 @@ | |||
89 | 7 | # info Vauxoo (info@vauxoo.com) | 7 | # info Vauxoo (info@vauxoo.com) |
90 | 8 | ############################################################################ | 8 | ############################################################################ |
91 | 9 | # Coded by: moylop260 (moylop260@vauxoo.com) | 9 | # Coded by: moylop260 (moylop260@vauxoo.com) |
93 | 10 | # Launchpad Project Manager for Publication: Nhomar Hernandez - nhomar@vauxoo.com | 10 | # Launchpad Project Manager for Publication: |
94 | 11 | # * Nhomar Hernandez - nhomar@vauxoo.com | ||
95 | 11 | ############################################################################ | 12 | ############################################################################ |
96 | 12 | # | 13 | # |
97 | 13 | # This program is free software: you can redistribute it and/or modify | 14 | # This program is free software: you can redistribute it and/or modify |
98 | @@ -28,8 +29,8 @@ | |||
99 | 28 | from openerp.osv import fields, osv | 29 | from openerp.osv import fields, osv |
100 | 29 | from openerp.tools.translate import _ | 30 | from openerp.tools.translate import _ |
101 | 30 | from openerp import tools | 31 | from openerp import tools |
102 | 31 | from openerp import release | ||
103 | 32 | import datetime | 32 | import datetime |
104 | 33 | from datetime import timedelta | ||
105 | 33 | from pytz import timezone | 34 | from pytz import timezone |
106 | 34 | import pytz | 35 | import pytz |
107 | 35 | import time | 36 | import time |
108 | @@ -47,61 +48,94 @@ | |||
109 | 47 | date_ref, '%Y-%m-%d %H:%M:%S')) | 48 | date_ref, '%Y-%m-%d %H:%M:%S')) |
110 | 48 | except BaseException: | 49 | except BaseException: |
111 | 49 | pass | 50 | pass |
114 | 50 | return super(account_payment_term, self).compute(cr, uid, ids, value, | 51 | return super(account_payment_term, self).compute( |
115 | 51 | date_ref, context=context) | 52 | cr, uid, ids, value, date_ref, context=context) |
116 | 52 | 53 | ||
117 | 53 | 54 | ||
118 | 54 | class account_invoice(osv.Model): | 55 | class account_invoice(osv.Model): |
119 | 55 | _inherit = 'account.invoice' | 56 | _inherit = 'account.invoice' |
138 | 56 | #_order = 'invoice_datetime asc' | 57 | # _order = 'invoice_datetime asc' |
121 | 57 | |||
122 | 58 | def _get_date_invoice_tz(self, cr, uid, ids, field_names=None, arg=False, context=None): | ||
123 | 59 | if context is None: | ||
124 | 60 | context = {} | ||
125 | 61 | res = {} | ||
126 | 62 | if release.version >= '6': | ||
127 | 63 | tz = self.pool.get('res.users').browse(cr, uid, uid).tz | ||
128 | 64 | for invoice in self.browse(cr, uid, ids, context=context): | ||
129 | 65 | res[invoice.id] = invoice.invoice_datetime and tools.\ | ||
130 | 66 | server_to_local_timestamp(invoice.invoice_datetime, | ||
131 | 67 | tools.DEFAULT_SERVER_DATETIME_FORMAT, | ||
132 | 68 | tools.DEFAULT_SERVER_DATETIME_FORMAT, tz) or False | ||
133 | 69 | elif release.version < '6': | ||
134 | 70 | # TODO: tz change for openerp5 | ||
135 | 71 | for invoice in self.browse(cr, uid, ids, context=context): | ||
136 | 72 | res[invoice.id] = invoice.date_invoice | ||
137 | 73 | return res | ||
139 | 74 | 58 | ||
140 | 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): |
141 | 76 | if context is None: | 60 | if context is None: |
142 | 77 | context = {} | 61 | context = {} |
143 | 62 | account_setting_obj = self.pool.get("account.config.settings") | ||
144 | 78 | ids = isinstance(ids, (int, long)) and [ids] or ids | 63 | ids = isinstance(ids, (int, long)) and [ids] or ids |
145 | 79 | res = {} | 64 | res = {} |
148 | 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_" + \ |
149 | 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)) |
150 | 67 | res[ids[0]] = self.pool.get("ir.config_parameter").get_param( | ||
151 | 68 | cr, uid, key_by_company_id, default='date', context=context) | ||
152 | 82 | return res | 69 | return res |
153 | 83 | 70 | ||
154 | 84 | _columns = { | 71 | _columns = { |
155 | 85 | # Extract date_invoice from original, but add datetime | 72 | # Extract date_invoice from original, but add datetime |
158 | 86 | #'date_invoice': fields.datetime('Date Invoiced', states={'open':[ | 73 | # 'date_invoice': fields.datetime('Date Invoiced', states={'open':[ |
159 | 87 | #('readonly',True)],'close':[('readonly',True)]}, | 74 | # ('readonly',True)],'close':[('readonly',True)]}, |
160 | 88 | # help="Keep empty to use the current date"), | 75 | # help="Keep empty to use the current date"), |
163 | 89 | 'invoice_datetime': fields.datetime('Date time of invoice', | 76 | 'invoice_datetime': fields.datetime( |
164 | 90 | states={'open': [('readonly', True)], 'close': [('readonly', True)]}, | 77 | 'Date time of invoice', |
165 | 78 | states={ | ||
166 | 79 | 'open': [('readonly', True)], | ||
167 | 80 | 'close': [('readonly', True)]}, | ||
168 | 91 | help="Keep empty to use the current date"), | 81 | help="Keep empty to use the current date"), |
171 | 92 | 'date_invoice_tz': fields.function(_get_date_invoice_tz, method=True, | 82 | 'date_invoice_tz': fields.datetime( |
172 | 93 | type='datetime', string='Date Invoiced with TZ', store=True, | 83 | string='Date Invoiced with TZ', |
173 | 94 | help='Date of Invoice with Time Zone'), | 84 | help='Date of Invoice with Time Zone'), |
175 | 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, |
176 | 86 | type='char', string="Date type") | ||
177 | 96 | } | 87 | } |
178 | 97 | 88 | ||
179 | 89 | def _get_datetime_with_user_tz(self, cr, uid, datetime_invoice=False, | ||
180 | 90 | context=None): | ||
181 | 91 | datetime_inv_tz = False | ||
182 | 92 | if datetime_invoice: | ||
183 | 93 | time_tz = self.pool.get("res.users").read( | ||
184 | 94 | cr, uid, uid, ["tz_offset"], context=context).get("tz_offset") | ||
185 | 95 | hours_tz = int(time_tz[:-2]) | ||
186 | 96 | minut_tz = int(time_tz[-2:]) | ||
187 | 97 | if time_tz[0] == '-': | ||
188 | 98 | minut_tz = minut_tz * -1 | ||
189 | 99 | datetime_inv_tz = ( | ||
190 | 100 | datetime_invoice + timedelta( | ||
191 | 101 | hours=hours_tz, | ||
192 | 102 | minutes=minut_tz)).strftime('%Y-%m-%d %H:%M:%S') | ||
193 | 103 | return datetime_inv_tz | ||
194 | 104 | |||
195 | 105 | def create(self, cr, uid, vals, context=None): | ||
196 | 106 | if 'invoice_datetime' in vals.keys(): | ||
197 | 107 | datetime_inv = vals.get("invoice_datetime") and \ | ||
198 | 108 | datetime.datetime.strptime( | ||
199 | 109 | vals.get("invoice_datetime"), "%Y-%m-%d %H:%M:%S") or False | ||
200 | 110 | if datetime_inv: | ||
201 | 111 | vals.update( | ||
202 | 112 | {'date_invoice_tz': self._get_datetime_with_user_tz( | ||
203 | 113 | cr, uid, datetime_inv)}) | ||
204 | 114 | return super(account_invoice, self).create( | ||
205 | 115 | cr, uid, vals, context=context) | ||
206 | 116 | |||
207 | 117 | def write(self, cr, uid, ids, vals, context=None): | ||
208 | 118 | for invoice in self.browse(cr, uid, ids, context=context): | ||
209 | 119 | datetime_inv = invoice.invoice_datetime and \ | ||
210 | 120 | datetime.datetime.strptime(invoice.invoice_datetime, | ||
211 | 121 | "%Y-%m-%d %H:%M:%S") or False | ||
212 | 122 | if datetime_inv: | ||
213 | 123 | vals.update( | ||
214 | 124 | {'date_invoice_tz': self._get_datetime_with_user_tz( | ||
215 | 125 | cr, uid, datetime_inv)}) | ||
216 | 126 | return super(account_invoice, self).write( | ||
217 | 127 | cr, uid, ids, vals, context=context) | ||
218 | 128 | |||
219 | 98 | def _get_default_type(self, cr, uid, ids): | 129 | def _get_default_type(self, cr, uid, ids): |
222 | 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") |
223 | 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_" + \ |
224 | 132 | str(account_setting_obj._default_company(cr, uid)) | ||
225 | 133 | type_show_date = self.pool.get("ir.config_parameter").get_param( | ||
226 | 134 | cr, uid, key_by_company_id, default='date') | ||
227 | 101 | return type_show_date | 135 | return type_show_date |
228 | 102 | 136 | ||
229 | 103 | _defaults = { | 137 | _defaults = { |
231 | 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'), |
232 | 105 | "date_type": _get_default_type | 139 | "date_type": _get_default_type |
233 | 106 | } | 140 | } |
234 | 107 | 141 | ||
235 | @@ -111,7 +145,8 @@ | |||
236 | 111 | if default is None: | 145 | if default is None: |
237 | 112 | default = {} | 146 | default = {} |
238 | 113 | default.update({'invoice_datetime': False, 'date_invoice': False}) | 147 | default.update({'invoice_datetime': False, 'date_invoice': False}) |
240 | 114 | return super(account_invoice, self).copy(cr, uid, ids, default, context) | 148 | return super(account_invoice, self).copy( |
241 | 149 | cr, uid, ids, default, context) | ||
242 | 115 | 150 | ||
243 | 116 | def _get_time_zone(self, cr, uid, invoice_id, context=None): | 151 | def _get_time_zone(self, cr, uid, invoice_id, context=None): |
244 | 117 | if context is None: | 152 | if context is None: |
245 | @@ -123,8 +158,9 @@ | |||
246 | 123 | hours = timezone(userstz) | 158 | hours = timezone(userstz) |
247 | 124 | fmt = '%Y-%m-%d %H:%M:%S %Z%z' | 159 | fmt = '%Y-%m-%d %H:%M:%S %Z%z' |
248 | 125 | now = datetime.datetime.now() | 160 | now = datetime.datetime.now() |
251 | 126 | loc_dt = hours.localize(datetime.datetime(now.year, now.month, now.day, | 161 | loc_dt = hours.localize(datetime.datetime(now.year, now.month, |
252 | 127 | now.hour, now.minute, now.second)) | 162 | now.day, now.hour, |
253 | 163 | now.minute, now.second)) | ||
254 | 128 | timezone_loc = (loc_dt.strftime(fmt)) | 164 | timezone_loc = (loc_dt.strftime(fmt)) |
255 | 129 | diff_timezone_original = timezone_loc[-5:-2] | 165 | diff_timezone_original = timezone_loc[-5:-2] |
256 | 130 | timezone_original = int(diff_timezone_original) | 166 | timezone_original = int(diff_timezone_original) |
257 | @@ -155,9 +191,10 @@ | |||
258 | 155 | 191 | ||
259 | 156 | if values.get('invoice_datetime', False) and not\ | 192 | if values.get('invoice_datetime', False) and not\ |
260 | 157 | values.get('date_invoice', False): | 193 | values.get('date_invoice', False): |
264 | 158 | date_invoice = fields.datetime.context_timestamp(cr, uid, | 194 | date_invoice = fields.datetime.context_timestamp( |
265 | 159 | datetime.datetime.strptime(values['invoice_datetime'], | 195 | cr, uid, datetime.datetime.strptime( |
266 | 160 | tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context) | 196 | values['invoice_datetime'], |
267 | 197 | tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context) | ||
268 | 161 | res['date_invoice'] = date_invoice | 198 | res['date_invoice'] = date_invoice |
269 | 162 | res['invoice_datetime'] = values['invoice_datetime'] | 199 | res['invoice_datetime'] = values['invoice_datetime'] |
270 | 163 | 200 | ||
271 | @@ -168,31 +205,39 @@ | |||
272 | 168 | '%Y-%m-%d %H:%M:%S').date().strftime('%Y-%m-%d') | 205 | '%Y-%m-%d %H:%M:%S').date().strftime('%Y-%m-%d') |
273 | 169 | if date_invoice != values['date_invoice']: | 206 | if date_invoice != values['date_invoice']: |
274 | 170 | if self.browse(cr, uid, ids)[0].date_type == 'datetime': | 207 | if self.browse(cr, uid, ids)[0].date_type == 'datetime': |
278 | 171 | date_invoice = fields.datetime.context_timestamp(cr, uid, | 208 | date_invoice = fields.datetime.context_timestamp( |
279 | 172 | datetime.datetime.strptime(values['invoice_datetime'], | 209 | cr, uid, datetime.datetime.strptime( |
280 | 173 | tools.DEFAULT_SERVER_DATETIME_FORMAT), context=context) | 210 | values['invoice_datetime'], |
281 | 211 | tools.DEFAULT_SERVER_DATETIME_FORMAT), | ||
282 | 212 | context=context) | ||
283 | 174 | res['date_invoice'] = date_invoice | 213 | res['date_invoice'] = date_invoice |
284 | 175 | res['invoice_datetime'] = values['invoice_datetime'] | 214 | res['invoice_datetime'] = values['invoice_datetime'] |
285 | 176 | elif self.browse(cr, uid, ids)[0].date_type == 'date': | 215 | elif self.browse(cr, uid, ids)[0].date_type == 'date': |
287 | 177 | user_hour = self._get_time_zone(cr, uid, [], context=context) | 216 | user_hour = self._get_time_zone( |
288 | 217 | cr, uid, [], context=context) | ||
289 | 178 | time_invoice = datetime.time(abs(user_hour), 0, 0) | 218 | time_invoice = datetime.time(abs(user_hour), 0, 0) |
290 | 179 | 219 | ||
291 | 180 | date_invoice = datetime.datetime.strptime( | 220 | date_invoice = datetime.datetime.strptime( |
292 | 181 | values['date_invoice'], '%Y-%m-%d').date() | 221 | values['date_invoice'], '%Y-%m-%d').date() |
293 | 182 | 222 | ||
294 | 183 | dt_invoice = datetime.datetime.combine( | 223 | dt_invoice = datetime.datetime.combine( |
296 | 184 | date_invoice, time_invoice).strftime('%Y-%m-%d %H:%M:%S') | 224 | date_invoice, |
297 | 225 | time_invoice).strftime('%Y-%m-%d %H:%M:%S') | ||
298 | 185 | 226 | ||
299 | 186 | res['invoice_datetime'] = dt_invoice | 227 | res['invoice_datetime'] = dt_invoice |
300 | 187 | res['date_invoice'] = values['date_invoice'] | 228 | res['date_invoice'] = values['date_invoice'] |
301 | 188 | else: | 229 | else: |
305 | 189 | raise osv.except_osv(_('Warning!'), _('Invoice dates should be equal')) | 230 | raise osv.except_osv( |
306 | 190 | #~ else: | 231 | _('Warning!'), |
307 | 191 | #~ raise osv.except_osv(_('Warning!'), _('Invoice dates should be equal')) | 232 | _('Invoice dates should be equal')) |
308 | 233 | # ~ else: | ||
309 | 234 | # ~ raise osv.except_osv(_('Warning!'), | ||
310 | 235 | # _('Invoice dates should be equal')) | ||
311 | 192 | 236 | ||
313 | 193 | if not values.get('invoice_datetime', False) and\ | 237 | if not values.get('invoice_datetime', False) and\ |
314 | 194 | not values.get('date_invoice', False): | 238 | not values.get('date_invoice', False): |
316 | 195 | res['date_invoice'] = fields.date.context_today(self, cr, uid, context=context) | 239 | res['date_invoice'] = fields.date.context_today( |
317 | 240 | self, cr, uid, context=context) | ||
318 | 196 | res['invoice_datetime'] = fields.datetime.now() | 241 | res['invoice_datetime'] = fields.datetime.now() |
319 | 197 | 242 | ||
320 | 198 | return res | 243 | return res |
321 | @@ -200,9 +245,9 @@ | |||
322 | 200 | def action_move_create(self, cr, uid, ids, context=None): | 245 | def action_move_create(self, cr, uid, ids, context=None): |
323 | 201 | for inv in self.browse(cr, uid, ids, context=context): | 246 | for inv in self.browse(cr, uid, ids, context=context): |
324 | 202 | if inv.type in ('out_invoice', 'out_refund'): | 247 | if inv.type in ('out_invoice', 'out_refund'): |
328 | 203 | vals_date = self.assigned_datetime(cr, uid, ids, | 248 | vals_date = self.assigned_datetime( |
329 | 204 | {'invoice_datetime': inv.invoice_datetime, | 249 | cr, uid, ids, {'invoice_datetime': inv.invoice_datetime, |
330 | 205 | 'date_invoice': inv.date_invoice}, | 250 | 'date_invoice': inv.date_invoice}, |
331 | 206 | context=context) | 251 | context=context) |
332 | 207 | self.write(cr, uid, ids, vals_date, context=context) | 252 | self.write(cr, uid, ids, vals_date, context=context) |
333 | 208 | return super(account_invoice, | 253 | return super(account_invoice, |
334 | 209 | 254 | ||
335 | === modified file 'invoice_datetime/res_config.py' | |||
336 | --- invoice_datetime/res_config.py 2014-10-03 07:19:35 +0000 | |||
337 | +++ invoice_datetime/res_config.py 2014-11-18 22:23:17 +0000 | |||
338 | @@ -31,29 +31,45 @@ | |||
339 | 31 | 31 | ||
340 | 32 | _columns = { | 32 | _columns = { |
341 | 33 | 'groups_id': fields.many2one('res.groups', 'Category',), | 33 | 'groups_id': fields.many2one('res.groups', 'Category',), |
343 | 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'), ( |
344 | 35 | 'datetime', 'Datetime')], | ||
345 | 36 | string="Default date of invoices", | ||
346 | 37 | help="Select the field you want to displayed in the \ | ||
347 | 38 | invoice for the selected company."), | ||
348 | 35 | } | 39 | } |
349 | 36 | 40 | ||
350 | 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): |
353 | 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( |
354 | 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)) |
355 | 44 | type_show_date = self.pool.get("ir.config_parameter").get_param( | ||
356 | 45 | cr, uid, key_by_company_id, default='date', context=context) | ||
357 | 40 | return {'select_date': type_show_date} | 46 | return {'select_date': type_show_date} |
358 | 41 | 47 | ||
359 | 42 | def set_default_select_date(self, cr, uid, ids, context=None): | 48 | def set_default_select_date(self, cr, uid, ids, context=None): |
360 | 43 | """ set default sale and purchase taxes for products """ | 49 | """ set default sale and purchase taxes for products """ |
363 | 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( |
364 | 45 | raise openerp.exceptions.AccessError(_("Only administrators can change the settings")) | 51 | cr, uid, 'base.group_erp_manager'): |
365 | 52 | raise openerp.exceptions.AccessError( | ||
366 | 53 | _("Only administrators can change the settings")) | ||
367 | 46 | config_parameters = self.pool.get("ir.config_parameter") | 54 | config_parameters = self.pool.get("ir.config_parameter") |
368 | 47 | for record in self.browse(cr, uid, ids, context=context): | 55 | for record in self.browse(cr, uid, ids, context=context): |
370 | 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 |
371 | 57 | record.company_id.id or | ||
372 | 58 | self._default_company(cr, uid)) | ||
373 | 49 | key_by_company_id = "acc_invoice.date_invoice_type_" + company_id | 59 | key_by_company_id = "acc_invoice.date_invoice_type_" + company_id |
375 | 50 | config_parameters.set_param(cr, uid, key_by_company_id, record.select_date or '', context=context) | 60 | config_parameters.set_param( |
376 | 61 | cr, uid, key_by_company_id, record.select_date or '', | ||
377 | 62 | context=context) | ||
378 | 51 | 63 | ||
379 | 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): |
381 | 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( |
382 | 66 | cr, uid, ids, company_id, context=context) | ||
383 | 54 | type_date = False | 67 | type_date = False |
384 | 55 | type_date = result.get('value', {}) | 68 | type_date = result.get('value', {}) |
387 | 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( |
388 | 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)) |
389 | 71 | type_date['select_date'] = self.pool.get( | ||
390 | 72 | "ir.config_parameter").get_param( | ||
391 | 73 | cr, uid, key_by_company_id, default='date', context=context) | ||
392 | 58 | result.update({'value': type_date}) | 74 | result.update({'value': type_date}) |
393 | 59 | return result | 75 | return result |
394 | 60 | 76 | ||
395 | === added directory 'invoice_datetime/tests' | |||
396 | === added file 'invoice_datetime/tests/__init__.py' | |||
397 | --- invoice_datetime/tests/__init__.py 1970-01-01 00:00:00 +0000 | |||
398 | +++ invoice_datetime/tests/__init__.py 2014-11-18 22:23:17 +0000 | |||
399 | @@ -0,0 +1,27 @@ | |||
400 | 1 | #!/usr/bin/python | ||
401 | 2 | # -*- encoding: utf-8 -*- | ||
402 | 3 | # | ||
403 | 4 | # Module Writen to OpenERP, Open Source Management Solution | ||
404 | 5 | # | ||
405 | 6 | # Copyright (c) 2014 Vauxoo - http://www.vauxoo.com/ | ||
406 | 7 | # All Rights Reserved. | ||
407 | 8 | # info Vauxoo (info@vauxoo.com) | ||
408 | 9 | # | ||
409 | 10 | # Coded by: vauxoo consultores (info@vauxoo.com) | ||
410 | 11 | # | ||
411 | 12 | # | ||
412 | 13 | # This program is free software: you can redistribute it and/or modify | ||
413 | 14 | # it under the terms of the GNU Affero General Public License as | ||
414 | 15 | # published by the Free Software Foundation, either version 3 of the | ||
415 | 16 | # License, or (at your option) any later version. | ||
416 | 17 | # | ||
417 | 18 | # This program is distributed in the hope that it will be useful, | ||
418 | 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
419 | 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
420 | 21 | # GNU Affero General Public License for more details. | ||
421 | 22 | # | ||
422 | 23 | # You should have received a copy of the GNU Affero General Public License | ||
423 | 24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
424 | 25 | # | ||
425 | 26 | |||
426 | 27 | from . import test_invoice_datetime | ||
427 | 0 | 28 | ||
428 | === added file 'invoice_datetime/tests/test_invoice_datetime.py' | |||
429 | --- invoice_datetime/tests/test_invoice_datetime.py 1970-01-01 00:00:00 +0000 | |||
430 | +++ invoice_datetime/tests/test_invoice_datetime.py 2014-11-18 22:23:17 +0000 | |||
431 | @@ -0,0 +1,89 @@ | |||
432 | 1 | #!/usr/bin/python | ||
433 | 2 | # -*- encoding: utf-8 -*- | ||
434 | 3 | # | ||
435 | 4 | # Module Writen to OpenERP, Open Source Management Solution | ||
436 | 5 | # | ||
437 | 6 | # Copyright (c) 2014 Vauxoo - http://www.vauxoo.com/ | ||
438 | 7 | # All Rights Reserved. | ||
439 | 8 | # info Vauxoo (info@vauxoo.com) | ||
440 | 9 | # | ||
441 | 10 | # Coded by: vauxoo consultores (info@vauxoo.com) | ||
442 | 11 | # | ||
443 | 12 | # | ||
444 | 13 | # This program is free software: you can redistribute it and/or modify | ||
445 | 14 | # it under the terms of the GNU Affero General Public License as | ||
446 | 15 | # published by the Free Software Foundation, either version 3 of the | ||
447 | 16 | # License, or (at your option) any later version. | ||
448 | 17 | # | ||
449 | 18 | # This program is distributed in the hope that it will be useful, | ||
450 | 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
451 | 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
452 | 21 | # GNU Affero General Public License for more details. | ||
453 | 22 | # | ||
454 | 23 | # You should have received a copy of the GNU Affero General Public License | ||
455 | 24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
456 | 25 | # | ||
457 | 26 | |||
458 | 27 | from openerp.tests.common import TransactionCase | ||
459 | 28 | from openerp.tools import mute_logger | ||
460 | 29 | import time | ||
461 | 30 | import datetime | ||
462 | 31 | import logging | ||
463 | 32 | _logger = logging.getLogger(__name__) | ||
464 | 33 | |||
465 | 34 | |||
466 | 35 | class TestInvoiceDatetime(TransactionCase): | ||
467 | 36 | def setUp(self): | ||
468 | 37 | super(TestInvoiceDatetime, self).setUp() | ||
469 | 38 | self.user = self.registry('res.users') | ||
470 | 39 | self.data = self.registry('ir.model.data') | ||
471 | 40 | self.invoice = self.registry('account.invoice') | ||
472 | 41 | |||
473 | 42 | @mute_logger('openerp.addons.base.ir.ir_model', 'openerp.osv.orm') | ||
474 | 43 | def test_get_datetime(self): | ||
475 | 44 | cr, uid = self.cr, self.uid | ||
476 | 45 | # get datetime of server in string | ||
477 | 46 | dt_server = time.strftime('%Y-%m-%d %H:%M:%S') | ||
478 | 47 | # I generate object of type datetime | ||
479 | 48 | # to send at function _get_datetime_with_user_tz | ||
480 | 49 | datetime_object = datetime.datetime.strptime(dt_server, | ||
481 | 50 | '%Y-%m-%d %H:%M:%S') | ||
482 | 51 | # create list with tz to apply in datetime | ||
483 | 52 | self.user.write(cr, uid, uid, {'tz': 'Europe/Rome'}) | ||
484 | 53 | # Assign tz to user | ||
485 | 54 | # call the function _get_datetime_with_user_tz | ||
486 | 55 | # to get the date with tz applied | ||
487 | 56 | datetime_tz_rome = self.invoice._get_datetime_with_user_tz( | ||
488 | 57 | cr, uid, datetime_object) | ||
489 | 58 | # Create an invoice with last tz of cycle America/Mexico_City | ||
490 | 59 | invoice_tz_rome_id = self.invoice.create( | ||
491 | 60 | cr, uid, | ||
492 | 61 | {'partner_id': 1, | ||
493 | 62 | 'account_id': 1, | ||
494 | 63 | 'invoice_datetime': dt_server}) | ||
495 | 64 | self.user.write(cr, uid, uid, {'tz': 'America/Mexico_City'}) | ||
496 | 65 | # Assign tz to user | ||
497 | 66 | datetime_tz_mx = self.invoice._get_datetime_with_user_tz( | ||
498 | 67 | cr, uid, datetime_object) | ||
499 | 68 | invoice_tz_mx_id = self.invoice.create( | ||
500 | 69 | cr, uid, | ||
501 | 70 | {'partner_id': 1, | ||
502 | 71 | 'account_id': 1, | ||
503 | 72 | 'invoice_datetime': dt_server}) | ||
504 | 73 | dt_inv_tz_rome = self.invoice.read( | ||
505 | 74 | cr, uid, invoice_tz_rome_id, []).get('date_invoice_tz') | ||
506 | 75 | dt_inv_tz_mx = self.invoice.read( | ||
507 | 76 | cr, uid, invoice_tz_mx_id, []).get('date_invoice_tz') | ||
508 | 77 | _logger.info("Validate datetime of function, for Rome-Mexico_City TZ") | ||
509 | 78 | self.assertNotEqual( | ||
510 | 79 | datetime_tz_rome, | ||
511 | 80 | datetime_tz_mx, 'Dates are equal, should be different') | ||
512 | 81 | _logger.info("Validate datetime of function versus invoice datetime") | ||
513 | 82 | self.assertEquals(datetime_tz_rome, dt_inv_tz_rome, | ||
514 | 83 | 'Date calculated and date of invoice are not equals') | ||
515 | 84 | self.assertEquals(datetime_tz_mx, dt_inv_tz_mx, | ||
516 | 85 | 'Date calculated and date of invoice are not equals') | ||
517 | 86 | _logger.info("Validate invoice datetime, for Rome-Mexico_City TZ") | ||
518 | 87 | self.assertNotEqual( | ||
519 | 88 | dt_inv_tz_rome, | ||
520 | 89 | dt_inv_tz_mx, 'Dates are equal, must be different on invoices') |
@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