为什么我的 "group by" 过滤器不显示选择字段中的字符串?

Why my "group by" filter does not show the string from Selection field?

我有一个名为 "range_time" 的选择计算字段,定义如下:

range_time = fields.Selection([
        (1, '0 - 2'),
        (2, '2 - 4'),
        (3, '4 - 8'),
        (4, '8 - 24'),
        (5, '24 - 48'),
        (6, '48 - 72'),
        (7, '> 72'),
        ],
        string="Open range time",
        default=1,
        compute='compute_range_time')

def compute_range_time(self):
            for rec in self:
                # here rec.real_open_time is a float field that show the time in hours.
                if rec.real_open_time < 2.1:
                    rec.range_time = 1
                elif rec.real_open_time > 2 and rec.real_open_time < 4.1:
                    rec.range_time = 2
                elif rec.real_open_time > 4 and rec.real_open_time < 8.1:
                    rec.range_time = 3
                elif rec.real_open_time > 8 and rec.real_open_time < 24.1:
                    rec.range_time = 4
                elif rec.real_open_time > 24 and rec.real_open_time < 48.1:
                    rec.range_time = 5
                elif rec.real_open_time > 48 and rec.real_open_time < 72.1:
                    rec.range_time = 6
                elif rec.real_open_time > 72:
                    rec.range_time = 7

然后我创建了一个与 range_time 相关的字段,名为 r_range_time,定义如下:

r_range_time = fields.Selection([
        (1, '0 - 2'),
        (2, '2 - 4'),
        (3, '4 - 8'),
        (4, '8 - 24'),
        (5, '24 - 48'),
        (6, '48 - 72'),
        (7, '> 72'),
        ], related='range_time', store=True)

我创建了这个相关字段,因为我想使用这个字段来按过滤器进行分组。所以我做到了并且有效。 XML:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="account_search_view" model="ir.ui.view">
            <field name="name">Group By Tickets</field>
            <field name="model">website.support.ticket</field>
            <field name="inherit_id" ref="website_support.website_support_ticket_view_search"/>
            <field name="arch" type="xml">
                <filter name="group_by_user" position="after">
                    <filter name="group_by_range_time" string="Open time range" domain="[]" context="{'group_by':'r_range_time'}"/>
                 </filter>
             </field>
        </record>
    </data>
</odoo> 

唯一的问题是:

它不显示选择字段中的字符串。为什么会这样?有什么解决办法吗?

尝试将您的 range_time 值更改为字符串:

range_time = fields.Selection([
    ('1', '0 - 2'),
    ('2', '2 - 4'),
    ('3', '4 - 8'),
    ('4', '8 - 24'),
    ('5', '24 - 48'),
    ('6', '48 - 72'),
    ('7', '> 72'),
    ],
    string="Open range time",
    default='1',
    compute='compute_range_time')

所有相关的和输入的值也应该在字符串中