I am trying to extend a bit product and sale modules, yet in version 6.1 In some onchange functions in sale_order_line, I call a method in product.product. Something like this:
def _compute_qty_swap_uom_uos(self, cr, uid,
product_id, swap_type='uom2uos', from_uom_id=False,
qty=False, to_uom_id=False, context=None):
There, I pass the new, actual values from a form (product_id, from_uom_id, qty, to_uom_id). Then, inside this method, I try to check if the product itself has an 'uos_id' defined or not, like this:
product_obj = self.pool.get('product.product')
product = product_obj.browse(cr, uid, product_id, context=context)
def_uos_id = product.uos_id
_logger.debug('[_compute_price_swap_uom_uos] def_uos_id = {}'.format(def_uos_id))
if not def_uos_id or not product.uos_coeff:
pass # whatever things to do
But no matter what, I am not able to access it and I get this message:
(...)
File "/opt/openerp/testing/openerp_61_ocb_devel/all-addons/product_list_price_uos/product.py", line 64, in _compute_qty_swap_uom_uos
def_uos_id = product.uos_id
AttributeError: 'browse_record_list' object has no attribute 'uos_id'
I have also tried with:
def_uos_id = product.uos_id.id
with same result.
Variable 'uos_id' is in product.template, but I should be able to access it through product.product due to inheritance. In fact, I am not even able to access product.product variables, like 'price'.
What am I missing or doing plainly wrong?
All my own fault. I was passing a None to product_id. Otherwise, it works nice, since I only need one product_id. So, Kupresh Laiya's answer is correct, but don't need it in this specific case. Also, it worked with just product.uos_id, no need for product.uos_id.id