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.

39 lines
1.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. # @ 2016 Florian DA COSTA @ Akretion
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. import os
  4. from odoo import api, models, fields
  5. class AttachmentQueue(models.Model):
  6. _inherit = "attachment.queue"
  7. task_id = fields.Many2one("attachment.synchronize.task", string="Task")
  8. method_type = fields.Selection(related="task_id.method_type")
  9. storage_backend_id = fields.Many2one(
  10. "storage.backend",
  11. string="Storage Backend",
  12. related="task_id.backend_id",
  13. store=True,
  14. )
  15. file_type = fields.Selection(
  16. selection_add=[("export", "Export File (External location)")]
  17. )
  18. def _run(self):
  19. super()._run()
  20. if self.file_type == "export":
  21. path = os.path.join(self.task_id.filepath, self.datas_fname)
  22. self.storage_backend_id._add_b64_data(path, self.datas)
  23. def _get_failure_emails(self):
  24. res = super()._get_failure_emails()
  25. if self.task_id.failure_emails:
  26. res = self.task_id.failure_emails
  27. return res
  28. @api.onchange("task_id")
  29. def onchange_task_id(self):
  30. for attachment in self:
  31. if attachment.task_id.method_type == "export":
  32. attachment.file_type = "export"