2016-08-15 9 views
1

フィールドに操作*をしようとしていますが、機能フィールドを試しましたが機能しませんでしたが、今はこの@ api.depends APIを試しています。 odoo 8で作業しますか?それはまだ古いAPIで機能フィールド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

に動作しない '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とamountは分かっていない! – hela

+0

次に、何かが間違っている、そのコードスニペットが正しいと完全に新しいAPIと互換性があります。 (@ Hardik Patadia:apoo.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

関連する問題