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.

44 lines
1.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2017-2018 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, fields, models
  5. class SubscriptionSubscription(models.Model):
  6. _inherit = 'subscription.subscription'
  7. server_action_id = fields.Many2one(
  8. 'ir.actions.server', string='Run action',
  9. help='If you need to run multiple actions, use an umbrella action',
  10. )
  11. model_id = fields.Many2one('ir.model', compute='_compute_model_id')
  12. @api.multi
  13. def model_copy(self):
  14. old_history = self.env['subscription.subscription.history'].search([
  15. ('subscription_id', 'in', self.ids),
  16. ])
  17. result = super(SubscriptionSubscription, self).model_copy()
  18. new_history = self.env['subscription.subscription.history'].search([
  19. ('subscription_id', 'in', self.ids),
  20. ])
  21. for history_item in new_history - old_history:
  22. action = history_item.subscription_id.server_action_id
  23. record = history_item.document_id
  24. if not action:
  25. continue
  26. action.with_context(
  27. active_id=record.id, active_ids=record.ids,
  28. active_model=record._name,
  29. ).run()
  30. return result
  31. @api.multi
  32. @api.depends('doc_source')
  33. def _compute_model_id(self):
  34. for this in self:
  35. if not this.doc_source:
  36. continue
  37. this.model_id = self.env['ir.model'].search([
  38. ('model', '=', this.doc_source._name),
  39. ], limit=1)