From: Christophe Simonis Date: Wed, 29 Oct 2014 18:05:43 +0000 (+0100) Subject: [MERGE] forward port of branch 7.0 up to 43db726 X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;h=21b1203ee0f810cece33b1123998b1f0efe5b82c;p=odoo%2Fodoo.git [MERGE] forward port of branch 7.0 up to 43db726 --- 21b1203ee0f810cece33b1123998b1f0efe5b82c diff --cc addons/product/product.py index 38bb85e,ac0de1d..0c08dbb --- a/addons/product/product.py +++ b/addons/product/product.py @@@ -868,15 -770,35 +868,43 @@@ class product_product(osv.osv) args.append((('categ_id', 'child_of', context['search_default_categ_id']))) return super(product_product, self).search(cr, uid, args, offset=offset, limit=limit, order=order, context=context, count=count) + def open_product_template(self, cr, uid, ids, context=None): + """ Utility method used to add an "Open Template" button in product views """ + product = self.browse(cr, uid, ids[0], context=context) + return {'type': 'ir.actions.act_window', + 'res_model': 'product.template', + 'view_mode': 'form', + 'res_id': product.product_tmpl_id.id, + 'target': 'new'} + + def _compute_uos_qty(self, cr, uid, ids, uom, qty, uos, context=None): + ''' + Computes product's invoicing quantity in UoS from quantity in UoM. + Takes into account the + :param uom: Source unit + :param qty: Source quantity + :param uos: Target UoS unit. + ''' + if not uom or not qty or not uos: + return qty + uom_obj = self.pool['product.uom'] + product_id = ids[0] if isinstance(ids, (list, tuple)) else ids + product = self.browse(cr, uid, product_id, context=context) + if isinstance(uos, (int, long)): + uos = uom_obj.browse(cr, uid, uos, context=context) + if isinstance(uom, (int, long)): + uom = uom_obj.browse(cr, uid, uom, context=context) + if product.uos_id: # Product has UoS defined + # We cannot convert directly between units even if the units are of the same category + # as we need to apply the conversion coefficient which is valid only between quantities + # in product's default UoM/UoS + qty_default_uom = uom_obj._compute_qty_obj(cr, uid, uom, qty, product.uom_id) # qty in product's default UoM + qty_default_uos = qty_default_uom * product.uos_coeff + return uom_obj._compute_qty_obj(cr, uid, product.uos_id, qty_default_uos, uos) + else: + return uom_obj._compute_qty_obj(cr, uid, uom, qty, uos) + + -product_product() class product_packaging(osv.osv): _name = "product.packaging"