'Return the ir.attachment records for a given bundle. This method takes care of mitigating
an issue happening when parallel transactions generate the same bundle: while the file is not
duplicated on the filestore (as it is stored according to its hash), there are multiple
ir.attachment records referencing the same version of a bundle. As we don\'t want to source
multiple time the same bundle in our `to_html` function, we group our ir.attachment records
by file name and only return the one with the max id for each group.'

def get_attachments(self, type):

    url_pattern = '/web/content/%-{0}/{1}{2}.{3}'.format(self.version, self.name, ('.%' if (type == 'css') else ''), type)
    self.env.cr.execute('\n                                                    SELECT    max(id)\n                                                            FROM    ir_attachment\n                                                        WHERE    url    like    %s\n                                            GROUP    BY    datas_fname\n                                            ORDER    BY    datas_fname\n                                    ', [url_pattern])
    attachment_ids = [r[0] for r in self.env.cr.fetchall()]
    return self.env['ir.attachment'].sudo().browse(attachment_ids)
