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.

56 lines
1.8 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.new.line"
  7. _description = "PoS Payment Change Wizard New 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. company_currency_id = fields.Many2one(
  18. comodel_name='res.currency', store=True,
  19. related='new_journal_id.currency_id',
  20. string="Company Currency", readonly=True,
  21. help='Utility field to express amount currency'
  22. )
  23. amount = fields.Monetary(
  24. string="Amount",
  25. required=True, default=0.0,
  26. currency_field='company_currency_id'
  27. )
  28. @api.model
  29. def _domain_new_journal_id(self):
  30. PosOrder = self.env["pos.order"]
  31. order = PosOrder.browse(self.env.context.get("active_id"))
  32. return [("id", "in", order.mapped(
  33. "session_id.statement_ids.journal_id").ids)]
  34. # View Section
  35. @api.model
  36. def default_get(self, fields):
  37. res = super().default_get(fields)
  38. if "new_line_ids" not in self._context:
  39. return res
  40. balance = self._context.get("amount_total", 0.0)
  41. for line in self.wizard_id.resolve_2many_commands(
  42. "new_line_ids",
  43. self._context["new_line_ids"],
  44. fields=["amount"]):
  45. balance -= line.get("amount")
  46. res.update({'amount': balance})
  47. return res