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 Jan 12, 2023
1 parent fe4a990 commit e11f429
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 25 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
34 changes: 15 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,17 @@ 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
3 changes: 1 addition & 2 deletions account_invoice_refund_link/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class AccountInvoiceLine(models.Model):
origin_line_id = fields.Many2one(
comodel_name="account.move.line",
string="Original invoice line",
help="Original invoice line to which this refund invoice line "
"is referred to",
help="Original invoice line to which this refund invoice line is referred to",
copy=False,
index=True,
)
Expand Down
4 changes: 4 additions & 0 deletions account_invoice_refund_link/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
* Luis M. Ontalba
* Ernesto Tejeda
* João Marques

* `Factor Libre <https://factorlibre.com>`_:

* Luis J. Salvatierra <[email protected]>
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
12 changes: 12 additions & 0 deletions account_invoice_refund_link/views/account_invoice_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
<field name="amount_total" string="Total" />
<field name="state" string="Status" />
</tree>
<form>
<group>
<field name="partner_id" />
<field name="move_type" invisible="1" />
<field name="invoice_date" />
<field name="name" />
<field name="invoice_origin" />
<field name="ref" />
<field name="amount_total" string="Total" />
<field name="state" string="Status" />
</group>
</form>
</field>
</page>
</notebook>
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 e11f429

Please sign in to comment.