Inherit field from one model to another model - Odoo v9 Community

拜拜、爱过 提交于 2019-12-04 20:33:55

The problem you have is that you're inheriting product.product and linking back to it again with a One2many field

If you want to add the product price to stock.move just delete the extra model that extends product.product and make a Many2one link like you've done in your stock.move model except that the model name is product.product

class StockMove(models.Model):
    _inherit = 'stock.move'

    price_unity = fields.Many2one("product.product", string="Precio", readonly=True)

This picks the object as a whole, but if you want only the price, then you'll have to use a related field

class StockMove(models.Model):
    _inherit = 'stock.move'

    product_id = fields.Many2one("product.product", "Product")
    price_unity = fields.Float(string="Precio", store=True, readonly=True, related="product_id.price")

Note: you don't need the product_id (the stock.move model already has a link to product.product with the same name), i just put it there to show you how related fields work

What about a related field on stock.move?

class StockMove(models.Model):
    _inherit = "stock.move"

    price_unity = fields.Float(
        string="Precio", related="product_id.price", readonly=True)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!