Browse files

[FIX] #563 Updated deprecated method calls to avoid warnings

  • Loading branch information...
cv-clearcorp committed Oct 8, 2018
1 parent 3e31382 commit 39a946d349150a1160a741a6b79ca1b86aa8e756
Showing with 37 additions and 55 deletions.
  1. +16 −20 currency_rate_update/
  2. +21 −35 currency_rate_update/
@@ -26,29 +26,29 @@ class ResCompany(models.Model):
"""override company to add currency update"""
def _multi_curr_enable(self, cr, uid, ids, field_name, arg, context=None):
def _multi_curr_enable(self, field_name, arg):
"check if multi company currency is enabled"
result = {}
if self.pool.get('ir.model.fields').search(cr, uid, [('name', '=', 'company_id'), ('model', '=', 'res.currency')]) == []:
if not self.env['ir.model.fields'].search([('name', '=', 'company_id'), ('model', '=', 'res.currency')]):
enable = 0
enable = 1
for id in ids:
result[id] = enable
for company in self:
result[] = enable
return result
def button_refresh_currency(self, cr, uid, ids, context=None):
def button_refresh_currency(self):
"""Refrech the currency !!for all the company
currency_updater_obj = self.pool.get('currency.rate.update')
currency_updater_obj = self.env['currency.rate.update']
currency_updater_obj.run_currency_update(cr, uid)
except Exception as e:
raise e
# print "ok"
return True
def write(self, cr, uid, ids, vals, context=None):
def write(self, vals):
"""handle the activation of the currecny update on compagnies.
There are two ways of implementing multi_company currency,
the currency is shared or not. The module take care of the two
@@ -58,41 +58,37 @@ def write(self, cr, uid, ids, vals, context=None):
If yours currency are not share you will be able to activate the
auto update on each separated company"""
save_cron = {}
for company in self.browse(cr, uid, ids, context=context):
for company in self:
if 'auto_currency_up' in vals:
enable = company.multi_company_currency_enable
compagnies =, uid, [])
compagnies =
activate_cron = 'f'
value = vals.get('auto_currency_up')
if not value:
for comp in compagnies:
if self.browse(cr, uid, comp).auto_currency_up:
if comp.auto_currency_up:
activate_cron = 't'
save_cron.update({'active': activate_cron})
for comp in compagnies:
if comp != and not enable:
if self.browse(cr, uid, comp).multi_company_currency_enable:
if != and not enable:
if comp.multi_company_currency_enable:
raise Exception('Yon can not activate auto currency ' +
'update on more thant one company with this ' +
'multi company configuration')
for comp in compagnies:
if self.browse(cr, uid, comp).auto_currency_up:
if comp.auto_currency_up:
activate_cron = 't'
save_cron.update({'active': activate_cron})
if 'interval_type' in vals:
save_cron.update({'interval_type': vals.get('interval_type')})
if save_cron:
return super(ResCompany, self).write(cr, uid, ids, vals, context=context)
return super(ResCompany, self).write(vals)
_inherit = ""
@@ -78,10 +78,9 @@ class CurrencyRateUpdateService(models.Model):
def _check_max_delta_days(self, cr, uid, ids):
for company in, uid, ids, ['max_delta_days']):
if company['max_delta_days'] >= 0:
def _check_max_delta_days(self):
for company in self:
if self.max_delta_days >= 0:
return False
@@ -114,26 +113,20 @@ class CurrencyRateUpdate(models.Model):
LOG_NAME = 'cron-rates'
MOD_NAME = 'currency_rate_update: '
def get_cron_id(self, cr, uid, context):
def get_cron_id(self):
"""return the updater cron's id. Create one if the cron does not exists """
cron_id = 0
cron_obj = self.pool.get('ir.cron')
cron_obj = self.env['ir.cron']
# find the cron that send messages
cron_id =
cron_id = cron_obj.with_context(active_test=False).search(
('function', 'ilike', self.cron['function']),
('model', 'ilike', self.cron['model'])
'active_test': False
cron_id = int(cron_id[0])
cron_id = cron_id[0].id
except Exception:'warning cron not found one will be created')
pass # ignore if the cron is missing cause we are going to create it in db
@@ -142,38 +135,35 @@ def get_cron_id(self, cr, uid, context):
if not cron_id:
# translate
self.cron['name'] = _('Currency Rate Update')
cron_id = cron_obj.create(cr, uid, self.cron, context)
cron_id = cron_obj.create(self.cron)
return cron_id
def save_cron(self, cr, uid, datas, context=None):
def save_cron(self, datas):
"""save the cron config data should be a dict"""
context = context or {}
# modify the cron
cron_id = self.get_cron_id(cr, uid, context)
self.pool.get('ir.cron').write(cr, uid, [cron_id], datas)
cron_id = self.get_cron_id()
self.env['ir.cron'].write([cron_id], datas)
def run_currency_update(self, cr, uid):
def run_currency_update(self):
"update currency at the given frequence"
factory = CurrencyGetterFactory()
curr_obj = self.pool.get('res.currency')
rate_obj = self.pool.get('res.currency.rate')
companies = self.pool.get('').search(cr, uid, [])
for comp in self.pool.get('').browse(cr, uid, companies):
curr_obj = self.env['res.currency']
rate_obj = self.env['res.currency.rate']
companies = self.env[''].search()
for comp in companies:
# the multi company currency can beset or no so we handle
# the two case
if not comp.auto_currency_up:
# we initialise the multi compnay search filter or not serach filter
# we fetch the main currency looking for currency with base = true. The main rate should be set at 1.00
main_curr_ids =, uid, [('base', '=', True), ('company_id', '=',])
main_curr_ids =[('base', '=', True), ('company_id', '=',])
if not main_curr_ids:
# If we can not find a base currency for this company we look for one with no company set
main_curr_ids =, uid, [('base', '=', True), ('company_id', '=', False)])
main_curr_ids =[('base', '=', True), ('company_id', '=', False)])
if main_curr_ids:
main_curr_rec = curr_obj.browse(cr, uid, main_curr_ids[0])
main_curr_rec = main_curr_ids[0]
raise orm.except_orm(_('Error!'), ('There is no base currency set!'))
if main_curr_rec.rate != 1:
@@ -205,11 +195,7 @@ def run_currency_update(self, cr, uid):
'rate': res[],
'name': rate_name
# show the most recent note at the top
note = "\n%s currency updated. "\

0 comments on commit 39a946d

Please sign in to comment.