sale_order.py 1.0 KB

123456789101112131415161718192021222324252627
  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. # For copyright and license notices, see __openerp__.py file in root directory
  4. ##############################################################################
  5. from openerp import models, api, exceptions, _
  6. class SaleOrder(models.Model):
  7. _inherit = "sale.order"
  8. @api.multi
  9. def button_draft(self):
  10. # go from canceled state to draft state
  11. for order in self:
  12. if order.state != 'cancel':
  13. raise exceptions.Warning(
  14. _("You can't back any order that it's not on cancel "
  15. "state. Order: %s" % order.name))
  16. order.order_line.write({'state': 'draft'})
  17. order.procurement_group_id.sudo().unlink()
  18. for line in order.order_line:
  19. line.procurement_ids.sudo().unlink()
  20. order.write({'state': 'draft'})
  21. order.delete_workflow()
  22. order.create_workflow()
  23. return True