sale_exception_confirm.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. #
  3. #
  4. # Copyright Camptocamp SA
  5. # @author: Guewen Baconnier
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. #
  21. from openerp import models, fields, api
  22. class SaleExceptionConfirm(models.TransientModel):
  23. _name = 'sale.exception.confirm'
  24. sale_id = fields.Many2one('sale.order', 'Sale')
  25. exception_ids = fields.Many2many('sale.exception',
  26. string='Exceptions to resolve',
  27. readonly=True)
  28. ignore = fields.Boolean('Ignore Exceptions')
  29. @api.model
  30. def default_get(self, field_list):
  31. res = super(SaleExceptionConfirm, self).default_get(field_list)
  32. order_obj = self.env['sale.order']
  33. sale_id = self._context.get('active_ids')
  34. assert len(sale_id) == 1, "Only 1 ID accepted, got %r" % sale_id
  35. sale_id = sale_id[0]
  36. sale = order_obj.browse(sale_id)
  37. exception_ids = [e.id for e in sale.exception_ids]
  38. res.update({'exception_ids': [(6, 0, exception_ids)]})
  39. res.update({'sale_id': sale_id})
  40. return res
  41. @api.one
  42. def action_confirm(self):
  43. if self.ignore:
  44. self.sale_id.ignore_exceptions = True
  45. return {'type': 'ir.actions.act_window_close'}