【问题标题】:How to display label of a field in qweb reports?如何在 qweb 报告中显示字段的标签?
【发布时间】:2018-11-09 15:13:36
【问题描述】:

有没有办法在 qweb 报告中显示我们放在字段上的标签?

例如

在我的 .py 中

findings = fields.Text(string="Findings")

在我的 .xml 文件中

<t t-esc="findings" /> <!-- only shows the value -->

我们也可以在qweb中获取标签吗?

【问题讨论】:

    标签: odoo odoo-8 qweb


    【解决方案1】:

    您无法获取该字段的标签。 相反,您可以添加 html 标签来显示标签

    例如:

    <p>Your Label <t t-esc="findings" /> </p>
    
     or
    <span> Some Text <t t-esc="findings" /> </span>
    

    【讨论】:

    • 无法在 qweb 报告中获得该字段的标签非常令人失望
    【解决方案2】:

    您可以使用函数获取字段描述(标签),但我鼓励您像在 odoo invoice reports 中那样显示标签。

    获取date_invoice标签:

    def get_field_label(self, model_name, field_name):
        ir_model_obj = self.env['ir.model']
        ir_model_fields_obj = self.env['ir.model.fields']
        model_id = ir_model_obj.search([('model', '=', model_name)], limit=1)
        field_id = ir_model_fields_obj.search([('name', '=', field_name), ('model_id', '=', model_id.id)], limit=1)
    
        return field_id.field_description
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多