mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[MRG] from trunk
This commit is contained in:
21
account_tax_analysis/__init__.py
Normal file
21
account_tax_analysis/__init__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author Vincent Renaville. Copyright 2013 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from . import account_tax_analysis
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
42
account_tax_analysis/__openerp__.py
Normal file
42
account_tax_analysis/__openerp__.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author Vincent Renaville. Copyright 2013 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
{"name": "Tax analysis",
|
||||
"version": "1.0",
|
||||
"depends": ["base", "account"],
|
||||
"author": "CamptoCamp SA",
|
||||
"category": 'Accounting & Finance',
|
||||
"description": """
|
||||
Tax analysis view
|
||||
=================
|
||||
|
||||
This add-on is a must if you want to be able to validate your VAT form.
|
||||
|
||||
Thanks to a new menu 'Accounting / Tax / Tax analysis'
|
||||
you are able to group accounting entries by Taxes (VAT codes)
|
||||
and/or financial accounts.
|
||||
|
||||
This way you will find easily differences you may see between
|
||||
the OpenERP tax report and what you see in your books.""",
|
||||
"website": "http://www.camptocamp.com",
|
||||
"data": ["account_tax_analysis_view.xml"],
|
||||
"installable": True,
|
||||
"active": False,
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
55
account_tax_analysis/account_tax_analysis.py
Normal file
55
account_tax_analysis/account_tax_analysis.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author Vincent Renaville. Copyright 2013 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from osv import orm, osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
|
||||
class account_tax_declaration_analysis(orm.TransientModel):
|
||||
_name = 'account.vat.declaration.analysis'
|
||||
_description = 'Account Vat Declaration'
|
||||
_columns = {
|
||||
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscalyear',
|
||||
help='Fiscalyear to look on', required=True),
|
||||
|
||||
'period_list': fields.many2many('account.period', 'account_tax_period_rel',
|
||||
'tax_analysis', 'period_id',
|
||||
'Period _list', required=True),
|
||||
}
|
||||
|
||||
def create_vat(self, cr, uid, ids, context=None):
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
action_obj = self.pool.get('ir.actions.act_window')
|
||||
domain = []
|
||||
data = self.read(cr, uid, ids, [], context=context)[0]
|
||||
period_list = data['period_list']
|
||||
if period_list:
|
||||
domain = [('period_id', 'in', period_list)]
|
||||
else:
|
||||
raise osv.except_osv(_('No period defined'),
|
||||
_("You must selected period "))
|
||||
actions = mod_obj.get_object_reference(cr, uid,
|
||||
'account_tax_analysis',
|
||||
'action_view_tax_analysis')
|
||||
id_action = actions[1] if actions else False
|
||||
action_mod = action_obj.read(cr, uid, id_action)
|
||||
action_mod['domain'] = domain
|
||||
return action_mod
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
121
account_tax_analysis/account_tax_analysis_view.xml
Normal file
121
account_tax_analysis/account_tax_analysis_view.xml
Normal file
@@ -0,0 +1,121 @@
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_account_move_line_filter_vat_analysis" model="ir.ui.view">
|
||||
<field name="name">Journal Items Tax</field>
|
||||
<field name="model">account.move.line</field>
|
||||
<field name="type">search</field>
|
||||
<field eval="32" name="priority"/>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Journal Items">
|
||||
<group>
|
||||
<separator orientation="vertical"/>
|
||||
<filter icon="terp-document-new"
|
||||
string="Unposted"
|
||||
domain="[('move_id.state','=','draft')]"
|
||||
help="Unposted Journal Items"/>
|
||||
<filter name="posted"
|
||||
icon="terp-camera_test"
|
||||
string="Posted"
|
||||
domain="[('move_id.state','=','posted')]"
|
||||
help="Posted Journal Items"/>
|
||||
<separator orientation="vertical"/>
|
||||
<field name="date"/>
|
||||
<field name="account_id"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<newline/>
|
||||
<group expand="1" string="Group By...">
|
||||
<filter string="Partner" icon="terp-partner"
|
||||
domain="[]"
|
||||
context="{'group_by': 'partner_id'}"/>
|
||||
<separator orientation="vertical"/>
|
||||
<filter string="Account"
|
||||
icon="terp-folder-green"
|
||||
context="{'group_by': 'account_id'}"/>
|
||||
<separator orientation="vertical"/>
|
||||
<filter string="Period"
|
||||
icon="terp-go-month"
|
||||
domain="[]"
|
||||
context="{'group_by': 'period_id'}"/>
|
||||
<filter string="Tax account"
|
||||
icon="terp-go-month"
|
||||
domain="[]"
|
||||
context="{'group_by': 'tax_code_id'}"/>
|
||||
</group>
|
||||
<newline/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_move_line_tree_tax_analysis" model="ir.ui.view">
|
||||
<field name="name">account.move.line.tree</field>
|
||||
<field name="model">account.move.line</field>
|
||||
<field name="type">tree</field>
|
||||
<field eval="16" name="priority"/>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Journal Items" editable="top" on_write="on_create_write">
|
||||
<field name="tax_code_id" />
|
||||
<field name="name"/>
|
||||
<field name="ref"/>
|
||||
<field name="period_id"/>
|
||||
<field name="date"/>
|
||||
<field name="partner_id" />
|
||||
<field name="account_id" domain="[('journal_id','=',journal_id), ('company_id', '=', company_id)]"/>
|
||||
<field name="debit" sum="Total debit"/>
|
||||
<field name="credit" sum="Total credit"/>
|
||||
<field name="tax_amount" sum="Total Taxe"/>
|
||||
<field name="amount_currency" />
|
||||
<field name="currency_id" />
|
||||
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="action_view_tax_analysis" model="ir.actions.act_window">
|
||||
<field name="name">Recurring Models</field>
|
||||
<field name="res_model">account.move.line</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree</field>
|
||||
<field name="search_view_id" ref="view_account_move_line_filter_vat_analysis"/>
|
||||
<field name="view_id" ref="view_move_line_tree_tax_analysis"/>
|
||||
</record>
|
||||
|
||||
<record id="view_account_vat_declaration_analysis" model="ir.ui.view">
|
||||
<field name="name">Account Vat Declaration</field>
|
||||
<field name="model">account.vat.declaration.analysis</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Taxes Report">
|
||||
<separator string="Taxes Report" colspan="4"/>
|
||||
<newline/>
|
||||
<field name="fiscalyear_id"/>
|
||||
<separator string="Periods" colspan="4"/>
|
||||
<field name="period_list" domain="[('fiscalyear_id', '=', fiscalyear_id)]"/>
|
||||
<group col="2" colspan="4">
|
||||
<button icon='gtk-cancel' special="cancel" string="Cancel" />
|
||||
<button name="create_vat" string="Show tax lines" colspan="1" type="object" icon="gtk-ok"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_account_vat_declaration_analysis" model="ir.actions.act_window">
|
||||
<field name="name">Account Vat Declaration</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">account.vat.declaration.analysis</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="help">This menu print a VAT declaration based on invoices or payments. You can select one or several periods of the fiscal year. Information required for a tax declaration is automatically generated by OpenERP from invoices (or payments, in some countries). This data is updated in real time. That’s very useful because it enables you to preview at any time the tax that you owe at the start and end of the month or quarter.</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
name="Taxes Analysis"
|
||||
parent="account.menu_tax_report"
|
||||
action="action_account_vat_declaration_analysis"
|
||||
id="menu_account_vat_declaration_analysis"
|
||||
icon="STOCK_PRINT"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
37
currency_rate_update/__init__.py
Executable file → Normal file
37
currency_rate_update/__init__.py
Executable file → Normal file
@@ -1,33 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# 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: $
|
||||
# Copyright (c) 2008 Camtocamp SA
|
||||
# @author JB Aubort, Nicolas Bessi, Joel Grand-Guillaume
|
||||
# European Central Bank and Polish National Bank invented by Grzegorz Grzelak
|
||||
#
|
||||
# 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 Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# 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 Affero General Public License for more details.
|
||||
#
|
||||
# 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.
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import currency_rate_update
|
||||
import company
|
||||
import wizard
|
||||
|
||||
59
currency_rate_update/__openerp__.py
Executable file → Normal file
59
currency_rate_update/__openerp__.py
Executable file → Normal file
@@ -1,35 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# 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: $
|
||||
# Copyright (c) 2008 Camtocamp SA
|
||||
# @author JB Aubort, Nicolas Bessi, Joel Grand-Guillaume
|
||||
# European Central Bank and Polish National Bank invented by Grzegorz Grzelak
|
||||
# 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
|
||||
# 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 Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# 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 Affero General Public License for more details.
|
||||
#
|
||||
# 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.
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
{
|
||||
"name" : "Currency Rate Update",
|
||||
"version" : "0.6",
|
||||
"version" : "0.7",
|
||||
"author" : "Camptocamp",
|
||||
"website" : "http://camptocamp.com",
|
||||
"category" : "Financial Management/Configuration",
|
||||
@@ -79,14 +72,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
|
||||
}
|
||||
|
||||
@@ -1,38 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# company.py
|
||||
# c2c_currency_update
|
||||
# @author Nicolas Bessi
|
||||
# Copyright (c) 2009 CamptoCamp. All rights reserved.
|
||||
##############################################################################
|
||||
#
|
||||
# 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
|
||||
# Copyright (c) 2009 CamptoCamp. All rights reserved.
|
||||
# @author Nicolas Bessi
|
||||
#
|
||||
# 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 free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 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.
|
||||
# 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 Affero 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.
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
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={}):
|
||||
"check if multi company currency is enabled"
|
||||
result = {}
|
||||
@@ -43,8 +35,8 @@ class res_company(osv.osv):
|
||||
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"""
|
||||
@@ -54,18 +46,18 @@ class res_company(osv.osv):
|
||||
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 :
|
||||
@@ -77,12 +69,12 @@ class res_company(osv.osv):
|
||||
# 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 {}
|
||||
@@ -93,10 +85,10 @@ class res_company(osv.osv):
|
||||
#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 '+\
|
||||
@@ -106,44 +98,44 @@ class res_company(osv.osv):
|
||||
}
|
||||
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',
|
||||
@@ -151,14 +143,15 @@ class res_company(osv.osv):
|
||||
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'
|
||||
),
|
||||
}
|
||||
res_company()
|
||||
}
|
||||
|
||||
|
||||
|
||||
10
currency_rate_update/company_view.xml
Executable file → Normal file
10
currency_rate_update/company_view.xml
Executable file → Normal file
@@ -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' />
|
||||
@@ -20,4 +21,3 @@
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
|
||||
253
currency_rate_update/currency_rate_update.py
Executable file → Normal file
253
currency_rate_update/currency_rate_update.py
Executable file → Normal file
@@ -1,40 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (c) 2009 Camptocamp SA
|
||||
# @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
|
||||
# - rates given by ECB webservice is now correct even when main_cur <> EUR
|
||||
# - rates given by PL_NBP webservice is now correct even when main_cur <> PLN
|
||||
# - if company_currency <> CHF, you can now update CHF via Admin.ch webservice
|
||||
# (same for EUR with ECB webservice and PLN with NBP webservice)
|
||||
# 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)
|
||||
# Copyright (c) 2009 Camptocamp SA
|
||||
# @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
|
||||
# - rates given by ECB webservice is now correct even when main_cur <> EUR
|
||||
# - rates given by PL_NBP webservice is now correct even when main_cur <> PLN
|
||||
# - if company_currency <> CHF, you can now update CHF via Admin.ch webservice
|
||||
# (same for EUR with ECB webservice and PLN with NBP webservice)
|
||||
# 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
|
||||
# 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 Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# 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 Affero General Public License for more details.
|
||||
#
|
||||
# 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.
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
@@ -42,24 +35,26 @@
|
||||
# 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):
|
||||
"""Class thats tell for wich services wich currencies
|
||||
_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"
|
||||
_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
|
||||
@@ -67,7 +62,7 @@ class Currency_rate_update_service(osv.osv):
|
||||
"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',
|
||||
@@ -75,7 +70,7 @@ class Currency_rate_update_service(osv.osv):
|
||||
'currency_id',
|
||||
'currency to update with this service',
|
||||
),
|
||||
#back ref
|
||||
#back ref
|
||||
'company_id' : fields.many2one(
|
||||
'res.company',
|
||||
'linked company',
|
||||
@@ -89,8 +84,8 @@ class Currency_rate_update_service(osv.osv):
|
||||
}
|
||||
_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 !')
|
||||
)
|
||||
]
|
||||
@@ -107,10 +102,9 @@ 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 that handle an ir cron call who will
|
||||
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"
|
||||
_description = "Currency Rate Update"
|
||||
@@ -125,52 +119,47 @@ class Currency_rate_update(osv.osv):
|
||||
'doall' : True,
|
||||
'model' : 'currency.rate.update',
|
||||
'function' : 'run_currency_update',
|
||||
'args' : '()',
|
||||
'args' : '()',
|
||||
}
|
||||
|
||||
logger = netsvc.Logger()
|
||||
|
||||
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 :
|
||||
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
|
||||
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"
|
||||
@@ -179,7 +168,7 @@ class Currency_rate_update(osv.osv):
|
||||
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
|
||||
@@ -215,12 +204,12 @@ class Currency_rate_update(osv.osv):
|
||||
'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 '')
|
||||
@@ -228,14 +217,13 @@ 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):
|
||||
class AbstractClassError(Exception):
|
||||
def __str__(self):
|
||||
return 'Abstract Class'
|
||||
def __repr__(self):
|
||||
@@ -247,25 +235,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',
|
||||
@@ -279,60 +267,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:
|
||||
@@ -355,14 +343,14 @@ 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 ###################################################################################
|
||||
#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)
|
||||
@@ -377,7 +365,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) :
|
||||
@@ -402,11 +390,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 +403,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 +421,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 +451,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 +462,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 +477,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 +503,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 +520,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 +538,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
|
||||
|
||||
14
currency_rate_update/currency_rate_update.xml
Executable file → Normal file
14
currency_rate_update/currency_rate_update.xml
Executable file → Normal file
@@ -1,36 +1,32 @@
|
||||
<?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>
|
||||
<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>
|
||||
</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>
|
||||
<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"/>
|
||||
<separator string="Logs" colspan="4"/>
|
||||
<field name="note" colspan="4" nolabel="1"/>
|
||||
<field name="note" colspan="4" nolabel="1"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
2
currency_rate_update/security/security.xml
Executable file → Normal file
2
currency_rate_update/security/security.xml
Executable file → Normal file
@@ -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