def _filestore(self): return config.filestore(self._cr.dbname)
def download_directory(self): """ Download related directory as a zip file. This method will be called by the Download button in VIEW Todo: Reads and writes in external folders, all the behavior should be inside a try...except block """ self.ensure_one() data_dir = config.filestore(self._cr.dbname) data_dir = os.path.abspath(data_dir) action = None # pylint: disable=locally-disabled, W0212 for record in self: ira_ids = record.mapped('ir_attachment_ids') if record.directory or ira_ids: zipname = u'{}.zip'.format(record.name) in_memory = BytesIO() zipf = zipfile.ZipFile(in_memory, 'w', zipfile.ZIP_DEFLATED) if record.directory: record._zipdir(record.directory, zipf) _logger.debug(in_memory.getbuffer().nbytes) for item in ira_ids: zipf.write( os.path.join(data_dir, Path(item.store_fname)), os.path.join('ir_attachments', item.datas_fname)) zipf.close() datas = base64.b64encode(in_memory.getvalue()) _logger.debug(u'zip size: %s', len(datas)) values = { 'name': zipname, 'datas': datas, 'datas_fname': zipname, 'res_model': record._name, 'res_id': record.id } if not record.zip_attachment_id: record.zip_attachment_id = \ record.zip_attachment_id.create(values) else: _id = record.zip_attachment_id.id record.zip_attachment_id.write(values) _id = record.zip_attachment_id.id _name = record.zip_attachment_id.name action = { 'type': 'ir.actions.act_url', 'url': DOWNLOAD_URL.format(id=_id, name=_name), 'nodestroy': True, 'target': 'new' } return action
def _filestore(self): return config.filestore(self._cr.dbname)
def caminho_sped(self): filestore = config.filestore(self._cr.dbname) return os.path.join(filestore, 'sped', limpa_formatacao(self.cnpj_cpf))