From 0333e4da027a0ea1bfc5c370e06e3b607655b40d Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Tue, 23 Dec 2014 16:58:31 +0100 Subject: [PATCH] [FIX] product: default category on UoM quick creation This revision adds the possibility to use the key `default_category_id` in the context to set the UoM category when quick creating a new UoM, like it's the case everywhere else with the `default_*` keys passed in the context. Closes #4407 --- addons/product/product.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index 45074b0e299..e1950861528 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -108,18 +108,21 @@ class product_uom(osv.osv): def name_create(self, cr, uid, name, context=None): """ The UoM category and factor are required, so we'll have to add temporary values for imported UoMs """ + if not context: + context = {} uom_categ = self.pool.get('product.uom.categ') + values = {self._rec_name: name, 'factor': 1} # look for the category based on the english name, i.e. no context on purpose! # TODO: should find a way to have it translated but not created until actually used - categ_misc = 'Unsorted/Imported Units' - categ_id = uom_categ.search(cr, uid, [('name', '=', categ_misc)]) - if categ_id: - categ_id = categ_id[0] - else: - categ_id, _ = uom_categ.name_create(cr, uid, categ_misc) - uom_id = self.create(cr, uid, {self._rec_name: name, - 'category_id': categ_id, - 'factor': 1}) + if not context.get('default_category_id'): + categ_misc = 'Unsorted/Imported Units' + categ_id = uom_categ.search(cr, uid, [('name', '=', categ_misc)]) + if categ_id: + values['category_id'] = categ_id[0] + else: + values['category_id'] = uom_categ.name_create( + cr, uid, categ_misc, context=context)[0] + uom_id = self.create(cr, uid, values, context=context) return self.name_get(cr, uid, [uom_id], context=context)[0] def create(self, cr, uid, data, context=None):