8000 [FIX] l10n_it_edi: recompute l10n_it_document_type for credit note · odoo-dev/odoo@4791dbf · GitHub
[go: up one dir, main page]

Skip to content

Commit 4791dbf

Browse files
kitan191fdardenne
authored andcommitted
[FIX] l10n_it_edi: recompute l10n_it_document_type for credit note
Steps to reproduce: - Install l10n_it_edi - Switch to an Italian company (e.g. IT Company) - Create an invoice - Confirm the invoice => Document Type (in "Electronic Invoicing" tab) is computed - Create a credit note from the invoice - On credit note wizard, click on "Reverse and Create Invoice" - Check the created credit note Issue: The credit note is posted but its Document Type field (l10n_it_document_type) is empty. l10n_it_document_type should be computed when it doesn't have a value already and the state of the move is "posted". The credit note will be rejected when sent to SDI because this field is empty. Cause: In the reverse method, the field is set to False in order to be recomputed. However, the compute method is triggered when the state changes, but the credit note is already posted. Therefore the field will not be recomputed. Solution: Set the value to False before the creation of the credit note. So that, the field will be recomputed when posting the credit note. opw-4689755 closes odoo#210642 X-original-commit: 6c49d48 Signed-off-by: Thomas Becquevort (thbe) <thbe@odoo.com> Signed-off-by: Anh Thao Pham (pta) <pta@odoo.com>
1 parent 44b9bf9 commit 4791dbf

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

addons/l10n_it_edi/models/account_move.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,10 @@ def _reverse_moves(self, default_values_list=None, cancel=False):
238238
But when reversing the move, the document type of the original move is copied and so it isn't recomputed.
239239
"""
240240
# EXTENDS account
241+
default_values_list = default_values_list or [{}] * len(self)
242+
for default_values in default_values_list:
243+
default_values.update({'l10n_it_document_type': False})
241244
reverse_moves = super()._reverse_moves(default_values_list, cancel)
242-
for move in reverse_moves:
243-
move.l10n_it_document_type = False
244245
return reverse_moves
245246

246247
@api.depends('l10n_it_edi_transaction')

addons/l10n_it_edi/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
# Part of Odoo. See LICENSE file for full copyright and licensing details.
33
from . import common
4+
from . import test_account_move_document_type
45
from . import test_account_move_payment_method
56
from . import test_edi_address
67
from . import test_edi_export
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from odoo.tests import tagged
2+
from odoo.addons.l10n_it_edi.tests.common import TestItEdi
3+
4+
5+
@tagged('post_install_l10n', 'post_install', '-at_install')
6+
class TestItAccountMoveDocumentType(TestItEdi):
7+
8+
def test_account_move_document_type(self):
9+
# l10n_it_document_type_01: "TD01 - Invoice (Immediate or Accompanying if <DatiTrasporto> or <DatiDDT> are completed)"
10+
# l10n_it_document_type_04: "TD04 - Credit note"
11+
dt_invoice = self.env.ref('l10n_it_edi.l10n_it_document_type_01')
12+
dt_credit_note = self.env.ref('l10n_it_edi.l10n_it_document_type_04')
13+
14+
invoice_x = self.init_invoice("out_invoice", amounts=[1000])
15+
# the compute method does nothing for moves that are not posted
16+
self.assertFalse(invoice_x.l10n_it_document_type)
17+
18+
invoice_x.action_post()
19+
self.assertEqual(invoice_x.l10n_it_document_type, dt_invoice)
20+
# create a draft credit note
21+
reversal_wizard = self.env['account.move.reversal'].with_context(active_model='account.move', active_ids=invoice_x.ids).create({
22+
'reason': 'XXX',
23+
'journal_id': invoice_x.journal_id.id,
24+
})
25+
reversal = reversal_wizard.refund_moves()
26+
credit_note_x = self.env['account.move'].browse(reversal['res_id'])
27+
self.assertFalse(credit_note_x.l10n_it_document_type)
28+
# post the credit note
29+
credit_note_x.action_post()
30+
self.assertEqual(credit_note_x.l10n_it_document_type, dt_credit_note)
31+
32+
invoice_y = self.init_invoice("out_invoice", amounts=[2000], post=True)
33+
self.assertEqual(invoice_y.l10n_it_document_type, dt_invoice)
34+
# create a credit note that is posted directly
35+
reversal_wizard = self.env['account.move.reversal'].with_context(active_model='account.move', active_ids=invoice_y.ids).create({
36+
'reason': 'YYY',
37+
'journal_id': invoice_y.journal_id.id,
38+
})
39+
reversal_wizard.modify_moves()
40+
credit_note_y = invoice_y.reversal_move_ids[0]
41+
self.assertEqual(credit_note_y.l10n_it_document_type, dt_credit_note)

0 commit comments

Comments
 (0)
0