|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# © 2017 FactorLibre - Hugo Santos <hugo.santos@factorlibre.com> |
| 3 | +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0 |
| 4 | +from odoo.tests import common |
| 5 | + |
| 6 | + |
| 7 | +class TestL10nEsAeatExportConfig(common.TransactionCase): |
| 8 | + |
| 9 | + def setUp(self): |
| 10 | + super(TestL10nEsAeatExportConfig, self).setUp() |
| 11 | + |
| 12 | + def test_onchange_export_config_line(self): |
| 13 | + export_config_line_env = self.env['aeat.model.export.config.line'] |
| 14 | + with self.env.do_in_onchange(): |
| 15 | + export_line_float = export_config_line_env.new() |
| 16 | + export_line_float.export_type = 'float' |
| 17 | + export_line_float.onchange_type() |
| 18 | + self.assertEqual(export_line_float.alignment, 'right', |
| 19 | + 'Export type float must be aligned to the right') |
| 20 | + export_line_str = export_config_line_env.new() |
| 21 | + export_line_str.export_type = 'string' |
| 22 | + export_line_str.onchange_type() |
| 23 | + self.assertEqual(export_line_str.alignment, 'left', |
| 24 | + 'Export type string must be aligned to the left') |
| 25 | + export_line_subtype = export_config_line_env.new() |
| 26 | + export_line_subtype.alignment = 'left' |
| 27 | + export_line_subtype.decimal_size = 10 |
| 28 | + export_line_subtype.apply_sign = True |
| 29 | + export_line_subtype.subconfig_id = export_line_str.id |
| 30 | + export_line_subtype.onchange_subconfig() |
| 31 | + self.assertFalse(export_line_subtype.alignment, |
| 32 | + 'Alignment must be False for a subtype line') |
| 33 | + self.assertEqual(export_line_subtype.decimal_size, 0) |
| 34 | + self.assertFalse(export_line_subtype.apply_sign, |
| 35 | + 'Apply sign must be False for a subtype line') |
| 36 | + |
| 37 | + def test_export_config_file(self): |
| 38 | + export_config = self.env['aeat.model.export.config'].create({ |
| 39 | + 'name': 'Test Export Config', |
| 40 | + 'model_number': '000', |
| 41 | + 'config_line_ids': [ |
| 42 | + (0, 0, { |
| 43 | + 'sequence': 1, |
| 44 | + 'name': '<T', |
| 45 | + 'fixed_value': '<T', |
| 46 | + 'export_type': 'string', |
| 47 | + 'size': 3, |
| 48 | + 'alignment': 'left' |
| 49 | + }), |
| 50 | + (0, 0, { |
| 51 | + 'sequence': 2, |
| 52 | + 'name': 'Empty spaces', |
| 53 | + 'fixed_value': '', |
| 54 | + 'export_type': 'string', |
| 55 | + 'size': 10, |
| 56 | + 'alignment': 'left' |
| 57 | + }), |
| 58 | + (0, 0, { |
| 59 | + 'sequence': 3, |
| 60 | + 'name': 'Integer Value', |
| 61 | + 'fixed_value': 1, |
| 62 | + 'export_type': 'integer', |
| 63 | + 'size': 3, |
| 64 | + 'alignment': 'right' |
| 65 | + }), |
| 66 | + (0, 0, { |
| 67 | + 'sequence': 4, |
| 68 | + 'name': 'Float Value', |
| 69 | + 'fixed_value': 15.0, |
| 70 | + 'export_type': 'float', |
| 71 | + 'size': 6, |
| 72 | + 'decimal_size': 2, |
| 73 | + 'alignment': 'right' |
| 74 | + }), |
| 75 | + (0, 0, { |
| 76 | + 'sequence': 5, |
| 77 | + 'name': 'Boolean True Value', |
| 78 | + 'expression': True, |
| 79 | + 'export_type': 'boolean', |
| 80 | + 'size': 2, |
| 81 | + 'alignment': 'left' |
| 82 | + }), |
| 83 | + (0, 0, { |
| 84 | + 'sequence': 6, |
| 85 | + 'name': 'Boolean False Value', |
| 86 | + 'expression': False, |
| 87 | + 'export_type': 'boolean', |
| 88 | + 'size': 2, |
| 89 | + 'alignment': 'left' |
| 90 | + }), |
| 91 | + (0, 0, { |
| 92 | + 'sequence': 7, |
| 93 | + 'name': '>', |
| 94 | + 'fixed_value': '>', |
| 95 | + 'size': 1, |
| 96 | + 'alignment': 'left' |
| 97 | + }) |
| 98 | + ] |
| 99 | + }) |
| 100 | + new_report = self.env['l10n.es.aeat.report'].new({ |
| 101 | + 'name': 'Test Report' |
| 102 | + }) |
| 103 | + export_to_boe = self.env['l10n.es.aeat.report.export_to_boe'].create({ |
| 104 | + 'name': 'test_export_to_boe.txt' |
| 105 | + }) |
| 106 | + export_file = export_to_boe._export_config( |
| 107 | + new_report, export_config) |
| 108 | + self.assertEqual(b'<T 001001500X >', export_file) |
0 commit comments