Odoo Help

Welcome!

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.

0

what is the id in product.product

By
Henry Lim
on 11/4/13, 10:28 PM 1,937 views

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

HERE IS MY FUNCTION:

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

HERE IS MY COLUMN FIELD:

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

HERE IS MY XML FILE:

<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"/>
                                </tree>
                            </field>
                        </page>

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
1
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

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

1 follower(s)

Stats

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