Skip to content

Commit

Permalink
[REF] account_payment_return_import_iso20022: Adapt module to native …
Browse files Browse the repository at this point in the history
…payment refactoring

Following OCA/bank-payment#979
  • Loading branch information
pedrobaeza authored and “heliaktiv” committed Apr 17, 2023
1 parent f55db44 commit cd89ad9
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions account_payment_return_import_iso20022/models/payment_return.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2016 Tecnativa - Carlos Dauden
# Copyright 2020 Tecnativa - Víctor Martínez
# Copyright 2022 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models
Expand All @@ -9,10 +10,24 @@ class PaymentReturnLine(models.Model):
_inherit = "payment.return.line"

def _find_match(self):
AccountMoveLine = self.env["account.move.line"]
lines = self.filtered(lambda x: not x.move_line_ids and x.reference)
for line in lines:
line.move_line_ids = AccountMoveLine.search(
[("bank_payment_line_id.name", "=", line.reference)]
"""Include in the matches the lines coming from payment orders."""
matched = self.env["payment.return.line"]
for line in self.filtered(lambda x: not x.move_line_ids and x.reference):
move_id = int(line.reference) if line.reference.isdigit() else -1
payments = self.env["account.payment"].search(
[
"|",
# Compatibility with old approach - To be removed on v16
("old_bank_payment_line_name", "=", line.reference),
("move_id", "=", move_id),
("payment_order_id", "!=", False),
],
)
return super(PaymentReturnLine, lines)._find_match()
if payments:
matched += line
for payment in payments:
line.move_line_ids |= payment.move_id.line_ids.filtered(
lambda x: x.account_id != payment.destination_account_id
and x.partner_id == payment.partner_id
)
return super(PaymentReturnLine, self - matched)._find_match()

0 comments on commit cd89ad9

Please sign in to comment.