diff --git a/l10n_de_dtvf/__manifest__.py b/l10n_de_dtvf/__manifest__.py index bc618781..e323d0be 100644 --- a/l10n_de_dtvf/__manifest__.py +++ b/l10n_de_dtvf/__manifest__.py @@ -15,6 +15,7 @@ ], "data": [ "security/ir.model.access.csv", + "views/account_account.xml", "views/l10n_de_dtvf_export.xml", "views/res_company.xml", ], diff --git a/l10n_de_dtvf/models/__init__.py b/l10n_de_dtvf/models/__init__.py index 69d9ad85..4eeb5c2c 100644 --- a/l10n_de_dtvf/models/__init__.py +++ b/l10n_de_dtvf/models/__init__.py @@ -1,4 +1,5 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import account_account from . import l10n_de_dtvf_export from . import res_company diff --git a/l10n_de_dtvf/models/l10n_de_dtvf_export.py b/l10n_de_dtvf/models/l10n_de_dtvf_export.py index 05399968..28ac2564 100644 --- a/l10n_de_dtvf/models/l10n_de_dtvf_export.py +++ b/l10n_de_dtvf/models/l10n_de_dtvf_export.py @@ -184,6 +184,8 @@ def _get_data_transaction(self, move): "payable", ) and move_line2.account_id.internal_type in ("receivable", "payable"): move_line, move_line2 = move_line2, move_line + if move_line.account_id.datev_export_nonautomatic: + move_line, move_line2 = move_line2, move_line data = { "Umsatz (ohne Soll/Haben-Kz)": ("%.2f" % abs(amount)).replace(".", ","), "Soll/Haben-Kennzeichen": move_line.debit and "S" or "H", @@ -191,6 +193,10 @@ def _get_data_transaction(self, move): "Gegenkonto (ohne BU-Schlüssel)": move_line2.account_id.code[ -code_length: ], + "BU-Schlüssel": "40" + if move_line.account_id.datev_export_nonautomatic + or move_line2.account_id.datev_export_nonautomatic + else "", "Buchungstext": move_line.name, "Belegdatum": move.date.strftime("%d%m"), "Belegfeld 1": move.name, diff --git a/l10n_de_dtvf/tests/test_l10n_de_dtvf.py b/l10n_de_dtvf/tests/test_l10n_de_dtvf.py index 31678b40..9a9b28d1 100644 --- a/l10n_de_dtvf/tests/test_l10n_de_dtvf.py +++ b/l10n_de_dtvf/tests/test_l10n_de_dtvf.py @@ -69,3 +69,63 @@ def test_happy_flow(self): ) self.wizard.action_draft() self.assertEqual(self.wizard.state, "draft") + + def test_nonautomatic_flag(self): + """Test setting BU-Schlussel 40 works as it should""" + journal = self.env["account.journal"].create( + { + "name": "Testjournal", + "type": "sale", + "code": "DTV", + } + ) + account1 = self.env["account.account"].create( + { + "name": "Nonautomatic export", + "code": "424242", + "user_type_id": self.env.ref("account.data_account_type_revenue").id, + } + ) + account2 = self.env["account.account"].create( + { + "name": "Receivable", + "code": "424243", + "datev_export_nonautomatic": True, + "user_type_id": self.env.ref("account.data_account_type_receivable").id, + "reconcile": True, + } + ) + move = self.env["account.move"].create( + { + "journal_id": journal.id, + "line_ids": [ + ( + 0, + 0, + { + "account_id": account1.id, + "credit": 42, + }, + ), + ( + 0, + 0, + { + "account_id": account2.id, + "debit": 42, + }, + ), + ], + } + ) + move.action_post() + self.wizard.journal_ids = journal + self.wizard.action_generate() + zip_buffer = io.BytesIO(base64.b64decode(self.wizard.file_data)) + with zipfile.ZipFile(zip_buffer) as zip_file: + move_line_file_name = [ + f for f in zip_file.namelist() if f.startswith("EXTF_Buchungsstapel") + ][0] + with zip_file.open(move_line_file_name) as move_line_file: + move_line = move_line_file.readlines()[2].decode("utf8") + self.assertIn('"40"', move_line) diff --git a/l10n_de_dtvf/views/l10n_de_dtvf_export.xml b/l10n_de_dtvf/views/l10n_de_dtvf_export.xml index 07a83ddb..70162bf0 100644 --- a/l10n_de_dtvf/views/l10n_de_dtvf_export.xml +++ b/l10n_de_dtvf/views/l10n_de_dtvf_export.xml @@ -34,6 +34,7 @@ domain="[('date_start', '>=', fiscalyear_start), ('date_end', '<=', fiscalyear_end)]" attrs="{'readonly': [('fiscalyear_id', '=', False)]}" /> +