'Check attachment_use field. If set to true and an existing pdf is already saved, load
this one now. Else, mark save it.'

@api.model
def _check_attachment_use(self, docids, report):

    save_in_attachment = {}
    save_in_attachment['model'] = report.model
    save_in_attachment['loaded_documents'] = {}
    if report.attachment:
        records = self.env[report.model].browse(docids)
        filenames = self._attachment_filename(records, report)
        attachments = None
        if report.attachment_use:
            attachments = self._attachment_stored(records, report, filenames=filenames)
        for record_id in docids:
            filename = filenames[record_id]
            if attachments:
                attachment = attachments[record_id]
                if attachment:
                    pdf = attachment.datas
                    pdf = base64.decodestring(pdf)
                    save_in_attachment['loaded_documents'][record_id] = pdf
                    _logger.info(('The    PDF    document    %s    was    loaded    from    the    database' % filename))
                    continue
            if (filename is False):
                continue
            else:
                save_in_attachment[record_id] = filename
    return save_in_attachment
