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.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
  3. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from openerp import models, fields, api
  6. class PosPartialReturnWizard(models.TransientModel):
  7. _name = 'pos.partial.return.wizard'
  8. order_id = fields.Many2one(
  9. comodel_name='pos.order', string='Order to Return')
  10. line_ids = fields.One2many(
  11. comodel_name='pos.partial.return.wizard.line',
  12. inverse_name='wizard_id', string='Lines to Return')
  13. @api.multi
  14. def confirm(self):
  15. self.ensure_one()
  16. return self[0].order_id.partial_refund(self[0])
  17. @api.model
  18. def default_get(self, fields):
  19. order_obj = self.env['pos.order']
  20. res = super(PosPartialReturnWizard, self).default_get(fields)
  21. order = order_obj.browse(self.env.context.get('active_id', False))
  22. if order:
  23. line_ids = []
  24. for line in order.lines:
  25. line_ids.append((0, 0, {
  26. 'pos_order_line_id': line.id,
  27. 'initial_qty': line.qty,
  28. 'max_returnable_qty': line.max_returnable_qty([]),
  29. }))
  30. res.update({
  31. 'order_id': order.id,
  32. 'line_ids': line_ids})
  33. return res