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.

72 lines
2.2 KiB

  1. # Copyright 2016-2018 Sylvain LE GAL (https://twitter.com/legalsylvain)
  2. # Copyright 2018 Lambda IS DOOEL <https://www.lambda-is.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, fields, models
  5. class PosPartialReturnWizard(models.TransientModel):
  6. _name = 'pos.partial.return.wizard'
  7. order_id = fields.Many2one(
  8. comodel_name='pos.order',
  9. string='Order to Return',
  10. )
  11. line_ids = fields.One2many(
  12. comodel_name='pos.partial.return.wizard.line',
  13. inverse_name='wizard_id',
  14. string='Lines to Return',
  15. )
  16. def confirm(self):
  17. self.ensure_one()
  18. return self[0].order_id.partial_refund(self[0])
  19. @api.model
  20. def default_get(self, fields):
  21. order_obj = self.env['pos.order']
  22. res = super(PosPartialReturnWizard, self).default_get(fields)
  23. order = order_obj.browse(self.env.context.get('active_id', False))
  24. if order:
  25. line_ids = []
  26. for line in order.lines:
  27. line_ids.append((0, 0, {
  28. 'pos_order_line_id': line.id,
  29. 'initial_qty': line.qty,
  30. 'max_returnable_qty': line.max_returnable_qty([]),
  31. }))
  32. res.update({
  33. 'order_id': order.id,
  34. 'line_ids': line_ids})
  35. return res
  36. class PosPartialReturnWizardLine(models.TransientModel):
  37. _name = 'pos.partial.return.wizard.line'
  38. wizard_id = fields.Many2one(
  39. comodel_name='pos.partial.return.wizard',
  40. string='Wizard',
  41. )
  42. pos_order_line_id = fields.Many2one(
  43. comodel_name='pos.order.line',
  44. required=True,
  45. readonly=True,
  46. string='Line To Return',
  47. )
  48. initial_qty = fields.Float(
  49. string='Initial Quantity',
  50. readonly=True,
  51. help="Quantity of Product initially sold",
  52. )
  53. max_returnable_qty = fields.Float(
  54. string='Returnable Quantity',
  55. readonly=True,
  56. help="Compute maximum quantity that can be returned for this line, "
  57. "depending of the quantity of the line and other possible "
  58. "refunds.",
  59. )
  60. qty = fields.Float(
  61. string='Returned Quantity',
  62. default=0.0,
  63. )