-
-
Notifications
You must be signed in to change notification settings - Fork 699
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #367 from Tecnativa/11.0-account_invoice_refund_li…
…nk-no_conflict [FIX] account_invoice_refund_link: Don't choke with standard fields
- Loading branch information
Showing
9 changed files
with
79 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,19 +6,19 @@ | |
Link refund invoice with original | ||
================================= | ||
|
||
This module links customer and supplier refunds with the invoice that originate | ||
them (and invoice lines). | ||
This module shows the links between refunds and their original invoices in the | ||
invoice form and also keep track of refund lines and their original invoice | ||
lines. | ||
|
||
Usage | ||
===== | ||
|
||
This module creates in the invoice form a new 'Refund' page. | ||
This module creates in the invoice form a new 'Refunds' page when the invoice | ||
has some refunds. It shows a line for each refund invoice with main | ||
information. | ||
|
||
In case of refund invoices this new page shows refund reason and original | ||
invoice information. | ||
|
||
In case of original invoices this new page shows a line for each refund | ||
invoice with main information. | ||
For refunds, it shows in "Other information" page the refund reason and | ||
original invoice link. | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
|
@@ -44,7 +44,7 @@ Contributors | |
------------ | ||
|
||
* Pexego Sistemas Informáticos. (http://pexego.es) | ||
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> | ||
* Pedro M. Baeza <pedro.baeza@tecnativa.com> | ||
* Antonio Espinosa <[email protected]> | ||
* Luis M. Ontalba <[email protected]> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import models | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2004-2011 Pexego Sistemas Informáticos. (http://pexego.es) | ||
# Copyright 2016 Antonio Espinosa <[email protected]> | ||
# Copyright 2014-2017 Pedro M. Baeza <[email protected]> | ||
|
@@ -7,7 +6,7 @@ | |
{ | ||
"name": "Link refund invoice with original", | ||
"summary": "Link refund invoice with its original invoice", | ||
"version": "11.0.1.0.0", | ||
"version": "11.0.2.0.0", | ||
"category": "Accounting & Finance", | ||
"website": "https://odoo-community.org/", | ||
"author": "Pexego, " | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 Antonio Espinosa <[email protected]> | ||
# Copyright 2017 Pedro M. Baeza <[email protected]> | ||
# Copyright 2017-2018 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
from openerp import _, api, SUPERUSER_ID | ||
from odoo import api, SUPERUSER_ID | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def _invoice_match(env, invoice): | ||
inv_type = 'out_invoice' if invoice.type == 'out_refund' else 'in_invoice' | ||
return env['account.invoice'].search([ | ||
('type', '=', inv_type), | ||
('number', '=ilike', invoice.origin), | ||
('company_id', '=', invoice.company_id.id), | ||
]) | ||
|
||
|
||
def match_origin_lines(refund, invoice): | ||
def match_origin_lines(refund): | ||
"""Try to match lines by product or by description.""" | ||
invoice = refund.refund_invoice_id | ||
invoice_lines = invoice.invoice_line_ids | ||
for refund_line in refund.invoice_line_ids: | ||
for invoice_line in invoice_lines: | ||
|
@@ -30,7 +21,7 @@ def match_origin_lines(refund, invoice): | |
) | ||
if match: | ||
invoice_lines -= invoice_line | ||
invoice_line.origin_line_ids = [(6, 0, refund_line.ids)] | ||
refund_line.origin_line_ids = [(6, 0, invoice_line.ids)] | ||
break | ||
if not invoice_lines: | ||
break | ||
|
@@ -42,15 +33,7 @@ def post_init_hook(cr, registry): | |
# Linking all refund invoices to its original invoices | ||
refunds = env['account.invoice'].search([ | ||
('type', 'in', ('out_refund', 'in_refund')), | ||
('origin_invoice_ids', '=', False), | ||
('refund_invoice_id', '!=', False), | ||
]) | ||
_logger.info("Linking %d refund invoices", len(refunds)) | ||
for refund in refunds: | ||
original = _invoice_match(env, refund) | ||
if not original: # pragma: no cover | ||
continue | ||
refund.write({ | ||
'origin_invoice_ids': [(6, 0, original.ids)], | ||
'refund_reason': _('Auto'), | ||
}) | ||
match_origin_lines(refund, original) | ||
match_origin_lines(refund) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import account_invoice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2004-2011 Pexego Sistemas Informáticos. (http://pexego.es) | ||
# Copyright 2016 Antonio Espinosa <[email protected]> | ||
# Copyright 2014-2017 Pedro M. Baeza <[email protected]> | ||
# Copyright 2014-2018 Pedro M. Baeza <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, models, fields | ||
|
@@ -11,30 +10,15 @@ class AccountInvoice(models.Model): | |
_inherit = 'account.invoice' | ||
|
||
refund_reason = fields.Text(string="Refund reason") | ||
origin_invoice_ids = fields.Many2many( | ||
comodel_name='account.invoice', column1='refund_invoice_id', | ||
column2='original_invoice_id', relation='account_invoice_refunds_rel', | ||
string="Original invoice", readonly=True, | ||
help="Original invoice to which this refund invoice is referred to", | ||
copy=False, | ||
) | ||
refund_invoice_ids = fields.Many2many( | ||
comodel_name='account.invoice', column1='original_invoice_id', | ||
column2='refund_invoice_id', relation='account_invoice_refunds_rel', | ||
string="Refund invoices", readonly=True, | ||
help="Refund invoices created from this invoice", | ||
copy=False, | ||
) | ||
|
||
@api.model | ||
def _prepare_refund(self, invoice, date_invoice=None, date=None, | ||
description=None, journal_id=None): | ||
"""Add link in the refund to the origin invoice and origin lines.""" | ||
"""Add link in the refund to the origin invoice lines.""" | ||
res = super(AccountInvoice, self)._prepare_refund( | ||
invoice, date_invoice=date_invoice, date=date, | ||
description=description, journal_id=journal_id, | ||
) | ||
res['origin_invoice_ids'] = [(6, 0, invoice.ids)] | ||
res['refund_reason'] = description | ||
refund_lines_vals = res['invoice_line_ids'] | ||
for i, line in enumerate(invoice.invoice_line_ids): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 Antonio Espinosa <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 Antonio Espinosa <[email protected]> | ||
# Copyright 2014-2017 Pedro M. Baeza <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
@@ -49,7 +48,6 @@ def _test_refund_link(self): | |
self.assertTrue(self.invoice.refund_invoice_ids) | ||
refund = self.invoice.refund_invoice_ids[0] | ||
self.assertEqual(refund.refund_reason, self.refund_reason) | ||
self.assertEqual(refund.origin_invoice_ids[0], self.invoice) | ||
self.assertEqual(len(self.invoice.invoice_line_ids), | ||
len(self.invoice_lines)) | ||
self.assertEqual(len(refund.invoice_line_ids), | ||
|
@@ -66,12 +64,12 @@ class TestInvoiceRefundLink(TestInvoiceRefundLinkBase): | |
def test_post_init_hook(self): | ||
self.assertTrue(self.invoice.refund_invoice_ids) | ||
refund = self.invoice.refund_invoice_ids[0] | ||
refund.write({ | ||
'origin_invoice_ids': [(5, False, False)], | ||
refund.invoice_line_ids.write({ | ||
'origin_line_ids': [(5, False, False)], | ||
}) | ||
self.assertFalse(refund.origin_invoice_ids) | ||
self.assertFalse(refund.mapped('invoice_line_ids.origin_line_ids')) | ||
post_init_hook(self.env.cr, None) | ||
self.refund_reason = 'Auto' | ||
self.refund_reason = 'The refund reason' | ||
self._test_refund_link() | ||
|
||
def test_refund_link(self): | ||
|
@@ -80,7 +78,6 @@ def test_refund_link(self): | |
def test_invoice_copy(self): | ||
refund = self.invoice.refund_invoice_ids[0] | ||
self.invoice.copy() | ||
self.assertEqual(refund.origin_invoice_ids, self.invoice) | ||
self.assertEqual( | ||
refund.mapped('invoice_line_ids.origin_line_ids'), | ||
self.invoice.mapped('invoice_line_ids'), | ||
|
@@ -89,7 +86,6 @@ def test_invoice_copy(self): | |
def test_refund_copy(self): | ||
refund = self.invoice.refund_invoice_ids[0] | ||
refund.copy() | ||
self.assertEqual(self.invoice.refund_invoice_ids, refund) | ||
self.assertEqual( | ||
self.invoice.mapped('invoice_line_ids.refund_line_ids'), | ||
refund.mapped('invoice_line_ids'), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters