【问题标题】:Odoo 10 : Using widgets to show number of surveyOdoo 10:使用小部件显示调查数量
【发布时间】:2019-03-22 03:23:04
【问题描述】:

我在客户表单视图中创建了一个调查按钮,该按钮打开了包含分配给该客户的所有调查的视图。下面是截图:

现在我想在此表单视图本身中显示分配给该客户的调查数量。就像有许多会议、机会、销售、问题、任务一样。我知道他们正在使用小部件以某种方式获取这些数字。但我无法弄清楚这些小部件是如何将这些数字带入表单视图的。有人可以指导我吗?

下面是我的调查按钮的代码:

<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>

【问题讨论】:

    标签: python xml button widget odoo


    【解决方案1】:

    通过在模型中定义一个新字段并使用函数计算该字段来实现:

    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-21
      • 2016-09-25
      • 2023-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-13
      相关资源
      最近更新 更多