[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:
Stefan Rijnhart 2014-12-23 16:58:31 +01:00 committed by Denis Ledoux
parent 68eaeb684d
commit 0333e4da02
1 changed files with 12 additions and 9 deletions

View File

@ -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):