Skip to content

Commit 9a912a5

Browse files
monen17Borruso
authored andcommitted
[REF] l10n_it_edi_extension: In tests, allow to reuse zip extraction
1 parent 92d481b commit 9a912a5

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

l10n_it_edi_extension/tests/common.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# Copyright 2025 Simone Rubino
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
44

5+
import base64
56

6-
from odoo.fields import Command
7+
from odoo import tools
8+
from odoo.fields import Command, Domain
79

810
from odoo.addons.l10n_it_edi.tests.common import TestItEdi
911

@@ -91,3 +93,23 @@ def setUpClass(cls):
9193
}
9294
)
9395
)
96+
97+
def _import_moves_from_zip(self, zip_name):
98+
path = f"{self.module}/tests/import_xmls/{zip_name}"
99+
with tools.file_open(path, mode="rb") as file:
100+
encoded_file = base64.encodebytes(file.read())
101+
102+
wizard_attachment_import = (
103+
self.env["l10n_it_edi.import_file_wizard"]
104+
.with_company(self.company)
105+
.create(
106+
{
107+
"l10n_it_edi_attachment_filename": zip_name,
108+
"l10n_it_edi_attachment": encoded_file,
109+
}
110+
)
111+
)
112+
action = wizard_attachment_import.action_import()
113+
114+
move_ids = action.get("domain", Domain).value
115+
return self.env["account.move"].browse(move_ids)

l10n_it_edi_extension/tests/test_import_edi_extension_xml.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from odoo import tools
1010
from odoo.exceptions import MissingError
11-
from odoo.fields import Domain
1211

1312
from .common import Common
1413

@@ -95,24 +94,9 @@ def test_04_xml_import(self):
9594
self.assertEqual(edi_attachment, orig_attachment_data)
9695

9796
def test_import_zip(self):
98-
path = "l10n_it_edi_extension/tests/import_xmls/xml_import.zip"
99-
import_file_model = self.env["l10n_it_edi.import_file_wizard"].with_company(
100-
self.company
101-
)
102-
103-
with tools.file_open(path, mode="rb") as file:
104-
encoded_file = base64.encodebytes(file.read())
105-
106-
wizard_attachment_import = import_file_model.create(
107-
{
108-
"l10n_it_edi_attachment_filename": "xml_import.zip",
109-
"l10n_it_edi_attachment": encoded_file,
110-
}
111-
)
112-
action = wizard_attachment_import.action_import()
97+
zip_name = "xml_import.zip"
98+
moves = self._import_moves_from_zip(zip_name)
11399

114-
move_ids = action.get("domain", Domain).value
115-
moves = self.env["account.move"].browse(move_ids)
116100
out_moves = moves.filtered(lambda m: m.is_sale_document())
117101
in_moves = moves.filtered(lambda m: m.is_purchase_document())
118102
self.assertEqual(len(out_moves), 6)

0 commit comments

Comments
 (0)