diff --git a/account_payment_return/models/account_move.py b/account_payment_return/models/account_move.py index 3688ad7179f7..455e9965629e 100644 --- a/account_payment_return/models/account_move.py +++ b/account_payment_return/models/account_move.py @@ -1,9 +1,8 @@ -# Copyright 2016 Tecnativa Carlos Dauden +# Copyright 2016-2024 Tecnativa - Carlos Dauden # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import _, fields, models -from odoo.tools import formatLang +from odoo import fields, models class AccountMove(models.Model): @@ -28,72 +27,32 @@ def check_payment_return(self): {"returned_payment": False} ) - def prepare_values_returned_widget(self, line_id, amount, is_return=False): - try: - payment_method_name = line_id.payment_method_line_id.name - except AttributeError: - payment_method_name = False - return { - "name": line_id.name, - "journal_name": line_id.journal_id.name, - "amount": amount, - "date": line_id.date, - "partial_id": line_id.id, - "currency_id": line_id.currency_id, - "currency": line_id.currency_id.symbol, - "position": line_id.currency_id.position, - "move_id": line_id.move_id.id, - "amount_company_currency": formatLang( - self.env, - abs(amount), - currency_obj=line_id.currency_id, - ), - "payment_method_name": payment_method_name, - "ref": "{} ({})".format(line_id.move_id.name, line_id.ref), - "returned": is_return, - } - - def _compute_payments_widget_reconciled_info(self): - moves_to_compute = self.env["account.move"] - for move in self: - if not move.returned_payment: - moves_to_compute |= move - else: - values_returned = [] - payments_widget_vals = { - "outstanding": False, - "content": values_returned, - "move_id": move.id, - "title": _("Returned on"), + def _get_all_reconciled_invoice_partials(self): + res = super()._get_all_reconciled_invoice_partials() + domain = [("origin_returned_move_ids.move_id", "=", self.id)] + move_reconciles = self.env["account.partial.reconcile"].search(domain) + for move_reconcile in move_reconciles: + res.append( + { + "aml_id": move_reconcile.credit_move_id.id, + "partial_id": move_reconcile.id, + "amount": move_reconcile.amount, + "currency": move_reconcile.credit_move_id.currency_id, + "aml": move_reconcile.credit_move_id, + "is_exchange": False, + } + ) + res.append( + { + "aml_id": move_reconcile.debit_move_id.id, + "partial_id": move_reconcile.id, + "amount": -move_reconcile.amount, + "currency": move_reconcile.debit_move_id.currency_id, + "aml": move_reconcile.debit_move_id, + "is_exchange": False, } - reconciled_payments = move._get_reconciled_payments() - domain = [("origin_returned_move_ids.move_id", "=", move.id)] - if len(reconciled_payments) > 0: - for rec_payment in reconciled_payments: - vals_rec_payment = self.prepare_values_returned_widget( - rec_payment, rec_payment.amount - ) - values_returned.append(vals_rec_payment) - move_reconciles = self.env["account.partial.reconcile"].search(domain) - for move_reconcile in move_reconciles: - payment_ret = move_reconcile.debit_move_id - payment = move_reconcile.credit_move_id - vals_payment = self.prepare_values_returned_widget( - payment, move_reconcile.amount - ) - values_returned.append(vals_payment) - vals_reconcile = self.prepare_values_returned_widget( - payment_ret, -move_reconcile.amount, True - ) - values_returned.append(vals_reconcile) - if payments_widget_vals["content"]: - move.invoice_payments_widget = payments_widget_vals - else: - move.invoice_payments_widget = False - if moves_to_compute: - return super( - AccountMove, moves_to_compute - )._compute_payments_widget_reconciled_info() + ) + return sorted(res, key=lambda ln: (ln["aml"].date, ln["aml_id"])) class AccountMoveLine(models.Model): diff --git a/account_payment_return/models/payment_return.py b/account_payment_return/models/payment_return.py index 2c7b56d4de81..1dbc4feb29d5 100644 --- a/account_payment_return/models/payment_return.py +++ b/account_payment_return/models/payment_return.py @@ -2,7 +2,7 @@ # Copyright 2011-2012 Avanzosc # Copyright 2013 Tecnativa - Pedro M. Baeza # Copyright 2014 Markus Schneider -# Copyright 2016-2023 Tecnativa - Carlos Dauden +# Copyright 2016-2024 Tecnativa - Carlos Dauden # Copyright 2017 Tecnativa - Luis M. Ontalba # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -211,7 +211,7 @@ def action_confirm(self): move_line_vals = self._prepare_move_line(move, total_amount) # credit_move_line: credit on transfer or bank account AccountMoveLine.create(move_line_vals) - move._post() + move._post(soft=False) for to_reconcile_aml_dic in to_reconcile_aml_list: ( to_reconcile_aml_dic["payment_aml"] + to_reconcile_aml_dic["return_aml"] diff --git a/account_payment_return/static/src/xml/account_payment_return.xml b/account_payment_return/static/src/xml/account_payment_return.xml index 96c716105494..c0b0f514347b 100644 --- a/account_payment_return/static/src/xml/account_payment_return.xml +++ b/account_payment_return/static/src/xml/account_payment_return.xml @@ -1,5 +1,5 @@ - @@ -11,7 +11,7 @@ > js_payment_info fa fa-#{line.returned and 'warning' or 'info-circle'} + >js_payment_info fa fa-#{line.amount < 0.0 and 'warning' or 'info-circle'} Payment Info @@ -20,7 +20,8 @@ position="replace" > - + Returned on + Paid on