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
46 lines
1.5 KiB
# Copyright (C) 2015 - Today: GRAP (http://www.grap.coop)
|
|
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class PosPaymentChangeWizardLine(models.TransientModel):
|
|
_name = "pos.payment.change.wizard.line"
|
|
_description = "PoS Payment Change Wizard Line"
|
|
|
|
wizard_id = fields.Many2one(
|
|
comodel_name="pos.payment.change.wizard", required=True,
|
|
)
|
|
|
|
new_journal_id = fields.Many2one(
|
|
comodel_name="account.journal",
|
|
string="Journal",
|
|
required=True,
|
|
domain=lambda s: s._domain_new_journal_id(),
|
|
)
|
|
|
|
amount = fields.Float(string="Amount", required=True)
|
|
|
|
@api.model
|
|
def _domain_new_journal_id(self):
|
|
PosOrder = self.env["pos.order"]
|
|
order = PosOrder.browse(self.env.context.get("active_id"))
|
|
# return [("id", "in", order.session_id.journal_ids.ids)]
|
|
return [("id", "in", order.mapped(
|
|
"session_id.statement_ids.journal_id").ids)]
|
|
|
|
# View Section
|
|
@api.model
|
|
def default_get(self, fields):
|
|
res = super().default_get(fields)
|
|
if "line_ids" not in self._context:
|
|
return res
|
|
balance = self._context.get("amount_total", 0.0)
|
|
for line in self.wizard_id.resolve_2many_commands(
|
|
"line_ids",
|
|
self._context["line_ids"],
|
|
fields=["amount"]):
|
|
balance -= line.get("amount")
|
|
res.update({'amount': balance})
|
|
return res
|