|
| 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