stock.py 882 B

12345678910111213141516171819202122232425262728
  1. # -*- coding: utf-8 -*-
  2. # © 2016 Lorenzo Battistini - Agile Business Group
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp import models, api
  5. from openerp.exceptions import Warning as UserError
  6. from openerp.tools.translate import _
  7. class StockMove(models.Model):
  8. _inherit = 'stock.move'
  9. @api.multi
  10. def action_back_to_draft(self):
  11. if self.filtered(lambda m: m.state != 'cancel'):
  12. raise UserError(_("You can set to draft cancelled moves only"))
  13. self.write({'state': 'draft'})
  14. class StockPicking(models.Model):
  15. _inherit = 'stock.picking'
  16. @api.multi
  17. def action_back_to_draft(self):
  18. if self.filtered(lambda p: p.state != 'cancel'):
  19. raise UserError(_("You can set to draft cancelled pickings only"))
  20. moves = self.mapped('move_lines')
  21. moves.action_back_to_draft()