[IMP] clean spaces

This commit is contained in:
Yannick Vaucher
2013-03-19 11:55:40 +01:00
parent 19454f3f79
commit 62d8bd3095
4 changed files with 112 additions and 113 deletions

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# company.py
# c2c_currency_update
# @author Nicolas Bessi
# @author Nicolas Bessi
# Copyright (c) 2009 CamptoCamp. All rights reserved.
##############################################################################
#
@@ -33,7 +33,7 @@ from openerp.osv import fields, osv
class res_company(osv.Model):
"""override company to add currency update"""
def _multi_curr_enable(self, cr, uid, ids, field_name, arg, context={}):
"check if multi company currency is enabled"
result = {}
@@ -44,8 +44,8 @@ class res_company(osv.Model):
for id in ids:
result[id] = enable
return result
def button_refresh_currency(self, cr, uid, ids, context=None):
"""Refrech the currency !!for all the company
now"""
@@ -55,18 +55,18 @@ class res_company(osv.Model):
except Exception, e:
return False
return True
def on_change_auto_currency_up(self, cr, uid, id, value):
"""handle the activation of the currecny update on compagnies.
There are two ways of implementing multi_company currency,
There are two ways of implementing multi_company currency,
the currency is shared or not. The module take care of the two
ways. If the currency are shared, you will only be able to set
auto update on one company, this will avoid to have unusefull cron
object running.
ways. If the currency are shared, you will only be able to set
auto update on one company, this will avoid to have unusefull cron
object running.
If yours currency are not share you will be able to activate the
auto update on each separated company"""
if len(id) :
id = id[0]
else :
@@ -78,12 +78,12 @@ class res_company(osv.Model):
# this statement is here beacaus we do no want to save in case of error
self.write(cr, uid, id,{'auto_currency_up':value})
for comp in compagnies :
if self.browse(cr, uid, comp).auto_currency_up:
if self.browse(cr, uid, comp).auto_currency_up:
activate_cron = 't'
break
self.pool.get('currency.rate.update').save_cron(
cr,
uid,
cr,
uid,
{'active':activate_cron}
)
return {}
@@ -94,10 +94,10 @@ class res_company(osv.Model):
#we ensure taht we did not have write a true value
self.write(cr, uid, id,{'auto_currency_up':False})
return {
'value':{
'value':{
'auto_currency_up':False
},
'warning':{
'title':"Warning",
'message': 'Yon can not activate auto currency '+\
@@ -107,44 +107,44 @@ class res_company(osv.Model):
}
self.write(cr, uid, id,{'auto_currency_up':value})
for comp in compagnies :
if self.browse(cr, uid, comp).auto_currency_up:
if self.browse(cr, uid, comp).auto_currency_up:
activate_cron = 't'
self.pool.get('currency.rate.update').save_cron(
cr,
uid,
cr,
uid,
{'active':activate_cron}
)
break
return {}
def on_change_intervall(self, cr, uid, id, interval) :
###Function that will update the cron
###freqeuence
self.pool.get('currency.rate.update').save_cron(
cr,
uid,
cr,
uid,
{'interval_type':interval}
)
compagnies = self.search(cr, uid, [])
for comp in compagnies :
self.write(cr, uid, comp,{'interval_type':interval})
return {}
_inherit = "res.company"
_columns = {
### activate the currency update
'auto_currency_up': fields.boolean('Automatical update of the currency this company'),
'services_to_use' : fields.one2many(
'currency.rate.update.service',
'currency.rate.update.service',
'company_id',
'Currency update services'
'Currency update services'
),
###predifine cron frequence
'interval_type': fields.selection(
[
('days','Day(s)'),
('weeks', 'Week(s)'),
('days','Day(s)'),
('weeks', 'Week(s)'),
('months', 'Month(s)')
],
'Currency update frequence',
@@ -152,15 +152,15 @@ class res_company(osv.Model):
also affect other compagnies"""
),
###function field that allows to know the
###mutli company currency implementation
###mutli company currency implementation
'multi_company_currency_enable' : fields.function(
_multi_curr_enable,
method=True,
type='boolean',
_multi_curr_enable,
method=True,
type='boolean',
string="Multi company currency",
help='if this case is not check you can'+\
' not set currency is active on two company'
),
}
}

View File

@@ -21,4 +21,3 @@
</record>
</data>
</openerp>

View File

@@ -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@birdglobe.com), Joel Grand-Guillaume
# Copyright (c) 2010 Alexis de Lattre (alexis@via.ecp.fr)
# - ported XML-based webservices (Admin.ch, ECB, PL NBP) to new XML lib
@@ -52,17 +52,17 @@ from openerp.tools.translate import _
_logger = logging.getLogger(__name__)
class Currency_rate_update_service(osv.Model):
"""Class thats tell for wich services wich currencies
"""Class thats tell for wich services wich currencies
have to be updated"""
_name = "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
@@ -70,7 +70,7 @@ class Currency_rate_update_service(osv.Model):
"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',
@@ -78,7 +78,7 @@ class Currency_rate_update_service(osv.Model):
'currency_id',
'currency to update with this service',
),
#back ref
#back ref
'company_id' : fields.many2one(
'res.company',
'linked company',
@@ -92,8 +92,8 @@ class Currency_rate_update_service(osv.Model):
}
_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 !')
)
]
@@ -112,7 +112,7 @@ class Currency_rate_update_service(osv.Model):
class Currency_rate_update(osv.Model):
"""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"
@@ -127,47 +127,47 @@ class Currency_rate_update(osv.Model):
'doall' : True,
'model' : 'currency.rate.update',
'function' : 'run_currency_update',
'args' : '()',
'args' : '()',
}
LOG_NAME = 'cron-rates'
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 :
_logger.info('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"
@@ -176,7 +176,7 @@ class Currency_rate_update(osv.Model):
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
@@ -212,12 +212,12 @@ class Currency_rate_update(osv.Model):
'rate':res[curr.name],
'name': rate_name
}
rate_obj.create(
rate_obj.create(
cr,
uid,
vals,
)
note = note + "\n%s currency updated. "\
%(datetime.strftime(datetime.today(), '%Y-%m-%d %H:%M:%S'))
note = note + (log_info or '')
@@ -227,11 +227,11 @@ class Currency_rate_update(osv.Model):
%(datetime.strftime(datetime.today(), '%Y-%m-%d %H:%M:%S'), str(e))
_logger.info(str(e))
service.write({'note':error_msg})
### Error Definition as specified in python 2.6 PEP
class AbstractClassError(Exception):
class AbstractClassError(Exception):
def __str__(self):
return 'Abstract Class'
def __repr__(self):
@@ -243,25 +243,25 @@ class AbstractMethodError(Exception):
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',
@@ -275,60 +275,60 @@ class Currency_getter_factory():
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, max_delta_days) :
"""Interface method that will retrieve 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:
@@ -354,11 +354,11 @@ class Curreny_getter_interface(object) :
_logger.warning("the rate date from ECB (%s) is not today's date", rate_date_str)
#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, max_delta_days):
"""implementation of abstract method of Curreny_getter_interface"""
self.validate_cur(main_currency)
@@ -373,7 +373,7 @@ class Yahoo_getter(Curreny_getter_interface) :
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 ############################################################################
class Admin_ch_getter(Curreny_getter_interface) :

View File

@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<openerp>
<data>
<openerp>
<data>
<record model="ir.ui.view" id="currency_rate_update_tree">
<field name="name">Update Rates service</field>
<field name="model">currency.rate.update.service</field>
@@ -12,7 +12,7 @@
</tree>
</field>
</record>
<record model="ir.ui.view" id="currency_rate_update_form">
<field name="name">Update Rates</field>
<field name="model">currency.rate.update.service</field>
@@ -23,10 +23,10 @@
<separator string="Currencies to update with this service" colspan="4"/>
<field name="currency_to_update" colspan="4" nolabel="1"/>
<separator string="Logs" colspan="4"/>
<field name="note" colspan="4" nolabel="1"/>
<field name="note" colspan="4" nolabel="1"/>
</form>
</field>
</record>
</data>
</openerp>