From 168a07ece03570162ea05ab1b996c4d09b3cfcfb Mon Sep 17 00:00:00 2001 From: Vicente Date: Thu, 13 Apr 2023 14:28:36 +0200 Subject: [PATCH] [IMP] pos_pms_link: remove reservation payments at the end of the pos.session --- pos_pms_link/models/__init__.py | 3 +- pos_pms_link/models/pos_session.py | 60 ++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 pos_pms_link/models/pos_session.py diff --git a/pos_pms_link/models/__init__.py b/pos_pms_link/models/__init__.py index 5fdfc6458..1146e6879 100755 --- a/pos_pms_link/models/__init__.py +++ b/pos_pms_link/models/__init__.py @@ -24,4 +24,5 @@ from . import pos_config from . import pos_payment from . import pms_reservation from . import pms_service -from . import product_pricelist \ No newline at end of file +from . import product_pricelist +from . import pos_session \ No newline at end of file diff --git a/pos_pms_link/models/pos_session.py b/pos_pms_link/models/pos_session.py new file mode 100644 index 000000000..b802d6dbe --- /dev/null +++ b/pos_pms_link/models/pos_session.py @@ -0,0 +1,60 @@ +############################################################################## +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +# Copyright (C) 2023 Comunitea Servicios Tecnológicos S.L. All Rights Reserved +# Vicente Ángel Gutiérrez +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import json +from odoo import api, fields, models, _ +from odoo.exceptions import Warning, UserError + +import logging +_logger = logging.getLogger(__name__) + + +class PosSession(models.Model): + _inherit = 'pos.session' + + def _accumulate_amounts(self, data): + res = super(PosSession, self)._accumulate_amounts(data) + if self.config_id.pay_on_reservation and self.config_id.pay_on_reservation_method_id: + reservation_orders = self.order_ids.filtered(lambda x: x.pms_reservation_id) + reservation_taxes = sum([order.amount_tax for order in reservation_orders]) + reservation_no_taxes = sum([order.amount_total - order.amount_tax for order in reservation_orders]) + + for element, value in dict(res["taxes"]).items(): + value['amount'] = value['amount'] + reservation_taxes + value['amount_converted'] = value['amount_converted'] + reservation_taxes + value['base_amount'] = value['base_amount'] + reservation_no_taxes + value['base_amount_converted'] = value['base_amount_converted'] + reservation_no_taxes + + for element, value in dict(res["sales"]).items(): + value['amount'] = value['amount'] - reservation_no_taxes + value['amount_converted'] = value['amount_converted'] - reservation_no_taxes + + if self.config_id.pay_on_reservation_method_id.split_transactions: + for element, value in dict(res["split_receivables"]).items(): + if element.payment_method_id == self.config_id.pay_on_reservation_method_id: + value['amount'] = 0.0 + value['amount_converted'] = 0.0 + + else: + for element, value in dict(res["combine_receivables"]).items(): + if element == self.config_id.pay_on_reservation_method_id: + value['amount'] = 0.0 + value['amount_converted'] = 0.0 + return res \ No newline at end of file