commit 1ff4302e2b01b97c145b327622e77afdf8e7382b Author: Alexis de Lattre Date: Mon Sep 23 13:22:01 2013 +0200 Module "currency_rate_date_check" : - move from extra-trunk to account-financial-tools - port from OpenERP 6.1 to OpenERP 7.0 - add icon and screenshots - add FR translation diff --git a/currency_rate_date_check/__init__.py b/currency_rate_date_check/__init__.py new file mode 100644 index 000000000..972d7471c --- /dev/null +++ b/currency_rate_date_check/__init__.py @@ -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 +# +# 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 . +# +############################################################################## + +import company +import currency_rate_date_check + diff --git a/currency_rate_date_check/__openerp__.py b/currency_rate_date_check/__openerp__.py new file mode 100644 index 000000000..523eb1b85 --- /dev/null +++ b/currency_rate_date_check/__openerp__.py @@ -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 +# +# 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 . +# +############################################################################## + + +{ + '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 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, +} diff --git a/currency_rate_date_check/company.py b/currency_rate_date_check/company.py new file mode 100644 index 000000000..24b9f6872 --- /dev/null +++ b/currency_rate_date_check/company.py @@ -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 +# +# 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 . +# +############################################################################## + +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']), + ] + diff --git a/currency_rate_date_check/company_view.xml b/currency_rate_date_check/company_view.xml new file mode 100644 index 000000000..ebf326759 --- /dev/null +++ b/currency_rate_date_check/company_view.xml @@ -0,0 +1,25 @@ + + + + + + + + + currency.rate.date.check.form + res.company + + + + + + + + + + + diff --git a/currency_rate_date_check/currency_rate_date_check.py b/currency_rate_date_check/currency_rate_date_check.py new file mode 100644 index 000000000..41207bbd3 --- /dev/null +++ b/currency_rate_date_check/currency_rate_date_check.py @@ -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 +# +# 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 . +# +############################################################################## + +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) + diff --git a/currency_rate_date_check/i18n/currency_rate_date_check.po b/currency_rate_date_check/i18n/currency_rate_date_check.po new file mode 100644 index 000000000..5287cb55c --- /dev/null +++ b/currency_rate_date_check/i18n/currency_rate_date_check.po @@ -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 "" + diff --git a/currency_rate_date_check/i18n/fr.po b/currency_rate_date_check/i18n/fr.po new file mode 100644 index 000000000..3984d6419 --- /dev/null +++ b/currency_rate_date_check/i18n/fr.po @@ -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" + diff --git a/currency_rate_date_check/images/date_check_company_config.jpg b/currency_rate_date_check/images/date_check_company_config.jpg new file mode 100644 index 000000000..33c4e76df Binary files /dev/null and b/currency_rate_date_check/images/date_check_company_config.jpg differ diff --git a/currency_rate_date_check/images/date_check_error_popup.jpg b/currency_rate_date_check/images/date_check_error_popup.jpg new file mode 100644 index 000000000..49aa03671 Binary files /dev/null and b/currency_rate_date_check/images/date_check_error_popup.jpg differ diff --git a/currency_rate_date_check/static/src/img/icon.png b/currency_rate_date_check/static/src/img/icon.png new file mode 100644 index 000000000..02b5494de Binary files /dev/null and b/currency_rate_date_check/static/src/img/icon.png differ