mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[FIX] flake8 PEP8 from module currency_date_check
This commit is contained in:
@@ -22,4 +22,3 @@
|
||||
|
||||
from . import company
|
||||
from . import currency_rate_date_check
|
||||
|
||||
|
||||
@@ -31,9 +31,14 @@
|
||||
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.
|
||||
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.
|
||||
|
||||
Please contact Alexis de Lattre from Akretion <alexis.delattre@akretion.com> for any help or question about this module.
|
||||
The maximum number of days of the interval can be configured on the company form.
|
||||
|
||||
Please contact Alexis de Lattre from Akretion <alexis.delattre@akretion.com>
|
||||
for any help or question about this module.
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
@@ -42,7 +47,7 @@ Please contact Alexis de Lattre from Akretion <alexis.delattre@akretion.com> for
|
||||
'images': [
|
||||
'images/date_check_error_popup.jpg',
|
||||
'images/date_check_company_config.jpg',
|
||||
],
|
||||
],
|
||||
'installable': True,
|
||||
'active': False,
|
||||
}
|
||||
|
||||
@@ -22,13 +22,16 @@
|
||||
|
||||
from openerp.osv import orm, fields
|
||||
|
||||
|
||||
class res_company(orm.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."),
|
||||
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 = {
|
||||
@@ -39,4 +42,4 @@ class res_company(orm.Model):
|
||||
('currency_rate_max_delta_positive',
|
||||
'CHECK (currency_rate_max_delta >= 0)',
|
||||
"The value of the field 'Max Time Delta in Days for Currency Rates' must be positive or 0."),
|
||||
]
|
||||
]
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import fields, orm
|
||||
from datetime import datetime, timedelta
|
||||
from openerp.osv import orm
|
||||
from datetime import datetime
|
||||
from openerp.tools.translate import _
|
||||
|
||||
# Here are some explainations about the design of this module.
|
||||
@@ -29,7 +29,9 @@ from openerp.tools.translate import _
|
||||
# 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
|
||||
# _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
|
||||
@@ -45,10 +47,12 @@ class res_currency(orm.Model):
|
||||
_inherit = 'res.currency'
|
||||
|
||||
def _current_rate_computation(self, cr, uid, ids, name, arg, raise_on_no_rate, context=None):
|
||||
if context is None: context = {}
|
||||
if context is None:
|
||||
context = {}
|
||||
# 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.get('date') and not context.get('currency_rate_type_id') and not context.get('disable_rate_date_check'):
|
||||
if 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
|
||||
@@ -67,7 +71,7 @@ class res_currency(orm.Model):
|
||||
('currency_id', '=', currency_id),
|
||||
('name', '<=', date),
|
||||
('currency_rate_type_id', '=', None)
|
||||
], order='name desc', limit=1, context=context)
|
||||
], order='name desc', limit=1, context=context)
|
||||
if not selected_rate:
|
||||
continue
|
||||
|
||||
@@ -76,7 +80,13 @@ class res_currency(orm.Model):
|
||||
max_delta = user.company_id.currency_rate_max_delta
|
||||
if (date_datetime - rate_date_datetime).days > max_delta:
|
||||
currency_name = self.read(cr, uid, currency_id, ['name'], context=context)['name']
|
||||
raise orm.except_orm(_('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))
|
||||
raise orm.except_orm(
|
||||
_('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)
|
||||
|
||||
return super(res_currency, self)._current_rate_computation(
|
||||
cr, uid, ids, name, arg, raise_on_no_rate, context=context)
|
||||
|
||||
Reference in New Issue
Block a user