【问题标题】:Value not update in one2many field with compute method Odoo12使用计算方法 Odoo12 在 one2many 字段中的值未更新
【发布时间】:2019-12-02 05:53:17
【问题描述】:

我下面在 one2many 字段中插入值的方法适用于 onchange 方法和带有依赖装饰器的 compute 方法。但我的要求并没有完全满足依赖装饰器。我的方法应该适用于视图负载。目前方法调用,我在终端上用 print 进行了测试,但 o2many 字段中的值仍然没有更新。

survey_user_input = fields.One2many('customer.survey', 'partner_id', compute='user_survey_output')

@api.one
def user_survey_output(self):
    print('TESSSSSSSSSSSSSSSSSSSS')
    Survey_user_input = self.env['survey.user_input']
    s_list = []
    value = {}
    for val in self:
        User_input = Survey_user_input.search(['|', ('partner_id', '=', val.id), ('email', '=', val.email)])
        for rec in User_input:
            data = {'partner_id': val.id,
                    'user_input_id': rec.id,
                    'survey_id': rec.survey_id.id,
                    'date_create': rec.date_create,
                    'deadline': rec.deadline,
                    'type': rec.type,
                    'state': rec.state,
                    }
            s_list.append((0, 0, data))
        value.update(survey_user_input=s_list)
        print('LLLLLLLLLLLLLLL', value)
        return {'value': value}

提前致谢。

【问题讨论】:

  • 您在哪个模型中创建了 survey_user_input 字段?您准备了动态字典并返回它,但它在哪里使用?
  • 在“res.partner”模型中我创建了survey_user_input字段。

标签: odoo insert-update odoo-12 one2many


【解决方案1】:

survey_user_input 是一个computed field,因此它必须将计算值分配给该字段。

如果它使用其他字段的值,它应该使用depends()指定这些字段(email字段用于search方法)。

@api.depends('email')
def user_survey_output(self):
    Survey_user_input = self.env['survey.user_input']
    for val in self:
        s_list = []
        # Loop body used to fill "s_list"
        val.survey_user_input = s_list

【讨论】:

  • 我在依赖中使用了电子邮件,但它仍然没有在搜索时自动更新字段。
  • 我在“res.partner”模型中使用 one2many 字段,而 co_model 是“survey.survey”。我想在调查模型发生更改时更新此字段。所以,取决于我的情况下没有使用的装饰器。
  • 您有任何与调查相关的字段吗?
  • partner_id 或 id 字段
  • 能否更新您的问题并添加字段?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-21
  • 1970-01-01
  • 1970-01-01
  • 2017-05-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多