[FIX] sale: proper guard of external ID resolution in config settings

ir.model.data.get_object() raises ValueErrors for missing references!

bzr revid: csn@openerp.com-20130129133631-d1kgb8b3wmdahy8s
This commit is contained in:
csn-openerp 2013-01-29 14:36:31 +01:00
parent efbb25bae3
commit 22c857caf3
1 changed files with 12 additions and 9 deletions

View File

@ -19,10 +19,14 @@
#
##############################################################################
import logging
from openerp.osv import fields, osv
from openerp import pooler
from openerp.tools.translate import _
_logger = logging.getLogger(__name__)
class sale_configuration(osv.osv_memory):
_inherit = 'sale.config.settings'
@ -81,8 +85,12 @@ Example: Product: this product is deprecated, do not purchase more than 5.
user = self.pool.get('res.users').browse(cr, uid, uid, context)
res['time_unit'] = user.company_id.project_time_mode_id.id
else:
product = ir_model_data.get_object(cr, uid, 'product', 'product_product_consultant')
res['time_unit'] = product.uom_id.id
try:
product = ir_model_data.get_object(cr, uid, 'product', 'product_product_consultant')
res['time_unit'] = product.uom_id.id
except ValueError:
# keep default value in that case
_logger.warning("Product with xml_id 'product.product_product_consultant' not found")
return res
def _get_default_time_unit(self, cr, uid, context=None):
@ -98,16 +106,11 @@ Example: Product: this product is deprecated, do not purchase more than 5.
wizard = self.browse(cr, uid, ids)[0]
if wizard.time_unit:
product = False
try:
product = ir_model_data.get_object(cr, uid, 'product', 'product_product_consultant')
except:
#product with xml_id product_product_consultant has not been found. Don't do anything except logging the exception
import logging
_logger = logging.getLogger(__name__)
_logger.warning("Warning, product with xml_id 'product_product_consultant' hasn't been found")
if product:
product.write({'uom_id': wizard.time_unit.id, 'uom_po_id': wizard.time_unit.id})
except ValueError:
_logger.warning("Product with xml_id 'product.product_product_consultant' not found, UoMs not updated!")
if wizard.module_project and wizard.time_unit:
user = self.pool.get('res.users').browse(cr, uid, uid, context)