如何在Odoo10中添加One2many字段中特定列的值

时间:2017-10-05 06:34:27

标签: python-2.7 api openerp odoo-10

我在One2many字段中有一个One2many字段和三个字段' name',#39; weight'和'价格'。我希望所有的价值都是“重量”。从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代码:

<group>
    <field name="machine_weight_id" style="width:630px">

        <tree editable="bottom">
            <field name="pet"/>
            <field name="weight"/>
            <field name="price"/>
            <field name="sum"/>
        </tree>
    </field>
</group>

1 个答案:

答案 0 :(得分: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