2017-10-05 106 views
1

我在One2many字段'name','weight'和'price'內有一個One2many字段和三個字段。我想要從One2many字段的多行中添加'weight'字段的所有值。如何在Odoo10中添加One2many字段中的特定列的值

我的Python和XML代碼是在這裏:

Python代碼:

class body_processing(models.Model): 
    _name = 'body.processing' 

    machine_weight_id = fields.One2many('machine.weight', 'machine_id', string='Weight Machine') 

class machine_weight(models.Model): 
    _name = 'machine.weight' 


@api.depends('weight','sum', 'machine_id') 
    def _onchange_amount_weight(self): 
     sum = 0.0 
     vals = 0.0 
     for line in self.machine_id: 
      vals = line.weight + line.sum 
      print"a", vals 
      line.sum = line.vals 
      print"b", line.sum 
      line.sum += line.weight 
      print"c", line.sum 

machine_id = fields.Many2one('sale.pet', string='Machine Weight', ondelete='cascade', index=True, 
          copy=False) 
pet = fields.Char() 
weight = fields.Integer() 
price = fields.Integer() 
sum = fields.Integer('SUM', change_default = True, default= _onchange_amount_weight) 

XML代碼:

回答

0

對於這個問題,我應用的另一個功能,我伸手打印每場的重量值。但是如何從每一行獲取價值權重並添加該值?

我的功能是在這裏:

@api.onchange('machine_weight_id') 
    def _onchange_amount_weight(self): 
     weight_obj = self.machine_weight_id 
     print "a:", weight_obj 
     for vals in weight_obj: 
      print"v::", vals 
      print "s", vals.weight 
      print'sum', vals.weight 
相關問題