Merge lp:~cv.clearcorp/openerp-ccorp-addons/7.0-fix_bug_exchange_rate into lp:openerp-ccorp-addons/7.0

Proposed by Carlos Vásquez (ClearCorp)
Status: Merged
Merged at revision: 822
Proposed branch: lp:~cv.clearcorp/openerp-ccorp-addons/7.0-fix_bug_exchange_rate
Merge into: lp:openerp-ccorp-addons/7.0
Diff against target: 63 lines (+15/-13)
2 files modified
currency_rate_update_BCCR/currency_rate_update.py (+14/-12)
currency_rate_update_BCCR/res_currency.py (+1/-1)
To merge this branch: bzr merge lp:~cv.clearcorp/openerp-ccorp-addons/7.0-fix_bug_exchange_rate
Reviewer Review Type Date Requested Status
ClearCorp drivers Pending
Review via email: mp+212212@code.launchpad.net

Description of the change

[FIX] Fix bug when currency_rate object is created. Fix datetime and add a comprobation for case when second_rate doesn't exist in currency

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'currency_rate_update_BCCR/currency_rate_update.py'
2--- currency_rate_update_BCCR/currency_rate_update.py 2014-03-19 17:36:05 +0000
3+++ currency_rate_update_BCCR/currency_rate_update.py 2014-03-21 17:38:37 +0000
4@@ -73,8 +73,7 @@
5 #get_update_currency return a dictionary with rate and name's currency
6 #receive a array with currency to update
7 res_sale, res_purchase, log_info = getter.get_updated_currency(cr, uid, [currency_id.name], '') #main_currency for this method is not necessary
8- rate_name = time.strftime('%Y-%m-%d')
9-
10+
11 #In res_currency_service, name is date when the rate is updated
12 for date, rate in res_sale[currency_id.name].iteritems():
13 rate_ids = rate_obj.search(cr, uid, [('currency_id','=',currency_id.id),('name','=',date)])
14@@ -83,17 +82,21 @@
15 rate = float(rate)
16 if currency_id.sequence > res_currency_base.sequence:
17 rate = 1.0/float(rate)
18- vals = {'currency_id': currency_id.id, 'rate': rate, 'name': date} #add purchase exchange rate
19+ vals = {'currency_id': currency_id.id, 'rate': rate, 'name': datetime.strptime(date,"%Y-%m-%d")}
20
21 #purchase rate
22- second_rate = res_purchase[currency_id.name][date]
23- if currency_id.sequence > res_currency_base.sequence:
24- second_rate = 1.0/float(second_rate)
25- vals.update({'second_rate': second_rate})
26- rate_obj.create(cr, uid, vals)
27-
28- note = "Currency sale and purchase rate " + currency_id.name + " updated at %s "\
29- %(str(datetime.today()))
30+ if currency_id.second_rate: #check if currency has second_rate activated option
31+ second_rate = res_purchase[currency_id.name][date]
32+ if currency_id.sequence > res_currency_base.sequence:
33+ second_rate = 1.0/float(second_rate)
34+ vals.update({'second_rate': second_rate})
35+ else:
36+ vals.update({'second_rate': 0.0})
37+
38+ x = rate_obj.create(cr, uid, vals)
39+
40+ note = "Currency sale and purchase rate " + currency_id.name + " updated at %s "\
41+ %(str(datetime.today()))
42
43 self.logger.notifyChannel(self.LOG_NAME, netsvc.LOG_INFO, str(note))
44
45@@ -221,5 +224,4 @@
46 self.updated_currency_purchase[curr][date_str] = rate
47
48 logger2.info(self.updated_currency_sale)
49- logger2.info(self.updated_currency_purchase)
50 return self.updated_currency_sale, self.updated_currency_purchase, self.log_info
51
52=== modified file 'currency_rate_update_BCCR/res_currency.py'
53--- currency_rate_update_BCCR/res_currency.py 2014-03-16 23:42:27 +0000
54+++ currency_rate_update_BCCR/res_currency.py 2014-03-21 17:38:37 +0000
55@@ -92,7 +92,7 @@
56
57 res.update ({
58 'interval_type': 'days',
59- 'nextcall': datetime.date.today() + datetime.timedelta(days=1), #Get tomorrow's date
60+ 'nextcall': time.strftime("%Y-%m-%d %H:%M:%S", (datetime.today() + timedelta(days=1)).timetuple() ), #tomorrow same time
61 'interval_number': 1,
62 'numbercall': -1,
63 'doall': True,

Subscribers

People subscribed via source and target branches