# -*- coding: utf-8 -*- from odoo import api, fields, models class HelpdeskTicket(models.Model): _inherit = 'helpdesk.ticket' rating_stars_html = fields.Html( string='Rating Stars', compute='_compute_rating_stars_html', help='HTML representation of rating stars' ) @api.depends('rating_ids', 'rating_ids.rating', 'rating_ids.create_date', 'rating_count') def _compute_rating_stars_html(self): """Compute HTML representation of rating stars""" # Unicode star characters filled_star = '★' # U+2605 BLACK STAR empty_star = '☆' # U+2606 WHITE STAR for ticket in self: # Flush to ensure rating_ids is up to date ticket.flush_recordset() # Use rating_ids which is a One2many field that exists on helpdesk.ticket # Filter for ratings with value > 0 and sort by create_date descending valid_ratings = ticket.rating_ids.filtered(lambda r: r.rating > 0) if valid_ratings: # Get the most recent rating rating = valid_ratings.sorted(key=lambda r: r.create_date or fields.Datetime.now(), reverse=True)[0] # Calculate filled and empty stars rating_int = round(rating.rating) filled_count = rating_int empty_count = 5 - rating_int # Generate HTML with stars html = '' html += '' + (filled_star * filled_count) + '' html += '' + (empty_star * empty_count) + '' html += '' ticket.rating_stars_html = html else: # No rating or zero rating - display "Not Rated" or empty stars ticket.rating_stars_html = '' + \ '' + (empty_star * 5) + '' + \ ''