Odoo Help


what is the id in product.product

Henry Lim
on 11/4/13, 10:28 PM 2,755 views

I have create new column called product_unit_cost in Bill Of Materials in the Components tab.


def _get_unit_cost(self, cr, uid, ids, field_name, arg, context):
        product_ids = self.pool.get('product.product').search(cr, uid, [('product_id', '=', uid)], context=context)
        prod = self.pool.get('product.product')
        prodobj = prod.browse(cr, uid, product_ids[0])
        res = prodobj.standard_price
        result = {}
        for id in ids:
            result[id] = res
        return result


'product_unit_cost' : fields.function(_get_unit_cost, type='many2one', relation="product.product", string="Product Unit Cost"),


<page string="Components">
                            <field name="bom_lines" widget="one2many_list">
                                <tree string="Components" editable="bottom">
                                    <field name="product_id" context="{'default_supply_method':'produce'}" on_change="onchange_product_id(product_id, name)"/>
                                    <field name="product_qty"/>
                                    <field name="product_uom" on_change="onchange_uom(product_id, product_uom)" groups="product.group_uom"/>
                                    <field name="product_unit_cost"/>
                                    <field name="name" invisible="1"/>
                                    <field name="date_start"/>
                                    <field name="date_stop"/>

Then it show me this error when I run:

File "/home/henry/openerp/7.0_20-09-13/server/openerp/osv/expression.py", line 642, in __init__
    self.parse(cr, uid, context=context)
  File "/home/henry/openerp/7.0_20-09-13/server/openerp/osv/expression.py", line 806, in parse
    raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
ValueError: Invalid field 'product_id' in leaf "<osv.ExtendedLeaf: ('product_id', '=', 1) on product_product (ctx: )>"
2013-11-05 02:25:13,890 8079 ERROR SydneyCakeHouseDB openerp.netsvc: Invalid field 'product_id' in leaf "<osv.ExtendedLeaf: ('product_id', '=', 1) on product_product (ctx: )>"

ValueError: Invalid field 'product_id' in leaf "<osv.ExtendedLeaf: ('product_id', '=', 1) on product_product (ctx: )>"

Please help! How can I get the id field in product.product? Please advise. thank you.

your function is wrong. You have assigned uid for product_id in search method. Remove that first. And can you explain on what condition are you wishing to access product_id in that function _get_unit_cost()?

Abhishek H Menon
on 11/5/13, 3:23 AM

Hi Abhishek, thank you for your reply. Actually i want the "Product Unit Cost" to be display in the bom_lines tree in the "Bill of Materials". The "Product Unit Cost" actually i want direct get from product.product table with the field name standard_price based on the product_id in the current bom_lines. So, how should I code my function? Please advise.

Henry Lim
on 11/5/13, 3:31 AM
Henry Lim
On 11/6/13, 1:09 AM

I have solved my issue:

def _get_total_cost(self, cr, uid, ids, field_name, arg, context):
        result = {}

        for bom_line_obj in self.browse(cr, uid, ids, context=context):
            result[bom_line_obj.id] = (bom_line_obj.product_id.product_tmpl_id.standard_price or 0.00) * (bom_line_obj.product_qty or 0.00)
        return result

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/4/13, 10:28 PM
Seen: 2755 times
Last updated: 3/16/15, 8:10 AM