[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
This commit is contained in:
parent
68eaeb684d
commit
0333e4da02
|
@ -108,18 +108,21 @@ class product_uom(osv.osv):
|
||||||
def name_create(self, cr, uid, name, context=None):
|
def name_create(self, cr, uid, name, context=None):
|
||||||
""" The UoM category and factor are required, so we'll have to add temporary values
|
""" The UoM category and factor are required, so we'll have to add temporary values
|
||||||
for imported UoMs """
|
for imported UoMs """
|
||||||
|
if not context:
|
||||||
|
context = {}
|
||||||
uom_categ = self.pool.get('product.uom.categ')
|
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!
|
# 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
|
# TODO: should find a way to have it translated but not created until actually used
|
||||||
categ_misc = 'Unsorted/Imported Units'
|
if not context.get('default_category_id'):
|
||||||
categ_id = uom_categ.search(cr, uid, [('name', '=', categ_misc)])
|
categ_misc = 'Unsorted/Imported Units'
|
||||||
if categ_id:
|
categ_id = uom_categ.search(cr, uid, [('name', '=', categ_misc)])
|
||||||
categ_id = categ_id[0]
|
if categ_id:
|
||||||
else:
|
values['category_id'] = categ_id[0]
|
||||||
categ_id, _ = uom_categ.name_create(cr, uid, categ_misc)
|
else:
|
||||||
uom_id = self.create(cr, uid, {self._rec_name: name,
|
values['category_id'] = uom_categ.name_create(
|
||||||
'category_id': categ_id,
|
cr, uid, categ_misc, context=context)[0]
|
||||||
'factor': 1})
|
uom_id = self.create(cr, uid, values, context=context)
|
||||||
return self.name_get(cr, uid, [uom_id], context=context)[0]
|
return self.name_get(cr, uid, [uom_id], context=context)[0]
|
||||||
|
|
||||||
def create(self, cr, uid, data, context=None):
|
def create(self, cr, uid, data, context=None):
|
||||||
|
|
Loading…
Reference in New Issue