Search code examples
pythonpython-3.xodooodoo-12

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


I have a Selection computed field called "range_time", defined like this:

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

Then I created a related field to range_time called r_range_time, defined like this:

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)

I created this related field because I want to use this field to make a group by filter. So I did it and it works. The 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> 

The only problem is this: List view

It doesn't show the string from the selection field. Why this happen? Any solution?


Solution

  • try changing your range_time value to string:

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

    And all the related and entered value should be in string too