Merge lp:~elbati/account-financial-tools/currency_rate_update_v7 into lp:~account-core-editors/account-financial-tools/7.0

Proposed by Lorenzo Battistini
Status: Merged
Approved by: Joël Grand-Guillaume @ camptocamp
Approved revision: 116
Merged at revision: 111
Proposed branch: lp:~elbati/account-financial-tools/currency_rate_update_v7
Merge into: lp:~account-core-editors/account-financial-tools/7.0
Diff against target: 362 lines (+49/-86)
8 files modified
currency_rate_update/__init__.py (+0/-1)
currency_rate_update/__openerp__.py (+13/-11)
currency_rate_update/company.py (+5/-3)
currency_rate_update/company_view.xml (+5/-4)
currency_rate_update/currency_rate_update.py (+25/-32)
currency_rate_update/currency_rate_update.xml (+0/-4)
currency_rate_update/security/security.xml (+1/-1)
currency_rate_update/wizard/__init__.py (+0/-30)
To merge this branch: bzr merge lp:~elbati/account-financial-tools/currency_rate_update_v7
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp code review, no test Approve
Joël Grand-Guillaume @ camptocamp code review, no test Approve
Guewen Baconnier @ Camptocamp Approve
Review via email: mp+147945@code.launchpad.net

Description of the change

Small changes to make currency_rate_update work with v7

To post a comment you must log in.
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi Lorenzo,

Thanks for this MP ! It looks good to me.

Regards,

Joël

review: Approve
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

Please:

