2016-08-04 7 views
0

odoo見積もりや販売注文で総製品重量を計算したいのですが、その方法を書く方法がわからない、誰かが私にそれについてのヒントを与えることができますか?ここhere is in image total weight written in bottomodooで製品重量を計算するには?

class ProductWeight(models.Model): 
    _inherit = "sale.order" 

    th_weight = fields.Float('Weight') 

    @api.one 
    def _calcweight(self): 
     currentweight = 0 
     for weight in self.weight_ids: 
      currentweight = currentweight + weight.th_weight 
     self.weight_total = currentweight 

    weight_total = fields.Float('Total Weight', store=True, compute="_calcweight") 

は、上記の総重量を計算するための私の方法ですが、その権利はない、私に404エラーを与えます。

+0

私に404が見つかりませんでしたエラー –

+0

問題の[mcve]を共有できますか? 404は非常に具体的な意味を持つので、間違ってAPIを使用しているようです –

+0

これは私の完全なコードです。私は理解できない間違いを犯していると思います –

答えて

2

まあ、私は、ユーザーがそれを製品に関連しないように、あなたはth_weightフィールドを変更することができますどのような場合には製品マスタデータでパラメータの重みを設定する必要があります

from openerp import models, fields, api 

class ProductWeight(models.Model): 
    _inherit = 'sale.order.line' 
    th_weight = fields.Float(string='Weight', 
           store=True, 
           related='product_id.weight') 

class ProductWeightOrder(models.Model): 
    _inherit = 'sale.order' 
    @api.depends('order_line.th_weight') 
    def _calcweight(self): 
     currentweight = 0 
     for order_line in self.order_line: 
      currentweight = currentweight + order_line.th_weight 
     self.weight_total = currentweight 

    weight_total = fields.Float(compute='_calcweight', string='Total Weight') 

次のコードを使用することをお勧めこの情報を記入しなければならないでしょう

関連する問題