Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] account_payment_return: Use _get_all_reconciled_invoice_partials method to simplify #778

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 27 additions & 69 deletions account_payment_return/models/account_move.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -28,73 +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,
"is_exchange": False,
}

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": bool(move_reconcile.exchange_move_id),
}
)
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": bool(move_reconcile.exchange_move_id),
}
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):
Expand Down
4 changes: 2 additions & 2 deletions account_payment_return/models/payment_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2011-2012 Avanzosc <http://www.avanzosc.com>
# Copyright 2013 Tecnativa - Pedro M. Baeza
# Copyright 2014 Markus Schneider <[email protected]>
# 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).

Expand Down Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2016 Tecnativa - Carlos Dauden
<!-- Copyright 2016-2024 Tecnativa - Carlos Dauden
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3). -->
<templates xml:space="preserve">

Expand All @@ -11,7 +11,7 @@
>
<attribute
name="t-attf-class"
>js_payment_info fa fa-#{line.returned and 'warning' or 'info-circle'}</attribute>
>js_payment_info fa fa-#{line.amount &lt; 0.0 and 'warning' or 'info-circle'}</attribute>
<attribute name="title">Payment Info</attribute>
</xpath>

Expand All @@ -20,7 +20,8 @@
position="replace"
>
<i class="o_field_widget text-start o_payment_label">
<t t-esc="line.returned and 'Returned on ' or 'Paid on '" />
<span t-if="line.amount &lt; 0.0">Returned on </span>
<span t-else="">Paid on </span>
<t t-esc="line.date" />
</i>
</xpath>
Expand Down
Loading