Skip to content
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

[15.0][IMP] datev_export_xml: Improve handling and download of bigger files #160

Closed
wants to merge 8 commits into from
2 changes: 1 addition & 1 deletion datev_export_xml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
# @author Grzegorz Grzelak
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
from . import controllers, models
2 changes: 1 addition & 1 deletion datev_export_xml/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

{
"name": "Datev Export XML",
"version": "15.0.1.0.1",
"version": "15.0.1.1.1",
"category": "Accounting",
"license": "AGPL-3",
"author": "Guenter Selbert, Thorsten Vocks, Maciej Wichowski, Daniela Scarpa, "
Expand Down
4 changes: 4 additions & 0 deletions datev_export_xml/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2022-2024 initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import main
40 changes: 40 additions & 0 deletions datev_export_xml/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (C) 2022-2024 initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import base64
import logging

from odoo import http
from odoo.http import request, send_file

from odoo.addons.web.controllers.main import Home

_logger = logging.getLogger(__name__)


class DatevHome(Home):
@http.route("/datev/xml/download/<int:line_id>", type="http", auth="user")
def datev_xml_download_attachment(self, line_id):
export = request.env["datev.export.xml.line"].search([("id", "=", line_id)])

Check warning on line 18 in datev_export_xml/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

datev_export_xml/controllers/main.py#L18

Added line #L18 was not covered by tests

if not export.attachment_id:
return request.not_found()

Check warning on line 21 in datev_export_xml/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

datev_export_xml/controllers/main.py#L21

Added line #L21 was not covered by tests

att = export.attachment_id

Check warning on line 23 in datev_export_xml/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

datev_export_xml/controllers/main.py#L23

Added line #L23 was not covered by tests

if att.store_fname:
full_path = att._full_path(att.store_fname)
return send_file(

Check warning on line 27 in datev_export_xml/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

datev_export_xml/controllers/main.py#L26-L27

Added lines #L26 - L27 were not covered by tests
full_path,
filename=att.name,
mimetype=att.mimetype,
as_attachment=True,
)

return request.make_response(

Check warning on line 34 in datev_export_xml/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

datev_export_xml/controllers/main.py#L34

Added line #L34 was not covered by tests
base64.b64decode(att.datas),
[
("Content-Type", att.mimetype),
("Content-Disposition", f'attachment; filename="{att.name}"'),
],
)
9 changes: 7 additions & 2 deletions datev_export_xml/i18n/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,12 @@ msgstr "Dateigröße"
#, python-format
msgid ""
"Filtered Export of %(count)s Documents\n"
" Date Range: %(start)s-%(end)s\n"
"Date Range: %(start)s-%(stop)s\n"
"Types: %(types)s"
msgstr ""
"Gefilterter Export von %(count)s Dokumente\n"
"Datumsbereich: %(start)s-%(stop)s\n"
"Typen: %(types)s"

#. module: datev_export_xml
#: model:ir.model.fields,field_description:datev_export_xml.field_datev_export_xml__message_follower_ids
Expand Down Expand Up @@ -553,9 +556,11 @@ msgstr ""
#: code:addons/datev_export_xml/models/datev_export.py:0
#, python-format
msgid ""
"Manually Doc Export of %(count)s Documents \n"
"Manual Export of %(count)s Documents\n"
"Numbers: %(names)s"
msgstr ""
"Manueller Export von %(count)s Documenten \n"
"Nummern: %(names)s"

#. module: datev_export_xml
#: model:ir.model.fields,field_description:datev_export_xml.field_datev_export_xml__manually_document_selection
Expand Down
34 changes: 34 additions & 0 deletions datev_export_xml/migrations/15.0.1.1.1/post-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# © 2023 initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging

from odoo import SUPERUSER_ID, api

_logger = logging.getLogger(__name__)


def migrate(cr, version):
env = api.Environment(cr, SUPERUSER_ID, {})

query = """
SELECT id, attachment_id FROM datev_export_xml
WHERE attachment_id IS NOT NULL
"""
env.cr.execute(query)

for export_id, attachment_id in env.cr.fetchall():
export = env["datev.export.xml"].browse(export_id)
attachment = env["ir.attachment"].browse(attachment_id)

_logger.info(f"Migrating attachment of {export}")

line = export.line_ids.create(
{
"attachment_id": attachment_id,
"export_id": export_id,
"invoice_ids": [(6, 0, export.invoice_ids.ids)],
}
)

attachment.write({"res_model": line._name, "res_id": line.id})
2 changes: 1 addition & 1 deletion datev_export_xml/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
res_config_settings,
)

from . import datev_export # isort:skip
from . import datev_export, datev_export_line # isort:skip
6 changes: 6 additions & 0 deletions datev_export_xml/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
return "Rechnung"
return "Gutschrift/Rechnungskorrektur"

def datev_party_attributes(self, partner):
result = {}
if partner.vat:
result["vat_id"] = partner.vat

Check warning on line 85 in datev_export_xml/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

datev_export_xml/models/account_move.py#L85

Added line #L85 was not covered by tests
return result

def datev_invoice_id(self):
self.ensure_one()
return self.datev_sanitize(self.name or "")
Expand Down
Loading
Loading