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.

46 lines
1.5 KiB

  1. # Copyright (C) 2015 - Today: GRAP (http://www.grap.coop)
  2. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, fields, models
  5. class PosPaymentChangeWizardLine(models.TransientModel):
  6. _name = "pos.payment.change.wizard.line"
  7. _description = "PoS Payment Change Wizard Line"
  8. wizard_id = fields.Many2one(
  9. comodel_name="pos.payment.change.wizard", required=True,
  10. )
  11. new_journal_id = fields.Many2one(
  12. comodel_name="account.journal",
  13. string="Journal",
  14. required=True,
  15. domain=lambda s: s._domain_new_journal_id(),
  16. )
  17. amount = fields.Float(string="Amount", required=True)
  18. @api.model
  19. def _domain_new_journal_id(self):
  20. PosOrder = self.env["pos.order"]
  21. order = PosOrder.browse(self.env.context.get("active_id"))
  22. # return [("id", "in", order.session_id.journal_ids.ids)]
  23. return [("id", "in", order.mapped(
  24. "session_id.statement_ids.journal_id").ids)]
  25. # View Section
  26. @api.model
  27. def default_get(self, fields):
  28. res = super().default_get(fields)
  29. if "line_ids" not in self._context:
  30. return res
  31. balance = self._context.get("amount_total", 0.0)
  32. for line in self.wizard_id.resolve_2many_commands(
  33. "line_ids",
  34. self._context["line_ids"],
  35. fields=["amount"]):
  36. balance -= line.get("amount")
  37. res.update({'amount': balance})
  38. return res