From bb632e4ddacbef7c70a6047290e333206de42f38 Mon Sep 17 00:00:00 2001 From: Juan Jose Scarafia Date: Wed, 29 Jan 2014 10:14:17 -0300 Subject: [PATCH 1/2] [IMP] Make base currency based on currency maked as base and not related to company currency --- currency_rate_update/currency_rate_update.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/currency_rate_update/currency_rate_update.py b/currency_rate_update/currency_rate_update.py index afa3eb920..5062062a3 100644 --- a/currency_rate_update/currency_rate_update.py +++ b/currency_rate_update/currency_rate_update.py @@ -164,7 +164,7 @@ class Currency_rate_update(osv.Model): def run_currency_update(self, cr, uid): "update currency at the given frequence" factory = Currency_getter_factory() - curr_obj = self.pool.get('res_currency') + curr_obj = self.pool.get('res.currency') rate_obj = self.pool.get('res.currency.rate') companies = self.pool.get('res.company').search(cr, uid, []) for comp in self.pool.get('res.company').browse(cr, uid, companies): @@ -176,8 +176,18 @@ class Currency_rate_update(osv.Model): search_filter = [] if comp.multi_company_currency_enable : search_filter = [('company_id','=',comp.id)] - #we fetch the main currency. The main rate should be set at 1.00 - main_curr = comp.currency_id.name + #we fetch the main currency looking for currency with base = true. The main rate should be set at 1.00 + main_curr_ids = curr_obj.search(cr, uid, [('base','=',True),('company_id','=',comp.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 = curr_obj.search(cr, uid, [('base','=',True),('company_id','=', False)]) + if main_curr_ids: + main_curr_rec = curr_obj.browse(cr, uid, main_curr_ids[0]) + else: + print ('Error !', 'There is no base currency set!') + if main_curr_rec.rate != 1: + print ('Error !', 'Base currency rate should be 1.00!') + main_curr = main_curr_rec.name for service in comp.services_to_use : print "comp.services_to_use =", comp.services_to_use note = service.note or '' From f6cd5b225aaa044c089104e45a05a5a50dc33094 Mon Sep 17 00:00:00 2001 From: Juan Jose Scarafia Date: Tue, 4 Feb 2014 14:47:25 -0300 Subject: [PATCH 2/2] FIX replace print for orm.except_orm --- currency_rate_update/currency_rate_update.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/currency_rate_update/currency_rate_update.py b/currency_rate_update/currency_rate_update.py index 5062062a3..878a16a31 100644 --- a/currency_rate_update/currency_rate_update.py +++ b/currency_rate_update/currency_rate_update.py @@ -35,7 +35,7 @@ # a webservice to the list of currencies supported by the Webservice # TODO : implement max_delta_days for Yahoo webservice -from openerp.osv import fields, osv +from openerp.osv import fields, osv, orm import time from datetime import datetime, timedelta import logging @@ -184,9 +184,9 @@ class Currency_rate_update(osv.Model): if main_curr_ids: main_curr_rec = curr_obj.browse(cr, uid, main_curr_ids[0]) else: - print ('Error !', 'There is no base currency set!') + raise orm.except_orm(_('Error!'),('There is no base currency set!')) if main_curr_rec.rate != 1: - print ('Error !', 'Base currency rate should be 1.00!') + raise orm.except_orm(_('Error!'),('Base currency rate should be 1.00!')) main_curr = main_curr_rec.name for service in comp.services_to_use : print "comp.services_to_use =", comp.services_to_use