hela hela - 3 months ago 41
Python Question

functional field odoo type float , new api

I'm trying to make an operation * on a field , i have tried functional fields but it didn't work , now i'm trying this @api.depends api , does it work with odoo 8 ? it still not work

class fleuret(osv.Model):
_inherit = "mrp.bom.line"
_columns = {
'unit_price' : fields.float(string='unit price', related='product_id.lst_price', store=True, readonly=True),
'amount' : fields.Float(string='price ',store=True, readonly=True,digits=dp.get_precision('Account'),compute='_compute_price'),
}
@api.one
@api.depends('product_qty')
def _compute_price(self):
self.amount =(unit_price * self.product_qty)

Answer
from openerp import models, fields, api
import openerp.addons.decimal_precision as dp

class fleuret(models.Model)
    _inherit = "mrp.bom.line"


    unit_price = fields.Float(
        string='unit price', related='product_id.lst_price',
        store=True, readonly=True)
    amount = fields.Float(
        string='price', store=True, digits=dp.get_precision('Account'),
        compute='_compute_price')

    @api.multi
    @api.depends('product_qty', 'unit_price')
    def _compute_price(self):
        for r in self:
            r.amount = r.unit_price * r.product_qty