openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #00102
lp:~akretion-team/account-financial-tools/70-currency-rate-date-check into lp:account-financial-tools
Alexis de Lattre has proposed merging lp:~akretion-team/account-financial-tools/70-currency-rate-date-check into lp:account-financial-tools.
Requested reviews:
Account Core Editors (account-core-editors)
For more details, see:
https://code.launchpad.net/~akretion-team/account-financial-tools/70-currency-rate-date-check/+merge/187009
Move my module from extra-trunk to account-financial-tools and port it to OpenERP 7.0.
This module has been used in production at Anevia for more than a year (on OpenERP 6.1) and I think it is a "must have" for companies in multi-currency who want to make sure that the currency rates they use are always up-to-date.
--
https://code.launchpad.net/~akretion-team/account-financial-tools/70-currency-rate-date-check/+merge/187009
Your team Account Core Editors is requested to review the proposed merge of lp:~akretion-team/account-financial-tools/70-currency-rate-date-check into lp:account-financial-tools.
=== added directory 'currency_rate_date_check'
=== added file 'currency_rate_date_check/__init__.py'
--- currency_rate_date_check/__init__.py 1970-01-01 00:00:00 +0000
+++ currency_rate_date_check/__init__.py 2013-09-23 12:13:48 +0000
@@ -0,0 +1,25 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Currency rate date check module for OpenERP
+# Copyright (C) 2012-2013 Akretion (http://www.akretion.com).
+# @author Alexis de Lattre <alexis.delattre@xxxxxxxxxxxx>
+#
+# 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/>.
+#
+##############################################################################
+
+import company
+import currency_rate_date_check
+
=== added file 'currency_rate_date_check/__openerp__.py'
--- currency_rate_date_check/__openerp__.py 1970-01-01 00:00:00 +0000
+++ currency_rate_date_check/__openerp__.py 2013-09-23 12:13:48 +0000
@@ -0,0 +1,48 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Currency rate date check module for OpenERP
+# Copyright (C) 2012-2013 Akretion (http://www.akretion.com).
+# @author Alexis de Lattre <alexis.delattre@xxxxxxxxxxxx>
+#
+# 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': 'Currency Rate Date Check',
+ 'version': '1.0',
+ 'category': 'Financial Management/Configuration',
+ 'license': 'AGPL-3',
+ 'summary': "Make sure currency rates used are always up-to-update",
+ 'description': """
+Currency Rate Date Check
+========================
+
+This module adds a check on dates when doing currency conversion in OpenERP. It checks that the currency rate used to make the conversion is not more than N days away from the date of the amount to convert. The maximum number of days of the interval can be configured on the company form.
+
+Please contact Alexis de Lattre from Akretion <alexis.delattre@xxxxxxxxxxxx> for any help or question about this module.
+ """,
+ 'author': 'Akretion',
+ 'website': 'http://www.akretion.com',
+ 'depends': ['base'],
+ 'data': ['company_view.xml'],
+ 'images': [
+ 'images/date_check_error_popup.jpg',
+ 'images/date_check_company_config.jpg',
+ ],
+ 'installable': True,
+ 'active': False,
+}
=== added file 'currency_rate_date_check/company.py'
--- currency_rate_date_check/company.py 1970-01-01 00:00:00 +0000
+++ currency_rate_date_check/company.py 2013-09-23 12:13:48 +0000
@@ -0,0 +1,45 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Currency rate date check module for OpenERP
+# Copyright (C) 2012-2013 Akretion (http://www.akretion.com)
+# @author Alexis de Lattre <alexis.delattre@xxxxxxxxxxxx>
+#
+# 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 openerp.osv import osv, fields
+
+class res_company(osv.Model):
+ _inherit = 'res.company'
+
+ _columns = {
+ 'currency_rate_max_delta': fields.integer('Max Time Delta in Days for Currency Rates', help="This is the maximum interval in days between the date associated with the amount to convert and the date of the nearest currency rate available in OpenERP."),
+ }
+
+ _defaults = {
+ 'currency_rate_max_delta': 7,
+ }
+
+ def _check_currency_rate_max_delta(self, cr, uid, ids):
+ for company in self.read(cr, uid, ids, ['currency_rate_max_delta']):
+ if company['currency_rate_max_delta'] < 0:
+ return False
+ return True
+
+ _constraints = [
+ (_check_currency_rate_max_delta, "The value must be positive or 0", ['currency_rate_max_delta']),
+ ]
+
=== added file 'currency_rate_date_check/company_view.xml'
--- currency_rate_date_check/company_view.xml 1970-01-01 00:00:00 +0000
+++ currency_rate_date_check/company_view.xml 2013-09-23 12:13:48 +0000
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ Copyright (C) 2012 Akretion (http://www.akretion.com/)
+ @author Alexis de Lattre <alexis.delattre@xxxxxxxxxxxx>
+ The licence is in the file __openerp__.py
+-->
+
+<openerp>
+<data>
+
+<record id="currency_rate_date_check_form" model="ir.ui.view">
+ <field name="name">currency.rate.date.check.form</field>
+ <field name="model">res.company</field>
+ <field name="inherit_id" ref="base.view_company_form" />
+ <field name="arch" type="xml">
+ <field name="currency_id" position="after">
+ <field name="currency_rate_max_delta" />
+ </field>
+ </field>
+</record>
+
+
+</data>
+</openerp>
=== added file 'currency_rate_date_check/currency_rate_date_check.py'
--- currency_rate_date_check/currency_rate_date_check.py 1970-01-01 00:00:00 +0000
+++ currency_rate_date_check/currency_rate_date_check.py 2013-09-23 12:13:48 +0000
@@ -0,0 +1,84 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Currency rate date check module for OpenERP
+# Copyright (C) 2012-2013 Akretion (http://www.akretion.com)
+# @author Alexis de Lattre <alexis.delattre@xxxxxxxxxxxx>
+#
+# 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 openerp.osv import osv, fields
+from datetime import datetime, timedelta
+from openerp.tools.translate import _
+
+# Here are some explainations about the design of this module.
+# In server/openerp/addons/base/res/res_currency.py :
+# compute() -> _get_conversion_rate() -> _current_rate() -> _current_rate_computation()
+# The date used for the rate is the one in the context
+# compute() adds currency_rate_type_from and currency_rate_type_to to the context
+# _get_conversion_rate() adds currency_rate_type_id to context ; its value is currency_rate_type_to ; if it doesn't exist it's currency_rate_type_from ; if it doesn't exist either it's False
+# It already contains raise "No rate found for currency ... at the date ..."
+# _current_rate() reads currency_rate_type_id from context and uses it in the SQL request
+# This is the function used for the definition of the field.function 'rate' on res_currency
+
+# Which one of the 3 functions should we inherit ? Good question...
+# It's probably better to inherit the lowest level function, i.e. _current_rate_computation()
+# Advantage : by inheriting the lowest level function, we can be sure that the check
+# always apply, even for scenarios where we read the field "rate" of the obj currency
+# => that's the solution I implement in the code below
+
+
+class res_currency(osv.Model):
+ _inherit = 'res.currency'
+
+ def _current_rate_computation(self, cr, uid, ids, name, arg, raise_on_no_rate, context=None):
+ # We only do the check if there is an explicit date in the context and
+ # there is no specific currency_rate_type_id
+ if context and context.get('date') and not context.get('currency_rate_type_id') and not context.get('disable_rate_date_check'):
+ for currency_id in ids:
+ # We could get the company from the currency, but it's not a
+ # 'required' field, so we should probably continue to get it from
+ # the user, shouldn't we ?
+ user = self.pool['res.users'].browse(cr, uid, uid, context=context)
+ # if it's the company currency, don't do anything
+ # (there is just one old rate at 1.0)
+ if user.company_id.currency_id.id == currency_id:
+ continue
+ else:
+ # now we do the real work !
+ date = context.get('date', datetime.today().strftime('%Y-%m-%d'))
+ date_datetime = datetime.strptime(date, '%Y-%m-%d')
+ #print "date =", date
+ rate_obj = self.pool['res.currency.rate']
+ selected_rate = rate_obj.search(cr, uid, [
+ ('currency_id', '=', currency_id),
+ ('name', '<=', date),
+ ('currency_rate_type_id', '=', None)
+ ], order='name desc', limit=1, context=context)
+ if not selected_rate:
+ continue
+
+ rate_date = rate_obj.read(cr, uid, selected_rate[0], ['name'], context=context)['name']
+ rate_date_datetime = datetime.strptime(rate_date, '%Y-%m-%d')
+ max_delta = user.company_id.currency_rate_max_delta
+ #print "max_delta=", max_delta
+ #print "rate_date=", rate_date
+ if (date_datetime - rate_date_datetime).days > max_delta:
+ currency_name = self.read(cr, uid, currency_id, ['name'], context=context)['name']
+ raise osv.except_osv(_('Error'), _('You are requesting a rate conversion on %s for currency %s but the nearest rate before that date is dated %s and the maximum currency rate time delta for your company is %s days') % (date, currency_name, rate_date, max_delta))
+ # Now we call the regular function from the "base" module
+ return super(res_currency, self)._current_rate_computation(cr, uid, ids, name, arg, raise_on_no_rate, context=context)
+
=== added directory 'currency_rate_date_check/i18n'
=== added file 'currency_rate_date_check/i18n/currency_rate_date_check.po'
--- currency_rate_date_check/i18n/currency_rate_date_check.po 1970-01-01 00:00:00 +0000
+++ currency_rate_date_check/i18n/currency_rate_date_check.po 2013-09-23 12:13:48 +0000
@@ -0,0 +1,54 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+# * currency_rate_date_check
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 7.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2013-09-23 10:05+0000\n"
+"PO-Revision-Date: 2013-09-23 10:05+0000\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: currency_rate_date_check
+#: model:ir.model,name:currency_rate_date_check.model_res_currency
+msgid "Currency"
+msgstr ""
+
+#. module: currency_rate_date_check
+#: code:addons/currency_rate_date_check/currency_rate_date_check.py:84
+#, python-format
+msgid "You are requesting a rate conversion on %s for currency %s but the nearest rate before that date is dated %s and the maximum currency rate time delta for your company is %s days"
+msgstr ""
+
+#. module: currency_rate_date_check
+#: model:ir.model,name:currency_rate_date_check.model_res_company
+msgid "Companies"
+msgstr ""
+
+#. module: currency_rate_date_check
+#: field:res.company,currency_rate_max_delta:0
+msgid "Max Time Delta in Days for Currency Rates"
+msgstr ""
+
+#. module: currency_rate_date_check
+#: help:res.company,currency_rate_max_delta:0
+msgid "This is the maximum interval in days between the date associated with the amount to convert and the date of the nearest currency rate available in OpenERP."
+msgstr ""
+
+#. module: currency_rate_date_check
+#: code:addons/currency_rate_date_check/currency_rate_date_check.py:84
+#, python-format
+msgid "Error"
+msgstr ""
+
+#. module: currency_rate_date_check
+#: constraint:res.company:0
+msgid "The value must be positive or 0"
+msgstr ""
+
=== added file 'currency_rate_date_check/i18n/fr.po'
--- currency_rate_date_check/i18n/fr.po 1970-01-01 00:00:00 +0000
+++ currency_rate_date_check/i18n/fr.po 2013-09-23 12:13:48 +0000
@@ -0,0 +1,54 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+# * currency_rate_date_check
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 7.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2013-09-23 10:06+0000\n"
+"PO-Revision-Date: 2013-09-23 10:06+0000\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: currency_rate_date_check
+#: model:ir.model,name:currency_rate_date_check.model_res_currency
+msgid "Currency"
+msgstr "Devise"
+
+#. module: currency_rate_date_check
+#: code:addons/currency_rate_date_check/currency_rate_date_check.py:84
+#, python-format
+msgid "You are requesting a rate conversion on %s for currency %s but the nearest rate before that date is dated %s and the maximum currency rate time delta for your company is %s days"
+msgstr "Vous demandez une conversion de devise à la date du %s pour la devise %s mais le taux de change le plus proche qui précède cette date est daté du %s et l'écart temporel maximum pour les taux de change pour votre société est de %s jours"
+
+#. module: currency_rate_date_check
+#: model:ir.model,name:currency_rate_date_check.model_res_company
+msgid "Companies"
+msgstr "Sociétés"
+
+#. module: currency_rate_date_check
+#: field:res.company,currency_rate_max_delta:0
+msgid "Max Time Delta in Days for Currency Rates"
+msgstr "Ecart temporel maximum pour les taux de change (en jours)"
+
+#. module: currency_rate_date_check
+#: help:res.company,currency_rate_max_delta:0
+msgid "This is the maximum interval in days between the date associated with the amount to convert and the date of the nearest currency rate available in OpenERP."
+msgstr "Intervalle de temps maximum en jours entre la date associée au montant à convertir et la date du taux de change le plus rapproché disponible dans OpenERP."
+
+#. module: currency_rate_date_check
+#: code:addons/currency_rate_date_check/currency_rate_date_check.py:84
+#, python-format
+msgid "Error"
+msgstr "Erreur"
+
+#. module: currency_rate_date_check
+#: constraint:res.company:0
+msgid "The value must be positive or 0"
+msgstr "La valeur doit être positive ou nulle"
+
=== added directory 'currency_rate_date_check/images'
=== added file 'currency_rate_date_check/images/date_check_company_config.jpg'
Binary files currency_rate_date_check/images/date_check_company_config.jpg 1970-01-01 00:00:00 +0000 and currency_rate_date_check/images/date_check_company_config.jpg 2013-09-23 12:13:48 +0000 differ
=== added file 'currency_rate_date_check/images/date_check_error_popup.jpg'
Binary files currency_rate_date_check/images/date_check_error_popup.jpg 1970-01-01 00:00:00 +0000 and currency_rate_date_check/images/date_check_error_popup.jpg 2013-09-23 12:13:48 +0000 differ
=== added directory 'currency_rate_date_check/static'
=== added directory 'currency_rate_date_check/static/src'
=== added directory 'currency_rate_date_check/static/src/img'
=== added file 'currency_rate_date_check/static/src/img/icon.png'
Binary files currency_rate_date_check/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and currency_rate_date_check/static/src/img/icon.png 2013-09-23 12:13:48 +0000 differ
Follow ups