<commit_before># -*- encoding: utf-8 -*-
from openerp import models, fields, api, _


class ProductTemplate(models.Model):
    _inherit = ['product.template']

    attachment_count = fields.Integer(compute='_compute_attachment_count', string="File")

    @api.multi
    def _compute_attachment_count(self):
        IrAttachment = self.env['ir.attachment']
        for ptemplate in self:
            ptemplate.attachment_count = IrAttachment.search_count([('res_model', '=', ptemplate._name), ('res_id', 'in', ptemplate.ids), ('product_downloadable', '=', True)])<commit_msg>[IMP] website_sale_digital : use read_group for computed fields<commit_after># -*- encoding: utf-8 -*-
from openerp import models, fields, api, _


class ProductTemplate(models.Model):
    _inherit = ['product.template']

    attachment_count = fields.Integer(compute='_compute_attachment_count', string="File")

    @api.multi
    def _compute_attachment_count(self):
        attachment_data = self.env['ir.attachment'].read_group([('res_model', '=', self._name), ('res_id', 'in', self.ids), ('product_downloadable', '=', True)], ['res_id'], ['res_id'])
        mapped_data = dict([(data['res_id'], data['res_id_count']) for data in attachment_data])
        for product_template in self:
            product_template.attachment_count = mapped_data.get(product_template.id, 0)
{'fraction_non_alphanumeric': 0.15247964470762398, 'fraction_numerical': 0.0022205773501110288, 'mean_word_length': 4.70464135021097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7311216', 'n_tokens_mistral': 407, 'n_tokens_neox': 397, 'n_words': 81}