Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How to access to product.uos_id?

Alejandro Santana
on 2/18/14, 1:38 AM 1,872 views

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

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 2/25/14, 10:17 PM
Krupesh Laiya
On 2/18/14, 8:16 AM

apply loop on to browse like:

for value in product_obj.browse(cr, uid, product, context=context):
          uos_id = value.uos_id  # or value.uos_id.id


| 5 4 7
Bikaner, India

OpenERP Devloper at SunARC Technology

On 2/18/14, 2:20 AM

In Product table using produt_tmpl_id field you can get product template table field value

For Example,

product_obj = self.pool.get('product.product')
product_obj = product_obj.browse(cr, uid, product, context=context)

statndard_price =product_obj.product_tmpl_id.standard_price

uos_id = product_obj.product_tmpl_id.uos_id.id

Something wrong still. It now raises: standard_price = product.product_tmpl_id.standard_price AttributeError: 'browse_record_list' object has no attribute 'product_tmpl_id'

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 2/18/14, 3:36 PM

you can try with apply loop the code updated by Krupesh Laiya

on 2/19/14, 12:55 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)


Asked: 2/18/14, 1:38 AM
Seen: 1872 times
Last updated: 3/16/15, 8:10 AM