2016-08-15 433 views
1

我試圖做一個操作*在一個字段上,我已經試過功能領域,但它沒有工作,現在我試着這@ @ api.depends API,做到這一點與odoo 8一起工作?它仍然無法正常工作功能領域odoo類型float,新api

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) 
+0

在舊的API'Float'應該爲小寫,你是新舊API攪拌。 – Zety

回答

0
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 
+0

你可以解釋你做了什麼。 – Zety

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

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

    @api.one  
    @api.depends('product_qty') 
    def _compute_price(self): 
     self.amount =(self.unit_price * self.product_qty) 

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

它現在成爲xml的問題,unit_price和金額未知! – hela

+0

然後你做錯了什麼,該代碼片段是正確的,並與新的API完全兼容。 (@Hardik Patadia:api.one自Odoo V9以來已棄用) – CZoellner

+0

@CZoellner - 感謝您的信息。 –

1
from openerp.osv import osv, fields 
from openerp import models,api, _ 
import openerp.addons.decimal_precision as dp 
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), 
       'units_price' : 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.units_price = (self.unit_price * self.product_qty) 
+0

請在您的解決方案中添加說明? – Zety