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.

40 lines
1.5 KiB

7 years ago
7 years ago
  1. # Copyright 2011 Raphaël Valyi, Renato Lima, Guewen Baconnier, Sodexis
  2. # Copyright 2017 Akretion (http://www.akretion.com)
  3. # Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
  4. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  5. from odoo import api, fields, models, _
  6. from odoo.exceptions import ValidationError
  7. class ExceptionRuleConfirm(models.AbstractModel):
  8. _name = 'exception.rule.confirm'
  9. _description = 'Exception Rule Confirm Wizard'
  10. related_model_id = fields.Many2one('base.exception',)
  11. exception_ids = fields.Many2many(
  12. 'exception.rule',
  13. string='Exceptions to resolve',
  14. readonly=True,
  15. )
  16. ignore = fields.Boolean('Ignore Exceptions')
  17. @api.model
  18. def default_get(self, field_list):
  19. res = super(ExceptionRuleConfirm, self).default_get(field_list)
  20. current_model = self.env.context.get('active_model')
  21. model_except_obj = self.env[current_model]
  22. active_ids = self.env.context.get('active_ids')
  23. if len(active_ids) > 1:
  24. raise ValidationError(
  25. _('Only 1 ID accepted, got %r.') % active_ids)
  26. active_id = active_ids[0]
  27. related_model_except = model_except_obj.browse(active_id)
  28. exception_ids = related_model_except.exception_ids.ids
  29. res.update({'exception_ids': [(6, 0, exception_ids)]})
  30. res.update({'related_model_id': active_id})
  31. return res
  32. @api.multi
  33. def action_confirm(self):
  34. self.ensure_one()
  35. return {'type': 'ir.actions.act_window_close'}