mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[MRG] [MIG] currency_rate_update to v7
This commit is contained in:
@@ -30,4 +30,3 @@
|
||||
|
||||
import currency_rate_update
|
||||
import company
|
||||
import wizard
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Copyright (c) 2008 Camtocamp SA
|
||||
# @author JB Aubort, Nicolas Bessi, Joel Grand-Guillaume
|
||||
# European Central Bank and Polish National Bank invented by Grzegorz Grzelak
|
||||
# $Id: $
|
||||
# Ported to OpenERP 7.0 by Lorenzo Battistini <lorenzo.battistini@agilebg.com>
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsability of assessing all potential
|
||||
@@ -29,7 +29,7 @@
|
||||
##############################################################################
|
||||
{
|
||||
"name" : "Currency Rate Update",
|
||||
"version" : "0.6",
|
||||
"version" : "0.7",
|
||||
"author" : "Camptocamp",
|
||||
"website" : "http://camptocamp.com",
|
||||
"category" : "Financial Management/Configuration",
|
||||
@@ -79,14 +79,16 @@ found in database.
|
||||
|
||||
Thanks to main contributors: Grzegorz Grzelak, Alexis de Lattre
|
||||
""",
|
||||
"depends" : ["base",
|
||||
"account"], #Added to ensure account security groups are present
|
||||
"init_xml" : ["security/security.xml"],
|
||||
"update_xml" : [
|
||||
"currency_rate_update.xml",
|
||||
"company_view.xml",
|
||||
],
|
||||
"demo_xml" : [],
|
||||
"depends" : [
|
||||
"base",
|
||||
"account", #Added to ensure account security groups are present
|
||||
],
|
||||
"data" : [
|
||||
"currency_rate_update.xml",
|
||||
"company_view.xml",
|
||||
"security/security.xml",
|
||||
],
|
||||
"demo" : [],
|
||||
"active": False,
|
||||
'installable': False
|
||||
'installable': True
|
||||
}
|
||||
|
||||
@@ -29,8 +29,9 @@
|
||||
##############################################################################
|
||||
|
||||
import netsvc
|
||||
from osv import fields, osv
|
||||
class res_company(osv.osv):
|
||||
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={}):
|
||||
@@ -161,4 +162,5 @@ class res_company(osv.osv):
|
||||
' not set currency is active on two company'
|
||||
),
|
||||
}
|
||||
res_company()
|
||||
|
||||
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
<field name="name">res.company.form.inherit</field>
|
||||
<field name="model">res.company</field>
|
||||
<field name="inherit_id" ref="base.view_company_form"/>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<notebook position="inside">
|
||||
<page string="Currency auto update configuration">
|
||||
<field name="auto_currency_up" on_change="on_change_auto_currency_up(auto_currency_up)"/>
|
||||
<field name="interval_type" on_change="on_change_intervall(interval_type)"/>
|
||||
<field name="multi_company_currency_enable"/>
|
||||
<group>
|
||||
<field name="auto_currency_up" on_change="on_change_auto_currency_up(auto_currency_up)"/>
|
||||
<field name="interval_type" on_change="on_change_intervall(interval_type)"/>
|
||||
<field name="multi_company_currency_enable"/>
|
||||
</group>
|
||||
<separator string="Currency updates services" colspan="4"/>
|
||||
<field name="services_to_use" colspan="4" nolabel="1"/>
|
||||
<button name="button_refresh_currency" string="Refresh currencies" type='object' />
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
# For more details, see Launchpad bug #645263
|
||||
# - mecanism to check if rates given by the webservice are "fresh" enough to be
|
||||
# written in OpenERP ('max_delta_days' parameter for each currency update service)
|
||||
# Ported to OpenERP 7.0 by Lorenzo Battistini <lorenzo.battistini@agilebg.com>
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsability of assessing all potential
|
||||
@@ -42,13 +43,15 @@
|
||||
# a webservice to the list of currencies supported by the Webservice
|
||||
# TODO : implement max_delta_days for Yahoo webservice
|
||||
|
||||
from osv import osv, fields
|
||||
from openerp.osv import fields, osv
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
import netsvc
|
||||
from tools.translate import _
|
||||
import logging
|
||||
from openerp.tools.translate import _
|
||||
|
||||
class Currency_rate_update_service(osv.osv):
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class Currency_rate_update_service(osv.Model):
|
||||
"""Class thats tell for wich services wich currencies
|
||||
have to be updated"""
|
||||
_name = "currency.rate.update.service"
|
||||
@@ -107,9 +110,8 @@ class Currency_rate_update_service(osv.osv):
|
||||
(_check_max_delta_days, "'Max delta days' must be >= 0", ['max_delta_days']),
|
||||
]
|
||||
|
||||
Currency_rate_update_service()
|
||||
|
||||
class Currency_rate_update(osv.osv):
|
||||
class Currency_rate_update(osv.Model):
|
||||
"""Class that handle an ir cron call who will
|
||||
update currencies based on a web url"""
|
||||
_name = "currency.rate.update"
|
||||
@@ -128,7 +130,6 @@ class Currency_rate_update(osv.osv):
|
||||
'args' : '()',
|
||||
}
|
||||
|
||||
logger = netsvc.Logger()
|
||||
LOG_NAME = 'cron-rates'
|
||||
MOD_NAME = 'c2c_currency_rate_update: '
|
||||
def get_cron_id(self, cr, uid, context):
|
||||
@@ -151,11 +152,7 @@ class Currency_rate_update(osv.osv):
|
||||
)
|
||||
cron_id = int(cron_id[0])
|
||||
except Exception,e :
|
||||
self.logger.notifyChannel(
|
||||
self.LOG_NAME,
|
||||
netsvc.LOG_INFO,
|
||||
'warning cron not found one will be created'
|
||||
)
|
||||
_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
|
||||
@@ -228,11 +225,10 @@ class Currency_rate_update(osv.osv):
|
||||
except Exception, e:
|
||||
error_msg = note + "\n%s ERROR : %s"\
|
||||
%(datetime.strftime(datetime.today(), '%Y-%m-%d %H:%M:%S'), str(e))
|
||||
self.logger.notifyChannel(self.LOG_NAME, netsvc.LOG_INFO, str(e))
|
||||
_logger.info(str(e))
|
||||
service.write({'note':error_msg})
|
||||
|
||||
|
||||
Currency_rate_update()
|
||||
|
||||
|
||||
### Error Definition as specified in python 2.6 PEP
|
||||
class AbstractClassError(Exception):
|
||||
@@ -355,7 +351,7 @@ class Curreny_getter_interface(object) :
|
||||
rate_date_str = datetime.strftime(rate_date, '%Y-%m-%d')
|
||||
if rate_date_str != datetime.strftime(datetime.today(), '%Y-%m-%d'):
|
||||
self.log_info = "WARNING : the rate date from ECB (%s) is not today's date" % rate_date_str
|
||||
netsvc.Logger().notifyChannel("rate_update", netsvc.LOG_WARNING, "the rate date from ECB (%s) is not today's date" % rate_date_str)
|
||||
_logger.warning("the rate date from ECB (%s) is not today's date", rate_date_str)
|
||||
|
||||
|
||||
#Yahoo ###################################################################################
|
||||
@@ -402,11 +398,10 @@ class Admin_ch_getter(Curreny_getter_interface) :
|
||||
currency_array.remove(main_currency)
|
||||
# Move to new XML lib cf Launchpad bug #645263
|
||||
from lxml import etree
|
||||
logger = netsvc.Logger()
|
||||
logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Admin.ch currency rate service : connecting...")
|
||||
_logger.debug("Admin.ch currency rate service : connecting...")
|
||||
rawfile = self.get_url(url)
|
||||
dom = etree.fromstring(rawfile)
|
||||
logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Admin.ch sent a valid XML file")
|
||||
_logger.debug("Admin.ch sent a valid XML file")
|
||||
adminch_ns = {'def': 'http://www.afd.admin.ch/publicdb/newdb/mwst_kurse'}
|
||||
rate_date = dom.xpath('/def:wechselkurse/def:datum/text()', namespaces=adminch_ns)[0]
|
||||
rate_date_datetime = datetime.strptime(rate_date, '%Y-%m-%d')
|
||||
@@ -416,7 +411,7 @@ class Admin_ch_getter(Curreny_getter_interface) :
|
||||
self.supported_currency_array = [x.upper() for x in self.supported_currency_array]
|
||||
self.supported_currency_array.append('CHF')
|
||||
|
||||
logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Supported currencies = " + str(self.supported_currency_array))
|
||||
_logger.debug("Supported currencies = " + str(self.supported_currency_array))
|
||||
self.validate_cur(main_currency)
|
||||
if main_currency != 'CHF':
|
||||
main_curr_data = self.rate_retrieve(dom, adminch_ns, main_currency)
|
||||
@@ -434,7 +429,7 @@ class Admin_ch_getter(Curreny_getter_interface) :
|
||||
else :
|
||||
rate = main_rate * curr_data['rate_ref'] / curr_data['rate_currency']
|
||||
self.updated_currency[curr] = rate
|
||||
logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
|
||||
_logger.debug("Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
|
||||
return self.updated_currency, self.log_info
|
||||
|
||||
## ECB getter ############################################################################
|
||||
@@ -464,11 +459,10 @@ class ECB_getter(Curreny_getter_interface) :
|
||||
currency_array.remove(main_currency)
|
||||
# Move to new XML lib cf Launchpad bug #645263
|
||||
from lxml import etree
|
||||
logger = netsvc.Logger()
|
||||
logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "ECB currency rate service : connecting...")
|
||||
_logger.debug("ECB currency rate service : connecting...")
|
||||
rawfile = self.get_url(url)
|
||||
dom = etree.fromstring(rawfile)
|
||||
logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "ECB sent a valid XML file")
|
||||
_logger.debug("ECB sent a valid XML file")
|
||||
ecb_ns = {'gesmes': 'http://www.gesmes.org/xml/2002-08-01', 'def': 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref'}
|
||||
rate_date = dom.xpath('/gesmes:Envelope/def:Cube/def:Cube/@time', namespaces=ecb_ns)[0]
|
||||
rate_date_datetime = datetime.strptime(rate_date, '%Y-%m-%d')
|
||||
@@ -476,7 +470,7 @@ class ECB_getter(Curreny_getter_interface) :
|
||||
#we dynamically update supported currencies
|
||||
self.supported_currency_array = dom.xpath("/gesmes:Envelope/def:Cube/def:Cube/def:Cube/@currency", namespaces=ecb_ns)
|
||||
self.supported_currency_array.append('EUR')
|
||||
logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Supported currencies = " + str(self.supported_currency_array))
|
||||
_logger.debug("Supported currencies = " + str(self.supported_currency_array))
|
||||
self.validate_cur(main_currency)
|
||||
if main_currency != 'EUR':
|
||||
main_curr_data = self.rate_retrieve(dom, ecb_ns, main_currency)
|
||||
@@ -491,7 +485,7 @@ class ECB_getter(Curreny_getter_interface) :
|
||||
else:
|
||||
rate = curr_data['rate_currency'] / main_curr_data['rate_currency']
|
||||
self.updated_currency[curr] = rate
|
||||
logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
|
||||
_logger.debug("Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
|
||||
return self.updated_currency, self.log_info
|
||||
|
||||
##PL NBP ############################################################################
|
||||
@@ -517,12 +511,11 @@ class PL_NBP_getter(Curreny_getter_interface) : # class added according to pol
|
||||
currency_array.remove(main_currency)
|
||||
# Move to new XML lib cf Launchpad bug #645263
|
||||
from lxml import etree
|
||||
logger = netsvc.Logger()
|
||||
logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "NBP.pl currency rate service : connecting...")
|
||||
_logger.debug("NBP.pl currency rate service : connecting...")
|
||||
rawfile = self.get_url(url)
|
||||
dom = etree.fromstring(rawfile) # If rawfile is not XML, it crashes here
|
||||
ns = {} # Cool, there are no namespaces !
|
||||
logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "NBP.pl sent a valid XML file")
|
||||
_logger.debug("NBP.pl sent a valid XML file")
|
||||
#node = xpath.Evaluate("/tabela_kursow", dom) # BEGIN Polish - rates table name
|
||||
#if isinstance(node, list) :
|
||||
# node = node[0]
|
||||
@@ -535,7 +528,7 @@ class PL_NBP_getter(Curreny_getter_interface) : # class added according to pol
|
||||
#we dynamically update supported currencies
|
||||
self.supported_currency_array = dom.xpath('/tabela_kursow/pozycja/kod_waluty/text()', namespaces=ns)
|
||||
self.supported_currency_array.append('PLN')
|
||||
logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Supported currencies = " + str(self.supported_currency_array))
|
||||
_logger.debug("Supported currencies = " + str(self.supported_currency_array))
|
||||
self.validate_cur(main_currency)
|
||||
if main_currency != 'PLN':
|
||||
main_curr_data = self.rate_retrieve(dom, ns, main_currency)
|
||||
@@ -553,5 +546,5 @@ class PL_NBP_getter(Curreny_getter_interface) : # class added according to pol
|
||||
else:
|
||||
rate = main_rate * curr_data['rate_ref'] / curr_data['rate_currency']
|
||||
self.updated_currency[curr] = rate
|
||||
logger.notifyChannel("rate_update", netsvc.LOG_DEBUG, "Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
|
||||
_logger.debug("Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
|
||||
return self.updated_currency, self.log_info
|
||||
|
||||
@@ -4,12 +4,10 @@
|
||||
<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>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Rates">
|
||||
<field name="service"/>
|
||||
<field name="currency_to_update"/>
|
||||
<field name="company_id"/>
|
||||
|
||||
</tree>
|
||||
</field>
|
||||
@@ -18,11 +16,9 @@
|
||||
<record model="ir.ui.view" id="currency_rate_update_form">
|
||||
<field name="name">Update Rates</field>
|
||||
<field name="model">currency.rate.update.service</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Rate">
|
||||
<field name="service"/>
|
||||
<field name="company_id"/>
|
||||
<field name="max_delta_days"/>
|
||||
<separator string="Currencies to update with this service" colspan="4"/>
|
||||
<field name="currency_to_update" colspan="4" nolabel="1"/>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" ?>
|
||||
<openerp>
|
||||
<data>
|
||||
<data noupdate="1">
|
||||
<record id="ir_model_access_currencyrateupdate0" model="ir.model.access">
|
||||
<field name="model_id" ref="currency_rate_update.model_currency_rate_update"/>
|
||||
<field eval="1" name="perm_read"/>
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (c) 2008 Camtocamp SA
|
||||
# @author JB Aubort
|
||||
# $Id$
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsability of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# garantees and support are strongly adviced to contract a Free Software
|
||||
# Service Company
|
||||
#
|
||||
# This program is Free Software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
Reference in New Issue
Block a user