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"