Odoo 15 帮助台格式化 ID 字段

Odoo 15 Helpdesk formatting ID field

我需要模块帮助台的帮助。我想通过插件将字段 ID 添加到树视图中。我可以设法做到这一点,但现在我想像这样设置字段的格式 Ticket ID:#1234,目前它的格式是:Ticket ID 1,234。我在源代码中也找不到字段 ID。

这是我的树视图代码:

<!-- Helpdesk Addon Tree View -->

  <record id="helpdesk_addon_tree_view" model="ir.ui.view">
    <field name="name">view.helpdesk.addon.tree</field>
    <field name="model">helpdesk.ticket</field>
    <field name="inherit_id" ref="helpdesk.helpdesk_tickets_view_tree"/>
    <field name="arch" type="xml">
      <field name="display_name" position="before">
        <field name="id" string="ID"/>
      </field>
      <field name="stage_id" position="after">
        <field name="create_date"/>
      </field>
    </field>
  </record>

</odoo>

id 是一个数字,您无法对其进行格式化,作为解决方法,您可以添加新的 Char 字段并覆盖创建方法来填充它,然后您可以在列表视图中使用新创建的字段.

from odoo import models, api, fields, _

class HelpdeskTicket(models.Model):
    _inherit = 'helpdesk.ticket'

    ticket_no = fields.Char(string="Ticket No")

                
    @api.model_create_multi
    def create(self, list_value):
        tickets = super(HelpdeskTicket, self).create(list_value)

        # set ticket Id
        for ticket in tickets:
            if ticket.id:
                ticket.ticket_no= '#' + str(ticket.id)
        return tickets

XML 将是:

<!-- Helpdesk Addon Tree View -->

  <record id="helpdesk_addon_tree_view" model="ir.ui.view">
    <field name="name">view.helpdesk.addon.tree</field>
    <field name="model">helpdesk.ticket</field>
    <field name="inherit_id" ref="helpdesk.helpdesk_tickets_view_tree"/>
    <field name="arch" type="xml">
      <field name="display_name" position="before">
        <field name="ticket_no" string="ID"/>
      </field>
      <field name="stage_id" position="after">
        <field name="create_date"/>
      </field>
    </field>
  </record>

</odoo>