python - Odoo 10:使用小部件显示调查数量
问题描述
我在客户表单视图中创建了一个调查按钮,它打开了包含分配给该客户的所有调查的视图。下面是截图:
现在我想在这个表单视图本身中显示分配给该客户的调查数量。就像有许多会议、机会、销售、问题、任务一样。我知道他们正在使用小部件以某种方式获取这些数字。但我无法弄清楚这些小部件是如何将这些数字带入表单视图的。有人可以指导我吗?
以下是我的调查按钮的代码:
<xpath expr='//div[@class="oe_button_box"]//button[@name="toggle_active"]' position='after'>
<button type="object" name="callSurvey" string="Survey" icon="survey.png" class="oe_stat_button"/>
</xpath>
解决方案
通过在模型中定义一个新字段并使用函数计算该字段来实现:
survey_count = fields.Integer(string="Survey", compute='compute_survey_count')
功能 :
@api.multi
def compute_survey_count(self):
for partner in self:
partner.survey_count = self.env['survey.user_input'].search_count([('email', '=', partner.email)])
views.xml 中的按钮:
<xpath expr='//div[@class="oe_button_box"]//button[@name="toggle_active"]' position='after'>
<button type="object" name="callSurvey" icon="contacts_custom/static/description/survey.png" class="oe_stat_button">
<field string="Surveys" name="survey_count" widget="statinfo" modifiers="{'readonly': true}"/>
</button>
</xpath>
推荐阅读
- javascript - React 将 this 绑定到类方法
- node.js - 使用带有 Universal Angular 5 的 Node.js 运行 Express Server 时出错
- scala - Foreach 循环遍历列表 Scala?
- list - 在 Haskell 中使用递归和模式匹配删除重复的列表元素
- r - geom_line() 仅使用默认的红色和蓝色,而不是 R ggplot 函数中指定的颜色
- python - ":=" 语法和赋值表达式:什么和为什么?
- r - 在反应部分 Rshiny 中使用输入变量
- smartcontracts - 我需要学习 haskell 才能在 Cardano 中编写 plutus 吗?
- git - 为本地分支创建远程跟踪分支而不与远程通信
- java - 将 InitBinder 与命令对象一起使用