8000 [FW][FIX] l10n_it_edi_ndd: recompute l10n_it_document_type for credit note by fw-bot · Pull Request #210642 · odoo/odoo · GitHub
[go: up one dir, main page]

Skip to content

[FW][FIX] l10n_it_edi_ndd: recompute l10n_it_document_type for credit note #210642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions addons/l10n_it_edi/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,10 @@ def _reverse_moves(self, default_values_list=None, cancel=False):
But when reversing the move, the document type of the original move is copied and so it isn't recomputed.
"""
# EXTENDS account
default_values_list = default_values_list or [{}] * len(self)
for default_values in default_values_list:
default_values.update({'l10n_it_document_type': False})
reverse_moves = super()._reverse_moves(default_values_list, cancel)
for move in reverse_moves:
move.l10n_it_document_type = False
return reverse_moves

@api.depends('l10n_it_edi_transaction')
Expand Down
1 change: 1 addition & 0 deletions addons/l10n_it_edi/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import common
from . import test_account_move_document_type
from . import test_account_move_payment_method
from . import test_edi_address
from . import test_edi_export
Expand Down
41 changes: 41 additions & 0 deletions addons/l10n_it_edi/tests/test_account_move_document_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from odoo.tests import tagged
from odoo.addons.l10n_it_edi.tests.common import TestItEdi


@tagged('post_install_l10n', 'post_install', '-at_install')
class TestItAccountMoveDocumentType(TestItEdi):

def test_account_move_document_type(self):
# l10n_it_document_type_01: "TD01 - Invoice (Immediate or Accompanying if <DatiTrasporto> or <DatiDDT> are completed)"
# l10n_it_document_type_04: "TD04 - Credit note"
dt_invoice = self.env.ref('l10n_it_edi.l10n_it_document_type_01')
dt_credit_note = self.env.ref('l10n_it_edi.l10n_it_document_type_04')

invoice_x = self.init_invoice("out_invoice", amounts=[1000])
# the compute method does nothing for moves that are not posted
self.assertFalse(invoice_x.l10n_it_document_type)

invoice_x.action_post()
self.assertEqual(invoice_x.l10n_it_document_type, dt_invoice)
# create a draft credit note
reversal_wizard = self.env['account.move.reversal'].with_context(active_model='account.move', active_ids=invoice_x.ids).create({
'reason': 'XXX',
'journal_id': invoice_x.journal_id.id,
})
reversal = reversal_wizard.refund_moves()
credit_note_x = self.env['account.move'].browse(reversal['res_id'])
self.assertFalse(credit_note_x.l10n_it_document_type)
# post the credit note
credit_note_x.action_post()
self.assertEqual(credit_note_x.l10n_it_document_type, dt_credit_note)

invoice_y = self.init_invoice("out_invoice", amounts=[2000], post=True)
self.assertEqual(invoice_y.l10n_it_document_type, dt_invoice)
# create a credit note that is posted directly
reversal_wizard = self.env['account.move.reversal'].with_context(active_model='account.move', active_ids=invoice_y.ids).create({
'reason': 'YYY',
'journal_id': invoice_y.journal_id.id,
})
reversal_wizard.modify_moves()
credit_note_y = invoice_y.reversal_move_ids[0]
self.assertEqual(credit_note_y.l10n_it_document_type, dt_credit_note)
0