微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么在数据库中存储计算字段odoo10为空

如何解决为什么在数据库中存储计算字段odoo10为空

我想将字段 @Override public void onPrepareOptionsMenu(Menu menu) { MenuItem IconBTON = menu.findItem(R.id.myIcon); if (statusBluetooth == true){ IconBTON.setVisible(true); } if (statusBluetooth == false){ IconBTON.setVisible(false); } } 存储到 odoo 中的表 tot_comp_survey 中。
使用此代码

survey_survey


from odoo import api,fields,models class Survey(models.Model): _inherit = 'survey.survey' tot_comp_survey = fields.Integer("Number of completed surveys",compute="_compute_survey_statistic",store=True)

_compute_survey_statistic

结果如下:

enter image description here

我想要完全存储在数据库中的存储字段,但是当我将此代码应用于具有 1000 行的数据库时,数据库中的 @api.multi def _compute_survey_statistic(self): UserInput = self.env['survey.user_input'] sent_survey = UserInput.search([('survey_id','in',self.ids),('type','=','link')]) start_survey = UserInput.search(['&',('survey_id','|',('state','skip'),'done')]) complete_survey = UserInput.search([('survey_id','done')]) for survey in self: survey.tot_sent_survey = len(sent_survey.filtered(lambda user_input: user_input.survey_id == survey)) survey.tot_start_survey = len(start_survey.filtered(lambda user_input: user_input.survey_id == survey)) survey.tot_comp_survey = len(complete_survey.filtered(lambda user_input: user_input.survey_id == survey)) 为空。

enter image description here

有人可以帮我吗?
是不是少了什么?
补充说明:当我在小数据库(只有8行数据)中升级这段代码时,升级过程时间是正常的,但当我在大数据库(1000行和更多行数据)中升级时,升级过程非常缓慢。

解决方法

基本上它在需要时计算。您是否尝试访问任何记录?

尝试将 @api.depends('user_input_ids','user_input_ids.input_type','user_input_ids.state') 添加到函数头中。然后 Odoo 知道何时更改这些值。

您可能需要添加一些 One2many 字段

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。