* use orm.Model instead of osv.osv in currency_rate_update.py and company.py
* remove unused wizard directory (and the corresponding import in currency_rate_update/__init__.py

review: Needs Fixing (code review, no test)
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

> Please:
>
> * use orm.Model instead of osv.osv in currency_rate_update.py and company.py
> * remove unused wizard directory (and the corresponding import in
> currency_rate_update/__init__.py

also:

* merge init_xml and update_xml in 'data' in __openerp__.py (you need to add a noupdate=1 in the security.xml file)
* rename demo_xml to demo in __openerp__.py

Thanks

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

It seems like I need to improve my review ;) ! Thanks Alex

111. By Lorenzo Battistini

[FIX] use osv.Model

112. By Lorenzo Battistini

[DEL] remove unused wizard directory

113. By Lorenzo Battistini

[FIX] loading xml files

114. By Lorenzo Battistini

[FIX] parameter name

115. By Lorenzo Battistini

[IMP] copyright headers

Revision history for this message
Lorenzo Battistini (elbati) wrote :

On 02/14/2013 01:22 PM, Alexandre Fayolle - camptocamp wrote:
>> Please:
>>
>> * use orm.Model instead of osv.osv in currency_rate_update.py and company.py
>> * remove unused wizard directory (and the corresponding import in
>> currency_rate_update/__init__.py
> also:
>
> * merge init_xml and update_xml in 'data' in __openerp__.py (you need to add a noupdate=1 in the security.xml file)
> * rename demo_xml to demo in __openerp__.py

Done

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

When `logging` is used, the variables should not be substituted in the string directly like this:

    _logger.warning("the rate date from ECB (%s) is not today's date" % rate_date_str)

But rather, given as arguments to the call as follows:

    _logger.warning("the rate date from ECB (%s) is not today's date", rate_date_str)

Thus, they will be interpreted only if the logging is effective.

As nobody noticed that before, I won't mind if you don't change them. But would be nice...

Beside that, seems fine to me.
Thanks

review: Approve
116. By Lorenzo Battistini

[IMP] logging arguments

Revision history for this message
Lorenzo Battistini (elbati) wrote :

2013/2/18 Guewen Baconnier @ Camptocamp <email address hidden>

>
> But rather, given as arguments to the call as follows:
>
> _logger.warning("the rate date from ECB (%s) is not today's date",
> rate_date_str)
>
> Thus, they will be interpreted only if the logging is effective.
>
>
Done

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi,

Thanks for the contribs !

Regards,

Joël

review: Approve (code review, no test)
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

LGTM. I'm about to merge.

review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'currency_rate_update/__init__.py'
2--- currency_rate_update/__init__.py 2011-08-12 12:35:23 +0000
3+++ currency_rate_update/__init__.py 2013-02-21 18:08:22 +0000
4@@ -30,4 +30,3 @@
5
6 import currency_rate_update
7 import company
8-import wizard
9
10=== modified file 'currency_rate_update/__openerp__.py'
11--- currency_rate_update/__openerp__.py 2013-01-04 10:31:20 +0000
12+++ currency_rate_update/__openerp__.py 2013-02-21 18:08:22 +0000
13@@ -3,7 +3,7 @@
14 # Copyright (c) 2008 Camtocamp SA
15 # @author JB Aubort, Nicolas Bessi, Joel Grand-Guillaume
16 # European Central Bank and Polish National Bank invented by Grzegorz Grzelak
17-# $Id: $
18+# Ported to OpenERP 7.0 by Lorenzo Battistini <lorenzo.battistini@agilebg.com>
19 #
20 # WARNING: This program as such is intended to be used by professional
21 # programmers who take the whole responsability of assessing all potential
22@@ -29,7 +29,7 @@
23 ##############################################################################
24 {
25 "name" : "Currency Rate Update",
26- "version" : "0.6",
27+ "version" : "0.7",
28 "author" : "Camptocamp",
29 "website" : "http://camptocamp.com",
30 "category" : "Financial Management/Configuration",
31@@ -79,14 +79,16 @@
32
33 Thanks to main contributors: Grzegorz Grzelak, Alexis de Lattre
34 """,
35- "depends" : ["base",
36- "account"], #Added to ensure account security groups are present
37- "init_xml" : ["security/security.xml"],
38- "update_xml" : [
39- "currency_rate_update.xml",
40- "company_view.xml",
41- ],
42- "demo_xml" : [],
43+ "depends" : [
44+ "base",
45+ "account", #Added to ensure account security groups are present
46+ ],
47+ "data" : [
48+ "currency_rate_update.xml",
49+ "company_view.xml",
50+ "security/security.xml",
51+ ],
52+ "demo" : [],
53 "active": False,
54- 'installable': False
55+ 'installable': True
56 }
57
58=== modified file 'currency_rate_update/company.py'
59--- currency_rate_update/company.py 2013-01-04 10:51:23 +0000
60+++ currency_rate_update/company.py 2013-02-21 18:08:22 +0000
61@@ -29,8 +29,9 @@
62 ##############################################################################
63
64 import netsvc
65-from osv import fields, osv
66-class res_company(osv.osv):
67+from openerp.osv import fields, osv
68+
69+class res_company(osv.Model):
70 """override company to add currency update"""
71
72 def _multi_curr_enable(self, cr, uid, ids, field_name, arg, context={}):
73@@ -161,4 +162,5 @@
74 ' not set currency is active on two company'
75 ),
76 }
77-res_company()
78+
79+
80
81=== modified file 'currency_rate_update/company_view.xml'
82--- currency_rate_update/company_view.xml 2012-02-03 13:53:02 +0000
83+++ currency_rate_update/company_view.xml 2013-02-21 18:08:22 +0000
84@@ -4,13 +4,14 @@
85 <field name="name">res.company.form.inherit</field>
86 <field name="model">res.company</field>
87 <field name="inherit_id" ref="base.view_company_form"/>
88- <field name="type">form</field>
89 <field name="arch" type="xml">
90 <notebook position="inside">
91 <page string="Currency auto update configuration">
92- <field name="auto_currency_up" on_change="on_change_auto_currency_up(auto_currency_up)"/>
93- <field name="interval_type" on_change="on_change_intervall(interval_type)"/>
94- <field name="multi_company_currency_enable"/>
95+ <group>
96+ <field name="auto_currency_up" on_change="on_change_auto_currency_up(auto_currency_up)"/>
97+ <field name="interval_type" on_change="on_change_intervall(interval_type)"/>
98+ <field name="multi_company_currency_enable"/>
99+ </group>
100 <separator string="Currency updates services" colspan="4"/>
101 <field name="services_to_use" colspan="4" nolabel="1"/>
102 <button name="button_refresh_currency" string="Refresh currencies" type='object' />
103
104=== modified file 'currency_rate_update/currency_rate_update.py'
105--- currency_rate_update/currency_rate_update.py 2012-04-23 12:19:50 +0000
106+++ currency_rate_update/currency_rate_update.py 2013-02-21 18:08:22 +0000
107@@ -14,6 +14,7 @@
108 # For more details, see Launchpad bug #645263
109 # - mecanism to check if rates given by the webservice are "fresh" enough to be
110 # written in OpenERP ('max_delta_days' parameter for each currency update service)
111+# Ported to OpenERP 7.0 by Lorenzo Battistini <lorenzo.battistini@agilebg.com>
112 #
113 # WARNING: This program as such is intended to be used by professional
114 # programmers who take the whole responsability of assessing all potential
115@@ -42,13 +43,15 @@
116 # a webservice to the list of currencies supported by the Webservice
117 # TODO : implement max_delta_days for Yahoo webservice
118
119-from osv import osv, fields
120+from openerp.osv import fields, osv
121 import time
122 from datetime import datetime, timedelta
123-import netsvc
124-from tools.translate import _
125-
126-class Currency_rate_update_service(osv.osv):
127+import logging
128+from openerp.tools.translate import _
129+
130+_logger = logging.getLogger(__name__)
131+
132+class Currency_rate_update_service(osv.Model):
133 """Class thats tell for wich services wich currencies
134 have to be updated"""
135 _name = "currency.rate.update.service"
136@@ -107,9 +110,8 @@
137 (_check_max_delta_days, "'Max delta days' must be >= 0", ['max_delta_days']),
138 ]
139
140-Currency_rate_update_service()
141
142-class Currency_rate_update(osv.osv):
143+class Currency_rate_update(osv.Model):
144 """Class that handle an ir cron call who will
145 update currencies based on a web url"""
146 _name = "currency.rate.update"
147@@ -128,7 +130,6 @@
148 'args' : '()',
149 }
150
151- logger = netsvc.Logger()
152 LOG_NAME = 'cron-rates'
153 MOD_NAME = 'c2c_currency_rate_update: '
154 def get_cron_id(self, cr, uid, context):
155@@ -151,11 +152,7 @@
156 )
157 cron_id = int(cron_id[0])
158 except Exception,e :
159- self.logger.notifyChannel(
160- self.LOG_NAME,
161- netsvc.LOG_INFO,
162- 'warning cron not found one will be created'
163- )
164+ _logger.info('warning cron not found one will be created')
165 pass # ignore if the cron is missing cause we are going to create it in db
166
167 #the cron does not exists
168@@ -228,11 +225,10 @@
169 except Exception, e:
170 error_msg = note + "\n%s ERROR : %s"\
171 %(datetime.strftime(datetime.today(), '%Y-%m-%d %H:%M:%S'), str(e))
172- self.logger.notifyChannel(self.LOG_NAME, netsvc.LOG_INFO, str(e))
173+ _logger.info(str(e))
174 service.write({'note':error_msg})
175
176-
177-Currency_rate_update()
178+
179
180 ### Error Definition as specified in python 2.6 PEP
181 class AbstractClassError(Exception):
182@@ -355,7 +351,7 @@
183 rate_date_str = datetime.strftime(rate_date, '%Y-%m-%d')
184 if rate_date_str != datetime.strftime(datetime.today(), '%Y-%m-%d'):
185 self.log_info = "WARNING : the rate date from ECB (%s) is not today's date" % rate_date_str
186- netsvc.Logger().notifyChannel("rate_update", netsvc.LOG_WARNING, "the rate date from ECB (%s) is not today's date" % rate_date_str)
187+ _logger.warning("the rate date from ECB (%s) is not today's date", rate_date_str)
188
189
190 #Yahoo ###################################################################################
191@@ -402,11 +398,10 @@
192 currency_array.remove(main_currency)
193 # Move to new XML lib cf Launchpad bug #645263
194 from lxml import etree
195- logger = netsvc.Logger()
196- logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Admin.ch currency rate service : connecting...")
197+ _logger.debug("Admin.ch currency rate service : connecting...")
198 rawfile = self.get_url(url)
199 dom = etree.fromstring(rawfile)
200- logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Admin.ch sent a valid XML file")
201+ _logger.debug("Admin.ch sent a valid XML file")
202 adminch_ns = {'def': 'http://www.afd.admin.ch/publicdb/newdb/mwst_kurse'}
203 rate_date = dom.xpath('/def:wechselkurse/def:datum/text()', namespaces=adminch_ns)[0]
204 rate_date_datetime = datetime.strptime(rate_date, '%Y-%m-%d')
205@@ -416,7 +411,7 @@
206 self.supported_currency_array = [x.upper() for x in self.supported_currency_array]
207 self.supported_currency_array.append('CHF')
208
209- logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Supported currencies = " + str(self.supported_currency_array))
210+ _logger.debug("Supported currencies = " + str(self.supported_currency_array))
211 self.validate_cur(main_currency)
212 if main_currency != 'CHF':
213 main_curr_data = self.rate_retrieve(dom, adminch_ns, main_currency)
214@@ -434,7 +429,7 @@
215 else :
216 rate = main_rate * curr_data['rate_ref'] / curr_data['rate_currency']
217 self.updated_currency[curr] = rate
218- logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
219+ _logger.debug("Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
220 return self.updated_currency, self.log_info
221
222 ## ECB getter ############################################################################
223@@ -464,11 +459,10 @@
224 currency_array.remove(main_currency)
225 # Move to new XML lib cf Launchpad bug #645263
226 from lxml import etree
227- logger = netsvc.Logger()
228- logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "ECB currency rate service : connecting...")
229+ _logger.debug("ECB currency rate service : connecting...")
230 rawfile = self.get_url(url)
231 dom = etree.fromstring(rawfile)
232- logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "ECB sent a valid XML file")
233+ _logger.debug("ECB sent a valid XML file")
234 ecb_ns = {'gesmes': 'http://www.gesmes.org/xml/2002-08-01', 'def': 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref'}
235 rate_date = dom.xpath('/gesmes:Envelope/def:Cube/def:Cube/@time', namespaces=ecb_ns)[0]
236 rate_date_datetime = datetime.strptime(rate_date, '%Y-%m-%d')
237@@ -476,7 +470,7 @@
238 #we dynamically update supported currencies
239 self.supported_currency_array = dom.xpath("/gesmes:Envelope/def:Cube/def:Cube/def:Cube/@currency", namespaces=ecb_ns)
240 self.supported_currency_array.append('EUR')
241- logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Supported currencies = " + str(self.supported_currency_array))
242+ _logger.debug("Supported currencies = " + str(self.supported_currency_array))
243 self.validate_cur(main_currency)
244 if main_currency != 'EUR':
245 main_curr_data = self.rate_retrieve(dom, ecb_ns, main_currency)
246@@ -491,7 +485,7 @@
247 else:
248 rate = curr_data['rate_currency'] / main_curr_data['rate_currency']
249 self.updated_currency[curr] = rate
250- logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
251+ _logger.debug("Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
252 return self.updated_currency, self.log_info
253
254 ##PL NBP ############################################################################
255@@ -517,12 +511,11 @@
256 currency_array.remove(main_currency)
257 # Move to new XML lib cf Launchpad bug #645263
258 from lxml import etree
259- logger = netsvc.Logger()
260- logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "NBP.pl currency rate service : connecting...")
261+ _logger.debug("NBP.pl currency rate service : connecting...")
262 rawfile = self.get_url(url)
263 dom = etree.fromstring(rawfile) # If rawfile is not XML, it crashes here
264 ns = {} # Cool, there are no namespaces !
265- logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "NBP.pl sent a valid XML file")
266+ _logger.debug("NBP.pl sent a valid XML file")
267 #node = xpath.Evaluate("/tabela_kursow", dom) # BEGIN Polish - rates table name
268 #if isinstance(node, list) :
269 # node = node[0]
270@@ -535,7 +528,7 @@
271 #we dynamically update supported currencies
272 self.supported_currency_array = dom.xpath('/tabela_kursow/pozycja/kod_waluty/text()', namespaces=ns)
273 self.supported_currency_array.append('PLN')
274- logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Supported currencies = " + str(self.supported_currency_array))
275+ _logger.debug("Supported currencies = " + str(self.supported_currency_array))
276 self.validate_cur(main_currency)
277 if main_currency != 'PLN':
278 main_curr_data = self.rate_retrieve(dom, ns, main_currency)
279@@ -553,5 +546,5 @@
280 else:
281 rate = main_rate * curr_data['rate_ref'] / curr_data['rate_currency']
282 self.updated_currency[curr] = rate
283- logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
284+ _logger.debug("Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
285 return self.updated_currency, self.log_info
286
287=== modified file 'currency_rate_update/currency_rate_update.xml'
288--- currency_rate_update/currency_rate_update.xml 2011-08-12 12:35:23 +0000
289+++ currency_rate_update/currency_rate_update.xml 2013-02-21 18:08:22 +0000
290@@ -4,12 +4,10 @@
291 <record model="ir.ui.view" id="currency_rate_update_tree">
292 <field name="name">Update Rates service</field>
293 <field name="model">currency.rate.update.service</field>
294- <field name="type">tree</field>
295 <field name="arch" type="xml">
296 <tree string="Rates">
297 <field name="service"/>
298 <field name="currency_to_update"/>
299- <field name="company_id"/>
300
301 </tree>
302 </field>
303@@ -18,11 +16,9 @@
304 <record model="ir.ui.view" id="currency_rate_update_form">
305 <field name="name">Update Rates</field>
306 <field name="model">currency.rate.update.service</field>
307- <field name="type">form</field>
308 <field name="arch" type="xml">
309 <form string="Rate">
310 <field name="service"/>
311- <field name="company_id"/>
312 <field name="max_delta_days"/>
313 <separator string="Currencies to update with this service" colspan="4"/>
314 <field name="currency_to_update" colspan="4" nolabel="1"/>
315
316=== modified file 'currency_rate_update/security/security.xml'
317--- currency_rate_update/security/security.xml 2011-09-01 13:58:58 +0000
318+++ currency_rate_update/security/security.xml 2013-02-21 18:08:22 +0000
319@@ -1,6 +1,6 @@
320 <?xml version="1.0" ?>
321 <openerp>
322- <data>
323+ <data noupdate="1">
324 <record id="ir_model_access_currencyrateupdate0" model="ir.model.access">
325 <field name="model_id" ref="currency_rate_update.model_currency_rate_update"/>
326 <field eval="1" name="perm_read"/>
327
328=== removed directory 'currency_rate_update/wizard'
329=== removed file 'currency_rate_update/wizard/__init__.py'
330--- currency_rate_update/wizard/__init__.py 2011-08-12 12:35:23 +0000
331+++ currency_rate_update/wizard/__init__.py 1970-01-01 00:00:00 +0000
332@@ -1,30 +0,0 @@
333-# -*- coding: utf-8 -*-
334-##############################################################################
335-#
336-# Copyright (c) 2008 Camtocamp SA
337-# @author JB Aubort
338-# $Id$
339-#
340-# WARNING: This program as such is intended to be used by professional
341-# programmers who take the whole responsability of assessing all potential
342-# consequences resulting from its eventual inadequacies and bugs
343-# End users who are looking for a ready-to-use solution with commercial
344-# garantees and support are strongly adviced to contract a Free Software
345-# Service Company
346-#
347-# This program is Free Software; you can redistribute it and/or
348-# modify it under the terms of the GNU General Public License
349-# as published by the Free Software Foundation; either version 2
350-# of the License, or (at your option) any later version.
351-#
352-# This program is distributed in the hope that it will be useful,
353-# but WITHOUT ANY WARRANTY; without even the implied warranty of
354-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
355-# GNU General Public License for more details.
356-#
357-# You should have received a copy of the GNU General Public License
358-# along with this program; if not, write to the Free Software
359-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
360-#
361-##############################################################################
362-

Subscribers

People subscribed via source and target branches