You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.1 KiB

  1. # coding: utf-8
  2. # @ 2016 Florian DA COSTA @ Akretion
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models, fields, api
  5. import base64
  6. import os
  7. class IrAttachmentMetadata(models.Model):
  8. _inherit = 'ir.attachment.metadata'
  9. task_id = fields.Many2one('external.file.task', string='Task')
  10. location_id = fields.Many2one(
  11. 'external.file.location', string='Location',
  12. related='task_id.location_id', store=True)
  13. file_type = fields.Selection(
  14. selection_add=[
  15. ('export_external_location',
  16. 'Export File (External location)')
  17. ])
  18. @api.multi
  19. def _run(self):
  20. super(IrAttachmentMetadata, self)._run()
  21. if self.file_type == 'export_external_location':
  22. protocols = self.env['external.file.location']._get_classes()
  23. location = self.location_id
  24. cls = protocols.get(location.protocol)[1]
  25. path = os.path.join(self.task_id.filepath, self.datas_fname)
  26. with cls.connect(location) as conn:
  27. datas = base64.decodestring(self.datas)
  28. conn.setcontents(path, data=datas)