<commit_before># Copyright 2004-2011 Pexego Sistemas Informáticos. (http://pexego.es)
# Copyright 2016 <NAME> <<EMAIL>>
# Copyright 2014-2018 <NAME> <<EMAIL>>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class AccountMove(models.Model):
    _inherit = "account.move"

    refund_invoice_ids = fields.One2many(
        "account.move", "reversed_entry_id", string="Refund Invoices", readonly=True
    )

    @api.model
    def _reverse_move_vals(self, default_values, cancel=True):
        move_vals = super()._reverse_move_vals(default_values, cancel)
        if self.env.context.get("link_origin_line", False) and move_vals[
            "move_type"
        ] in (
            "out_refund",
            "in_refund",
        ):
            refund_lines_vals = move_vals.get("line_ids", [])
            for i, line in enumerate(self.line_ids):
                if i + 1 > len(refund_lines_vals):  # pragma: no cover
                    # Avoid error if someone manipulate the original method
                    break
                if not line.exclude_from_invoice_tab:
                    refund_lines_vals[i][2]["origin_line_id"] = line.id
        return move_vals<commit_msg>[FIX] account_invoice_refund_link: Don't link incorrect lines<commit_after># Copyright 2004-2011 Pexego Sistemas Informáticos. (http://pexego.es)
# Copyright 2016 <NAME> <<EMAIL>>
# Copyright 2014-2022 <NAME> <<EMAIL>>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class AccountMove(models.Model):
    _inherit = "account.move"

    refund_invoice_ids = fields.One2many(
        "account.move", "reversed_entry_id", string="Refund Invoices", readonly=True
    )

    @api.model
    def _reverse_move_vals(self, default_values, cancel=True):
        move_vals = super()._reverse_move_vals(default_values, cancel)
        if self.env.context.get("link_origin_line", False) and move_vals[
            "move_type"
        ] in (
            "out_refund",
            "in_refund",
        ):
            refund_lines_vals = [
                x[2]
                for x in move_vals.get("line_ids", [])
                if not x[2].get("exclude_from_invoice_tab", True)
            ]
            for i, line in enumerate(self.invoice_line_ids):
                if i < len(refund_lines_vals):
                    refund_lines_vals[i]["origin_line_id"] = line.id
        return move_vals
{'fraction_non_alphanumeric': 0.11331444759206799, 'fraction_numerical': 0.020234722784297856, 'mean_word_length': 2.4915254237288136, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4036864', 'n_tokens_mistral': 832, 'n_tokens_neox': 772, 'n_words': 164}