'get the repatition of rating grade for the given res_ids.
:param add_stats : flag to add stat to the result
:type add_stats : boolean
:param domain : optional extra domain of the rating to include/exclude in repartition
:return dictionnary
if not add_stats, the dict is like
- key is the rating value (integer)
- value is the number of object (res_model, res_id) having the value
otherwise, key is the value of the information (string) : either stat name (avg, total, ...) or \'repartition\'
containing the same dict if add_stats was False.'

@api.multi
def rating_get_repartition(self, add_stats=False, domain=None):

    base_domain = [('res_model', '=', self._name), ('res_id', 'in', self.ids), ('rating', '>=', 1), ('consumed', '=', True)]
    if domain:
        base_domain += domain
    data = self.env['rating.rating'].read_group(base_domain, ['rating'], ['rating', 'res_id'])
    values = dict.fromkeys(range(1, 11), 0)
    values.update(((d['rating'], d['rating_count']) for d in data))
    if add_stats:
        rating_number = sum(values.values())
        result = {'repartition': values, 'avg': ((sum([float((key * values[key])) for key in values]) / rating_number) if (rating_number > 0) else 0), 'total': reduce((lambda x, y: (y['rating_count'] + x)), data, 0)}
        return result
    return values
