From 7c852ea45478903f990d510ea6da12d4202afeaa Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Fri, 7 Apr 2017 23:50:20 +0200 Subject: [PATCH] [FIX] currency_rate_update should now work in multi-company --- .../models/currency_rate_update.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/currency_rate_update/models/currency_rate_update.py b/currency_rate_update/models/currency_rate_update.py index a0a148514..0a825fd39 100644 --- a/currency_rate_update/models/currency_rate_update.py +++ b/currency_rate_update/models/currency_rate_update.py @@ -165,22 +165,22 @@ class CurrencyRateUpdateService(models.Model): for curr in srv.currency_to_update: if curr == main_currency: continue - do_create = True - for rate in curr.rate_ids: - if rate.name == rate_name: - rate.rate = res[curr.name] - do_create = False - break - if do_create: + rates = rate_obj.search([ + ('currency_id', '=', curr.id), + ('company_id', '=', company.id), + ('name', '=', rate_name)]) + if not rates: vals = { 'currency_id': curr.id, 'rate': res[curr.name], - 'name': rate_name + 'name': rate_name, + 'company_id': company.id, } rate_obj.create(vals) _logger.info( - 'Updated currency %s via service %s', - curr.name, srv.service) + 'Updated currency %s via service %s ' + 'in company %s', + curr.name, srv.service, company.name) # Show the most recent note at the top msg = '%s \n%s currency updated. %s' % (