Skip to content

Commit

Permalink
[MIG] account_invoice_refund_link: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ljsalvatierra-factorlibre committed Oct 14, 2022
1 parent 94ef566 commit ed2f77d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion account_invoice_refund_link/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{
"name": "Show links between refunds and their originator invoices.",
"version": "15.0.1.0.1",
"version": "16.0.1.0.0",
"development_status": "Mature",
"category": "Accounting & Finance",
"website": "https://github.com/OCA/account-invoicing",
Expand Down
37 changes: 18 additions & 19 deletions account_invoice_refund_link/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2014-2022 Pedro M. Baeza <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import fields, models


class AccountMove(models.Model):
Expand All @@ -13,21 +13,20 @@ class AccountMove(models.Model):
"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
def _reverse_moves(self, default_values_list=None, cancel=False):
reverse_moves = super()._reverse_moves(
default_values_list=default_values_list, cancel=cancel
)
if self.env.context.get("link_origin_line", False):
for move in reverse_moves:
if move.move_type in (
"out_refund",
"in_refund",
):
refund_lines = move.line_ids.filtered(
lambda x: x.display_type == "product"
)
for i, line in enumerate(self.invoice_line_ids):
if i < len(refund_lines):
refund_lines[i].origin_line_id = line.id
return reverse_moves
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def setUpClass(cls):
{
"name": "TESTACC",
"code": "TESTACC",
"user_type_id": cls.env.ref(
"account.data_account_type_other_income"
).id,
"account_type": "income",
"deprecated": False,
"company_id": cls.env.user.company_id.id,
}
Expand Down
6 changes: 6 additions & 0 deletions setup/account_invoice_refund_link/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit ed2f77d

Please sign in to comment.