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.

74 lines
2.3 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. _description = 'Partial Return Wizard'
  8. order_id = fields.Many2one(
  9. comodel_name='pos.order',
  10. string='Order to Return',
  11. )
  12. line_ids = fields.One2many(
  13. comodel_name='pos.partial.return.wizard.line',
  14. inverse_name='wizard_id',
  15. string='Lines to Return',
  16. )
  17. def confirm(self):
  18. self.ensure_one()
  19. return self[0].order_id.partial_refund(self[0])
  20. @api.model
  21. def default_get(self, fields):
  22. order_obj = self.env['pos.order']
  23. res = super(PosPartialReturnWizard, self).default_get(fields)
  24. order = order_obj.browse(self.env.context.get('active_id', False))
  25. if order:
  26. line_ids = []
  27. for line in order.lines:
  28. line_ids.append((0, 0, {
  29. 'pos_order_line_id': line.id,
  30. 'initial_qty': line.qty,
  31. 'max_returnable_qty': line.max_returnable_qty([]),
  32. }))
  33. res.update({
  34. 'order_id': order.id,
  35. 'line_ids': line_ids})
  36. return res
  37. class PosPartialReturnWizardLine(models.TransientModel):
  38. _name = 'pos.partial.return.wizard.line'
  39. _description = 'Partial Return Wizard Line'
  40. wizard_id = fields.Many2one(
  41. comodel_name='pos.partial.return.wizard',
  42. string='Wizard',
  43. )
  44. pos_order_line_id = fields.Many2one(
  45. comodel_name='pos.order.line',
  46. required=True,
  47. readonly=True,
  48. string='Line To Return',
  49. )
  50. initial_qty = fields.Float(
  51. string='Initial Quantity',
  52. readonly=True,
  53. help="Quantity of Product initially sold",
  54. )
  55. max_returnable_qty = fields.Float(
  56. string='Returnable Quantity',
  57. readonly=True,
  58. help="Compute maximum quantity that can be returned for this line, "
  59. "depending of the quantity of the line and other possible "
  60. "refunds.",
  61. )
  62. qty = fields.Float(
  63. string='Returned Quantity',
  64. default=0.0,
  65. )