clearcorp team mailing list archive
-
clearcorp team
-
Mailing list archive
-
Message #00699
lp:~ss-dtic/openerp-ccorp-addons/6.1-base_import_exchange_rates into lp:openerp-ccorp-addons/6.1
Miguel Gutierrez has proposed merging lp:~ss-dtic/openerp-ccorp-addons/6.1-base_import_exchange_rates into lp:openerp-ccorp-addons/6.1.
Requested reviews:
CLEARCORP drivers (clearcorp-drivers)
For more details, see:
https://code.launchpad.net/~ss-dtic/openerp-ccorp-addons/6.1-base_import_exchange_rates/+merge/156380
Fix base_import_exchange_rates module
--
https://code.launchpad.net/~ss-dtic/openerp-ccorp-addons/6.1-base_import_exchange_rates/+merge/156380
Your team CLEARCORP development team is subscribed to branch lp:openerp-ccorp-addons/6.1.
=== modified file 'base_import_exchange_rates/__init__.py'
--- base_import_exchange_rates/__init__.py 2012-06-30 22:41:06 +0000
+++ base_import_exchange_rates/__init__.py 2013-04-01 17:40:31 +0000
@@ -27,7 +27,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
-
+import res_currency
import currency_rate_update
import company
import wizard
=== modified file 'base_import_exchange_rates/__terp__.py'
--- base_import_exchange_rates/__terp__.py 2012-06-30 22:41:06 +0000
+++ base_import_exchange_rates/__terp__.py 2013-04-01 17:40:31 +0000
@@ -8,17 +8,17 @@
# Inspired directly from Camp2Camp module c2c_currency_rate_update
# The module was copied and modified in order to provide enough flexibility to extend it
# to use as a generic WebService XML data importer into OpenERP.
-#
+#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
-#
+#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
-#
+#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
-#
+#
# THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
@@ -28,11 +28,11 @@
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
+#
# The views and conclusions contained in the software and documentation are those of the
# authors and should not be interpreted as representing official policies, either expressed
# or implied, of ClearCorp S.A..
-#
+#
##############################################################################
{
@@ -43,16 +43,16 @@
'website': 'http://clearcorp.co.cr',
'category': 'Generic Modules/Base',
'description': """Import exchange rates from XML web service.
- Configuration:
- 1) Install the module.
- 2) Go to Administration > Company, open the company you want to syncronize.
- 3) in the page ´Currency auto update configuration´ you can configure wich webservice you wan to use
- the company the currency is related to, and the currecy.
- 4) You have to go to Administration>Configuration>Planification , and configure the interval you want for the method to syncronize.
-
-
-
-
+ Configuration:
+ 1) Install the module.
+ 2) Go to Administration > Company, open the company you want to syncronize.
+ 3) in the page ´Currency auto update configuration´ you can configure wich webservice you wan to use
+ the company the currency is related to, and the currecy.
+ 4) You have to go to Administration>Configuration>Planification , and configure the interval you want for the method to syncronize.
+
+
+
+
""",
'depends': ['account'],
'init_xml': ['security/security.xml'],
@@ -60,6 +60,7 @@
'update_xml': [
'currency_rate_update.xml',
'company_view.xml',
+ 'res_currency_view.xml',
],
'license': 'Other OSI approved licence',
'installable': True,
=== modified file 'base_import_exchange_rates/currency_rate_update.py'
--- base_import_exchange_rates/currency_rate_update.py 2012-06-30 22:41:06 +0000
+++ base_import_exchange_rates/currency_rate_update.py 2013-04-01 17:40:31 +0000
@@ -2,8 +2,8 @@
##############################################################################
#
# Copyright (c) 2009 Camptocamp SA
-# @author Nicolas Bessi
-# @source JBA and AWST inpiration
+# @author Nicolas Bessi
+# @source JBA and AWST inpiration
# @contributor Grzegorz Grzelak (grzegorz.grzelak@xxxxxxxxxxxxx),
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
@@ -42,17 +42,17 @@
class res_currency_rate_update_service(osv.osv):
- """Class thats tell for wich services wich currencies
+ """Class thats tell for wich services wich currencies
have to be updated"""
_name = "res.currency.rate.update.service"
_description = "Currency Rate Update"
_columns = {
- ##list of webservicies the value sould be a class name
- 'service' : fields.selection(
+ ##list of webservicies the value sould be a class name
+ 'service' : fields.selection(
[
#('Admin_ch_getter','Admin.ch'),
#('ECB_getter','European Central Bank'),
- #('NYFB_getter','Federal Reserve Bank of NY'),
+ #('NYFB_getter','Federal Reserve Bank of NY'),
#('Google_getter','Google Finance'),
#('Yahoo_getter','Yahoo Finance '),
#('PL_NBP_getter','Narodowy Bank Polski'), # Added for polish rates
@@ -61,7 +61,7 @@
"Webservice to use",
required = True
),
- ##list of currency to update
+ ##list of currency to update
'currency_to_update' : fields.many2many(
'res.currency',
'res_curreny_auto_udate_rel',
@@ -69,7 +69,7 @@
'currency_id',
'currency to update with this service',
),
- #back ref
+ #back ref
'company_id' : fields.many2one(
'res.company',
'linked company',
@@ -79,8 +79,8 @@
}
_sql_constraints = [
(
- 'curr_service_unique',
- 'unique (service, company_id)',
+ 'curr_service_unique',
+ 'unique (service, company_id)',
_('You can use a service one time per company !')
)
]
@@ -88,7 +88,7 @@
res_currency_rate_update_service()
class Currency_rate_update(osv.osv):
- """Class that handle an ir cron call who will
+ """Class that handle an ir cron call who will
update currencies based on a web url"""
_name = "currency.rate.update"
_description = "Currency Rate Update"
@@ -103,7 +103,7 @@
'doall' : True,
'model' : 'currency.rate.update',
'function' : 'run_currency_update',
- 'args' : '()',
+ 'args' : '()',
}
logger2 = logging.getLogger('currency.rate.update')
logger = netsvc.Logger()
@@ -111,45 +111,45 @@
MOD_NAME = 'c2c_currency_rate_update: '
def get_cron_id(self, cr, uid, context):
"""return the updater cron's id. Create one if the cron does not exists """
-
+
cron_id = 0
cron_obj = self.pool.get('ir.cron')
- try:
+ try:
#find the cron that send messages
cron_id = cron_obj.search(
- cr,
- uid,
+ cr,
+ uid,
[
- ('function', 'ilike', self.cron['function']),
+ ('function', 'ilike', self.cron['function']),
('model', 'ilike', self.cron['model'])
- ],
+ ],
context={
'active_test': False
- }
+ }
)
cron_id = int(cron_id[0])
except Exception,e :
self.logger.notifyChannel(
- self.LOG_NAME,
- netsvc.LOG_INFO,
+ self.LOG_NAME,
+ netsvc.LOG_INFO,
'warning cron not found one will be created'
)
print 'warning cron not found one will be created'
pass # ignore if the cron is missing cause we are going to create it in db
-
+
#the cron does not exists
if not cron_id :
#translate
self.cron['name'] = _('Currency Rate Update')
cron_id = cron_obj.create(cr, uid, self.cron, context)
-
+
return cron_id
-
+
def save_cron(self, cr, uid, datas, context={}):
"""save the cron config data should be a dict"""
#modify the cron
- cron_id = self.get_cron_id(cr, uid, context)
- result = self.pool.get('ir.cron').write(cr, uid, [cron_id], datas)
+ cron_id = self.get_cron_id(cr, uid, context)
+ result = self.pool.get('ir.cron').write(cr, uid, [cron_id], datas)
def run_currency_update(self, cr, uid):
"update currency at the given frequence"
@@ -158,7 +158,7 @@
rate_obj = self.pool.get('res.currency.rate')
companies = self.pool.get('res.company').search(cr, uid, [])
for comp in self.pool.get('res.company').browse(cr, uid, companies):
- ##the multi company currency can beset or no so we handle
+ ##the multi company currency can beset or no so we handle
##the two case
if not comp.auto_currency_up :
continue
@@ -180,13 +180,16 @@
for curr in service.currency_to_update :
if curr.name not in res:
continue
-
+
for name, rate in res[curr.name].iteritems():
rate_ids = rate_obj.search(cr, uid, [('currency_id','=',curr.id),('name','=',name)])
if not len(rate_ids):
+ if curr.import_inverted:
+ rate = 1/rate
+
vals = {'currency_id': curr.id, 'rate': rate, 'name': name}
rate_obj.create(cr, uid, vals)
-
+
note = note + "\n currency updated at %s "\
%(str(datetime.today()))
note = note + (log_info or '')
@@ -196,10 +199,10 @@
%(str(datetime.today()), str(e))
self.logger.notifyChannel(self.LOG_NAME, netsvc.LOG_INFO, str(e))
service.write({'note':error_msg})
-
+
def get_next_date(self, cr, uid, context=None):
tomorrow=datetime.date.today() + datetime.timedelta(days=1)
- pday= tomorrow.day
+ pday= tomorrow.day
pmonth = tomorrow.month
pyear = tomorrow.year
phour = "02:00:00"
@@ -213,12 +216,12 @@
-
-
+
+
Currency_rate_update()
### Error Definition as specified in python 2.6 PEP
-class AbstractClassError(Exception):
+class AbstractClassError(Exception):
def __str__(self):
return 'Abstract Class'
def __repr__(self):
@@ -230,25 +233,25 @@
def __repr__(self):
return 'Abstract Method'
-class UnknowClassError(Exception):
+class UnknowClassError(Exception):
def __str__(self):
return 'Unknown Class'
def __repr__(self):
return 'Unknown Class'
-class UnsuportedCurrencyError(Exception):
+class UnsuportedCurrencyError(Exception):
def __init__(self, value):
self.curr = value
def __str__(self):
return 'Unsupported currency '+self.curr
def __repr__(self):
return 'Unsupported currency '+self.curr
-
-### end of error definition
+
+### end of error definition
class Currency_getter_factory():
- """Factory pattern class that will return
+ """Factory pattern class that will return
a currency getter class base on the name passed
to the register method"""
- def register(self, class_name):
+ def register(self, class_name):
allowed = [
'Admin_ch_getter',
'PL_NBP_getter',
@@ -263,60 +266,60 @@
return class_def()
else :
raise UnknowClassError
-
+
class Curreny_getter_interface(object) :
"Abstract class of currency getter"
-
+
#remove in order to have a dryer code
# def __init__(self):
- # raise AbstractClassError
-
+ # raise AbstractClassError
+
log_info = " "
-
+
supported_currency_array = \
['AFN', 'ALL', 'DZD', 'USD', 'USD', 'USD', 'EUR', 'AOA', 'XCD', 'XCD', 'ARS',
-'AMD', 'AWG', 'AUD', 'EUR', 'AZN', 'EUR', 'BSD', 'BHD', 'EUR', 'BDT', 'BBD',
-'XCD', 'BYR', 'EUR', 'BZD', 'XOF', 'BMD', 'BTN', 'INR', 'BOB', 'ANG', 'BAM',
-'BWP', 'NOK', 'BRL', 'GBP', 'USD', 'USD', 'BND', 'BGN', 'XOF', 'MMK', 'BIF',
-'XOF', 'USD', 'KHR', 'XAF', 'CAD', 'EUR', 'CVE', 'KYD', 'XAF', 'XAF', 'CLP',
-'CNY', 'AUD', 'AUD', 'COP', 'XAF', 'KMF', 'XPF', 'XAF', 'CDF', 'NZD', 'CRC',
-'HRK', 'CUP', 'ANG', 'EUR', 'CYP', 'CZK', 'DKK', 'DJF', 'XCD', 'DOP', 'EUR',
-'XCD', 'IDR', 'USD', 'EGP', 'EUR', 'SVC', 'USD', 'GBP', 'XAF', 'ETB', 'ERN',
-'EEK', 'ETB', 'EUR', 'FKP', 'DKK', 'FJD', 'EUR', 'EUR', 'EUR', 'XPF', 'XPF',
-'EUR', 'XPF', 'XAF', 'GMD', 'GEL', 'EUR', 'GHS', 'GIP', 'XAU', 'GBP', 'EUR',
-'DKK', 'XCD', 'XCD', 'EUR', 'USD', 'GTQ', 'GGP', 'GNF', 'XOF', 'GYD', 'HTG',
-'USD', 'AUD', 'BAM', 'EUR', 'EUR', 'HNL', 'HKD', 'HUF', 'ISK', 'INR', 'IDR',
-'XDR', 'IRR', 'IQD', 'EUR', 'IMP', 'ILS', 'EUR', 'JMD', 'NOK', 'JPY', 'JEP',
-'JOD', 'KZT', 'AUD', 'KES', 'AUD', 'KPW', 'KRW', 'KWD', 'KGS', 'LAK', 'LVL',
-'LBP', 'LSL', 'ZAR', 'LRD', 'LYD', 'CHF', 'LTL', 'EUR', 'MOP', 'MKD', 'MGA',
-'EUR', 'MWK', 'MYR', 'MVR', 'XOF', 'EUR', 'MTL', 'FKP', 'USD', 'USD', 'EUR',
-'MRO', 'MUR', 'EUR', 'AUD', 'MXN', 'USD', 'USD', 'EUR', 'MDL', 'EUR', 'MNT',
-'EUR', 'XCD', 'MAD', 'MZN', 'MMK', 'NAD', 'ZAR', 'AUD', 'NPR', 'ANG', 'EUR',
-'XCD', 'XPF', 'NZD', 'NIO', 'XOF', 'NGN', 'NZD', 'AUD', 'USD', 'NOK', 'OMR',
-'PKR', 'USD', 'XPD', 'PAB', 'USD', 'PGK', 'PYG', 'PEN', 'PHP', 'NZD', 'XPT',
-'PLN', 'EUR', 'STD', 'USD', 'QAR', 'EUR', 'RON', 'RUB', 'RWF', 'STD', 'ANG',
-'MAD', 'XCD', 'SHP', 'XCD', 'XCD', 'EUR', 'XCD', 'EUR', 'USD', 'WST', 'EUR',
-'SAR', 'SPL', 'XOF', 'RSD', 'SCR', 'SLL', 'XAG', 'SGD', 'ANG', 'ANG', 'EUR',
-'EUR', 'SBD', 'SOS', 'ZAR', 'GBP', 'GBP', 'EUR', 'XDR', 'LKR', 'SDG', 'SRD',
-'NOK', 'SZL', 'SEK', 'CHF', 'SYP', 'TWD', 'RUB', 'TJS', 'TZS', 'THB', 'IDR',
-'TTD', 'XOF', 'NZD', 'TOP', 'TTD', 'TND', 'TRY', 'TMM', 'USD', 'TVD', 'UGX',
-'UAH', 'AED', 'GBP', 'USD', 'USD', 'UYU', 'USD', 'UZS', 'VUV', 'EUR', 'VEB',
+'AMD', 'AWG', 'AUD', 'EUR', 'AZN', 'EUR', 'BSD', 'BHD', 'EUR', 'BDT', 'BBD',
+'XCD', 'BYR', 'EUR', 'BZD', 'XOF', 'BMD', 'BTN', 'INR', 'BOB', 'ANG', 'BAM',
+'BWP', 'NOK', 'BRL', 'GBP', 'USD', 'USD', 'BND', 'BGN', 'XOF', 'MMK', 'BIF',
+'XOF', 'USD', 'KHR', 'XAF', 'CAD', 'EUR', 'CVE', 'KYD', 'XAF', 'XAF', 'CLP',
+'CNY', 'AUD', 'AUD', 'COP', 'XAF', 'KMF', 'XPF', 'XAF', 'CDF', 'NZD', 'CRC',
+'HRK', 'CUP', 'ANG', 'EUR', 'CYP', 'CZK', 'DKK', 'DJF', 'XCD', 'DOP', 'EUR',
+'XCD', 'IDR', 'USD', 'EGP', 'EUR', 'SVC', 'USD', 'GBP', 'XAF', 'ETB', 'ERN',
+'EEK', 'ETB', 'EUR', 'FKP', 'DKK', 'FJD', 'EUR', 'EUR', 'EUR', 'XPF', 'XPF',
+'EUR', 'XPF', 'XAF', 'GMD', 'GEL', 'EUR', 'GHS', 'GIP', 'XAU', 'GBP', 'EUR',
+'DKK', 'XCD', 'XCD', 'EUR', 'USD', 'GTQ', 'GGP', 'GNF', 'XOF', 'GYD', 'HTG',
+'USD', 'AUD', 'BAM', 'EUR', 'EUR', 'HNL', 'HKD', 'HUF', 'ISK', 'INR', 'IDR',
+'XDR', 'IRR', 'IQD', 'EUR', 'IMP', 'ILS', 'EUR', 'JMD', 'NOK', 'JPY', 'JEP',
+'JOD', 'KZT', 'AUD', 'KES', 'AUD', 'KPW', 'KRW', 'KWD', 'KGS', 'LAK', 'LVL',
+'LBP', 'LSL', 'ZAR', 'LRD', 'LYD', 'CHF', 'LTL', 'EUR', 'MOP', 'MKD', 'MGA',
+'EUR', 'MWK', 'MYR', 'MVR', 'XOF', 'EUR', 'MTL', 'FKP', 'USD', 'USD', 'EUR',
+'MRO', 'MUR', 'EUR', 'AUD', 'MXN', 'USD', 'USD', 'EUR', 'MDL', 'EUR', 'MNT',
+'EUR', 'XCD', 'MAD', 'MZN', 'MMK', 'NAD', 'ZAR', 'AUD', 'NPR', 'ANG', 'EUR',
+'XCD', 'XPF', 'NZD', 'NIO', 'XOF', 'NGN', 'NZD', 'AUD', 'USD', 'NOK', 'OMR',
+'PKR', 'USD', 'XPD', 'PAB', 'USD', 'PGK', 'PYG', 'PEN', 'PHP', 'NZD', 'XPT',
+'PLN', 'EUR', 'STD', 'USD', 'QAR', 'EUR', 'RON', 'RUB', 'RWF', 'STD', 'ANG',
+'MAD', 'XCD', 'SHP', 'XCD', 'XCD', 'EUR', 'XCD', 'EUR', 'USD', 'WST', 'EUR',
+'SAR', 'SPL', 'XOF', 'RSD', 'SCR', 'SLL', 'XAG', 'SGD', 'ANG', 'ANG', 'EUR',
+'EUR', 'SBD', 'SOS', 'ZAR', 'GBP', 'GBP', 'EUR', 'XDR', 'LKR', 'SDG', 'SRD',
+'NOK', 'SZL', 'SEK', 'CHF', 'SYP', 'TWD', 'RUB', 'TJS', 'TZS', 'THB', 'IDR',
+'TTD', 'XOF', 'NZD', 'TOP', 'TTD', 'TND', 'TRY', 'TMM', 'USD', 'TVD', 'UGX',
+'UAH', 'AED', 'GBP', 'USD', 'USD', 'UYU', 'USD', 'UZS', 'VUV', 'EUR', 'VEB',
'VEF', 'VND', 'USD', 'USD', 'USD', 'XPF', 'MAD', 'YER', 'ZMK', 'ZWD']
##updated currency this arry will contain the final result
updated_currency = {}
-
+
def get_updated_currency(self, currency_array, main_currency) :
"""Interface method that will retriev the currency
This function has to be reinplemented in child"""
raise AbstractMethodError
-
+
def validate_cur(self, currency) :
"""Validate if the currency to update is supported"""
if currency not in self.supported_currency_array :
- raise UnsuportedCurrencyError(currency)
-
+ raise UnsuportedCurrencyError(currency)
+
def get_url(self, url):
"""Return a string of a get url query"""
try:
@@ -329,12 +332,12 @@
raise osv.except_osv('Error !', self.MOD_NAME+'Unable to import urllib !')
except IOError:
raise osv.except_osv('Error !', self.MOD_NAME+'Web Service does not exist !')
-
-#Yahoo ###################################################################################
+
+#Yahoo ###################################################################################
class Yahoo_getter(Curreny_getter_interface) :
"""Implementation of Currency_getter_factory interface
for Yahoo finance service"""
-
+
def get_updated_currency(self, currency_array, main_currency):
"""implementation of abstract method of Curreny_getter_interface"""
self.validate_cur(main_currency)
@@ -349,15 +352,15 @@
self.updated_currency[curr] = val
else :
raise Exception('Could not update the %s'%(curr))
-
+
return self.updated_currency, self.log_info # empty string added by polish changes
-##Admin CH ############################################################################
+##Admin CH ############################################################################
class Admin_ch_getter(Curreny_getter_interface) :
"""Implementation of Currency_getter_factory interface
for Admin.ch service"""
-
+
def rate_retrieve(self, node) :
- """ Parse a dom node to retrieve
+ """ Parse a dom node to retrieve
currencies data"""
res = {}
if isinstance(node, list) :
@@ -376,7 +379,7 @@
currency_array.remove(main_currency)
from xml.dom.minidom import parseString
from xml import xpath
- rawfile = self.get_url(url)
+ rawfile = self.get_url(url)
dom = parseString(rawfile)
#we dynamically update supported currencies
self.supported_currency_array = []
@@ -384,7 +387,7 @@
for el in xpath.Evaluate("/wechselkurse/devise/@code", dom):
self.supported_currency_array.append(el.value.upper())
self.validate_cur(main_currency)
- #The XML give the value in franc for 1 XX if we are in CHF
+ #The XML give the value in franc for 1 XX if we are in CHF
#we want to have the value for 1 xx in chf
#if main currency is not CHF we have to apply a computation on it
if main_currency != 'CHF':
@@ -394,7 +397,7 @@
main_rate = tmp_data['rate_currency'] / tmp_data['rate_ref']
for curr in currency_array :
curr_xpath = "/wechselkurse/devise[@code='%s']"%(curr.lower())
- for node in xpath.Evaluate(curr_xpath, dom):
+ for node in xpath.Evaluate(curr_xpath, dom):
tmp_data = self.rate_retrieve(node)
#Source is in CHF, so we transform it into reference currencies
if main_currency == 'CHF' :
@@ -405,13 +408,13 @@
self.updated_currency[curr] = rate
return self.updated_currency, self.log_info # empty string added by polish changes
-## ECB getter ############################################################################
+## ECB getter ############################################################################
class ECB_getter(Curreny_getter_interface) :
"""Implementation of Currency_getter_factory interface
for ECB service"""
-
+
def rate_retrieve(self, node) :
- """ Parse a dom node to retrieve
+ """ Parse a dom node to retrieve
currencies data"""
res = {}
if isinstance(node, list) :
@@ -428,7 +431,7 @@
currency_array.remove(main_currency)
from xml.dom.minidom import parseString
from xml import xpath
- rawfile = self.get_url(url)
+ rawfile = self.get_url(url)
dom = parseString(rawfile)
#we dynamically update supported currencies
self.supported_currency_array = []
@@ -438,18 +441,18 @@
self.validate_cur(main_currency)
for curr in currency_array :
curr_xpath = "//Cube/Cube/Cube[@currency='%s']"%(curr.upper())
- for node in xpath.Evaluate(curr_xpath, dom):
+ for node in xpath.Evaluate(curr_xpath, dom):
tmp_data = self.rate_retrieve(node)
self.updated_currency[curr] = tmp_data['rate_currency']
return self.updated_currency, self.log_info # empty string added by polish changes
-##PL NBP ############################################################################
+##PL NBP ############################################################################
class PL_NBP_getter(Curreny_getter_interface) : # class added according to polish needs = based on class Admin_ch_getter
"""Implementation of Currency_getter_factory interface
for PL NBP service"""
-
+
def rate_retrieve(self, node) :
- """ Parse a dom node to retrieve
+ """ Parse a dom node to retrieve
currencies data"""
res = {}
if isinstance(node, list) :
@@ -470,12 +473,12 @@
currency_array.remove(main_currency)
from xml.dom.minidom import parseString
from xml import xpath
- rawfile = self.get_url(url)
+ rawfile = self.get_url(url)
dom = parseString(rawfile)
node = xpath.Evaluate("/tabela_kursow", dom) # BEGIN Polish - rates table name
if isinstance(node, list) :
node = node[0]
- self.log_info = node.getElementsByTagName('numer_tabeli')[0].childNodes[0].data
+ self.log_info = node.getElementsByTagName('numer_tabeli')[0].childNodes[0].data
self.log_info = self.log_info + " " + node.getElementsByTagName('data_publikacji')[0].childNodes[0].data # END Polish - rates table name
#we dynamically update supported currencies
@@ -486,19 +489,19 @@
self.validate_cur(main_currency)
for curr in currency_array :
curr_xpath = "/tabela_kursow/pozycja[kod_waluty='%s']"%(curr.upper())
- for node in xpath.Evaluate(curr_xpath, dom):
+ for node in xpath.Evaluate(curr_xpath, dom):
tmp_data = self.rate_retrieve(node)
#Source is in PLN, so we transform it into reference currencies
rate = 1 / (tmp_data['rate_currency'] / tmp_data['rate_ref'])
self.updated_currency[curr] = rate
return self.updated_currency, self.log_info
-##PL NBP ############################################################################
+##PL NBP ############################################################################
class bccr_getter(Curreny_getter_interface) : # class added for CR rates
"""Implementation of Currency_getter_factory interface
for PL NBP service"""
-
+
def get_updated_currency(self, cr, uid, currency_array, main_currency):
logger2 = logging.getLogger('bccr_getter')
"""implementation of abstract method of Curreny_getter_interface"""
@@ -514,12 +517,12 @@
# Get the last rate for the selected currency
currency_obj = pooler.get_pool(cr.dbname).get('res.currency')
currency_rate_obj = pooler.get_pool(cr.dbname).get('res.currency.rate')
-
+
currency_id = currency_obj.search(cr, uid, [('name','=',curr)])
if not currency_id:
continue
-
+
last_rate_id = currency_rate_obj.search(cr, uid, [('currency_id','in',currency_id)], order='name DESC', limit=1)
last_rate = currency_rate_obj.browse(cr, uid, last_rate_id)
if len(last_rate):
@@ -529,12 +532,12 @@
last_rate_date = today
url = url1 + last_rate_date + url2
-
+
if curr.upper() == 'CRC':
url = url + '318' #318: indicator number for CRC sale rate
elif curr.upper() == 'EUR':
url = url + '333' #333: indicator number for EUR rate
-
+
if url:
#debug(url)
logger2.info(url)
=== added file 'base_import_exchange_rates/res_currency.py'
--- base_import_exchange_rates/res_currency.py 1970-01-01 00:00:00 +0000
+++ base_import_exchange_rates/res_currency.py 2013-04-01 17:40:31 +0000
@@ -0,0 +1,45 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# base_currency_symbol.py
+# base_currency_symbol
+# First author: Carlos Vásquez <carlos.vasquez@xxxxxxxxxxxxxxx> (ClearCorp S.A.)
+# Copyright (c) 2010-TODAY ClearCorp S.A. (http://clearcorp.co.cr). All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are
+# permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of
+# conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND ANY EXPRESS OR IMPLIED
+# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# The views and conclusions contained in the software and documentation are those of the
+# authors and should not be interpreted as representing official policies, either expressed
+# or implied, of ClearCorp S.A..
+#
+##############################################################################
+
+from osv import osv,fields
+
+class res_currency(osv.osv):
+
+ _inherit = 'res.currency'
+
+ _columns = {
+ #True if need to change the rate= 1/rate
+ 'import_inverted': fields.boolean('Import Inverted'),
+ }
+res_currency()
=== added file 'base_import_exchange_rates/res_currency_view.xml'
--- base_import_exchange_rates/res_currency_view.xml 1970-01-01 00:00:00 +0000
+++ base_import_exchange_rates/res_currency_view.xml 2013-04-01 17:40:31 +0000
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+ <data>
+ <!--
+ Resource: res.currency
+ -->
+ <record id="view_currency_form_rate" model="ir.ui.view">
+ <field name="name">res.currency.rate_update</field>
+ <field name="model">res.currency</field>
+ <field name="type">form</field>
+ <field name="inherit_id" ref="base.view_currency_form"/>
+ <field name="arch" type="xml">
+ <field name="accuracy" position="after">
+ <field name="import_inverted"/>
+ </field>
+ </field>
+ </record>
+ </data>
+</openerp>
Follow ups