Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
5 Răspunsuri
4217 Vizualizări

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


Imagine profil
Abandonează
Autor

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.

Cel mai bun răspuns

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

Imagine profil
Abandonează
Cel mai bun răspuns

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')



Imagine profil
Abandonează