Odoo:one2many 中的值在 api.depends 中没有变化

Odoo : Value in one2many doen't change in api.depends

我有 3 个模型,这是每个模型的有趣部分:

投票:

class vote(osv.osv)

_name = 'vote'

_columns = {
    name = fields.many2one('res.partner', 
                                            'Member of enterprise',
                                            select=True),

    type = fields.interger('Type'),
}

history_line:

class history_line(osv.osv)

_name = 'history_line'

_columns = {
    fieldsA = fields.integer('First field'),
    fieldB = fields.integer('Second field'),
    this_id = fields.many2one('res.partner', 'link to res'),
}

res_partner:

class res_partner(osv.osv)

_inherit = 'res.partner'

_columns = {
    vote_partner_ids = fields.one2many('vote', 
                                            'name',
                                            'Voted peoples',
                                            select=True),

    vote_history_ids = fields.one2many('history.line',
                                              'this_id',
                                              compute='compute_type', 
                                              string='History of votes'),
}

@api.multi
@api.depends('vote_partner_ids.type')
def compute_type(self):
    for record in self:
        if self.vote_partner_ids.type:
            record.vote_history_ids = [(0, 0, {'self.vote_history_ids.fieldA': self.vote_partner_ids.type + 4,
                                                'self.vote_history_ids.fieldB': self.vote_partner_ids.type - 2})]

它们也是新 history_line 的默认值(例如,当您什么都不做时,fieldA = 1,当您什么都不做时,fieldB = -1)

我无法将我的计算功能移到别处,因为很多东西都在这里计算。

问题是:当我修改投票类型时,将创建一个新的历史行,但使用默认值。我不能让价值观成为其他任何东西。 (即使我直接输入一个值,比如 10) 那么为什么选择默认值,即使我要求它们被计算,但它仍然理解它必须创建一个新的元组?

您不必为要更改的字段添加 "PATH",删除 self.vote_history_ids。在要更改的字段之前取决于:

@api.multi
@api.depends('vote_partner_ids.type')
def compute_type(self):
    for record in self:
        if self.vote_partner_ids.type:
            record.vote_history_ids = [(0, 0, {'fieldA': self.vote_partner_ids.type + 4,
                                                'fieldB': self.vote_partner_ids.type - 2})]