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.

67 lines
2.3 KiB

4 years ago
  1. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  2. from odoo import fields, models
  3. class StorageBackend(models.Model):
  4. _inherit = "storage.backend"
  5. synchronize_task_ids = fields.One2many(
  6. "attachment.synchronize.task", "backend_id", string="Tasks"
  7. )
  8. import_task_count = fields.Integer(
  9. "Import Tasks", compute="_compute_import_task_count"
  10. )
  11. export_task_count = fields.Integer(
  12. "Export Tasks", compute="_compute_export_task_count"
  13. )
  14. def _compute_import_task_count(self):
  15. for rec in self:
  16. rec.import_task_count = len(
  17. rec.synchronize_task_ids.filtered(lambda t: t.method_type == "import")
  18. )
  19. def _compute_export_task_count(self):
  20. for rec in self:
  21. rec.export_task_count = len(
  22. rec.synchronize_task_ids.filtered(lambda t: t.method_type == "export")
  23. )
  24. def action_related_import_task(self):
  25. self.ensure_one()
  26. act_window_xml_id = "attachment_synchronize.action_attachment_import_task"
  27. act_window = self.env.ref(act_window_xml_id).read()[0]
  28. domain = [
  29. ("id", "in", self.synchronize_task_ids.ids),
  30. ("method_type", "=", "import"),
  31. ]
  32. act_window["domain"] = domain
  33. if self.import_task_count == 1:
  34. form = self.env.ref("attachment_synchronize.view_attachment_task_form")
  35. act_window["views"] = [(form.id, "form")]
  36. act_window["res_id"] = (
  37. self.env["attachment.synchronize.task"].search(domain).id
  38. )
  39. return act_window
  40. def action_related_export_task(self):
  41. self.ensure_one()
  42. act_window_xml_id = "attachment_synchronize.action_attachment_export_task"
  43. act_window = self.env.ref(act_window_xml_id).read()[0]
  44. domain = [
  45. ("id", "in", self.synchronize_task_ids.ids),
  46. ("method_type", "=", "export"),
  47. ]
  48. act_window["domain"] = domain
  49. if self.export_task_count == 1:
  50. form = self.env.ref("attachment_synchronize.view_attachment_task_form")
  51. act_window["views"] = [(form.id, "form")]
  52. act_window["res_id"] = (
  53. self.env["attachment.synchronize.task"].search(domain).id
  54. )
  55. return act_window