Skip to Content
Menu
This question has been flagged
5 Replies
3744 Views

we use odoo 11.

model.py

    product_id = fields.Many2one('product.product', string="piece")   

    price_unit = fields.Float('Unit Price', default=0.0)  

view.xml

<page string="Replacement piece">
    <field name="product_ids">
        <tree editable="bottom">
            <field name="product_id"/>
            <field name="price_unit"/>
        </tree>
    </field>
</page>

please help me.

Thanks


Avatar
Discard
Author

Hi Avinash, Thanks. You helped a lot

My Pleasure

Hello Sana, Sorry. There is an Update in the answer. Please try this. Don't do the previous answer.

Best Answer

Hello,

Try the OnChange method.


@api.onchange('product_id')
def onchange_product_id(self):
self.price_unit = self.product_id.standard_price or 0.0

self.product_id.standard_price for Cost Price
self.product_id.lst_price for Sales Price


Thanks & Regards

Avinash N K

Avatar
Discard
Best Answer

You can use compute functions with @api.depends('product_id')

eg:-

@api.depends('product_variant_ids')
    def _compute_product_variant_id(self):
        for p in self:
            p.product_variant_id = p.product_variant_ids[:1].id

product_variant_id = fields.Many2one('product.product', 'Product', compute='_compute_product_variant_id')



Avatar
Discard