Skip to content

Commit

Permalink
[MIG] datev_export_xml: Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinafernandez-tecnativa committed May 13, 2024
1 parent 5d9702c commit 13f67b1
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 88 deletions.
7 changes: 4 additions & 3 deletions datev_export_xml/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
# @author Guenter Selbert <guenter.selbert@sewisoft.de>
# @author Thorsten Vocks <thorsten.vocks@openbig.org>
# @author Grzegorz Grzelak
# Copyright 2023 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Datev Export XML",
"version": "14.0.1.0.0",
"version": "13.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"author": "Guenter Selbert, Thorsten Vocks, Maciej Wichowski, Daniela Scarpa, "
"Maria Sparenberg, initOS GmbH, Odoo Community Association (OCA)",
"summary": "Export invoices and refunds as xml and pdf files zipped in DATEV format.",
"website": "https://github.com/OCA/l10n-germany",
"depends": ["datev_export",],
"depends": ["datev_export"],
"data": [
"data/ir_cron_data.xml",
"security/groups.xml",
Expand All @@ -27,6 +28,6 @@
"views/res_config_settings_views.xml",
"views/templates.xml",
],
"demo": ["demo/export_data.xml",],
"demo": ["demo/export_data.xml"],
"installable": True,
}
2 changes: 0 additions & 2 deletions datev_export_xml/demo/export_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<record id="base.main_company" model="res.company">
<field name="datev_client_number">1234</field>
<field name="datev_consultant_number">12345</field>
<!-- <field name="group_account_user" eval="True"/> -->
<!-- <field name="group_analytic_accounting" eval="True"/> -->
</record>

<!-- Company Datev Accounts -->
Expand Down
24 changes: 11 additions & 13 deletions datev_export_xml/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# @author Guenter Selbert <guenter.selbert@sewisoft.de>
# @author Thorsten Vocks
# @author Grzegorz Grzelak
# Copyright 2023 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging
Expand Down Expand Up @@ -41,7 +42,7 @@ class AccountMove(models.Model):

def datev_format_total(self, value):
self.ensure_one()
return f"-{value:.2f}" if self.move_type.endswith("_refund") else f"{value:.2f}"
return f"-{value:.2f}" if self.type.endswith("_refund") else f"{value:.2f}"

def datev_sanitize(self, value, length=36):
return re.sub(r"[^a-zA-Z0-9$%&\*\+\-/]", "-", value)[:length]
Expand All @@ -57,10 +58,12 @@ def datev_delivery_date(self):
return self.invoice_date

pickings = self.env["stock.move"]
if self.move_type == "out_invoice":
if self.type == "out_invoice":
pickings = self.mapped("invoice_line_ids.sale_line_ids.move_ids.picking_id")
elif self.move_type == "in_invoice":
pickings = self.mapped("invoice_line_ids.purchase_order_id.picking_ids")
elif self.type == "in_invoice":
pickings = self.mapped(
"invoice_line_ids.purchase_line_id.order_id.picking_ids"
)

if pickings:
return pickings.sorted("date DESC")[0].date.date()
Expand All @@ -70,7 +73,7 @@ def datev_delivery_date(self):

def datev_invoice_type(self):
self.ensure_one()
if self.move_type in ["out_invoice", "in_invoice"]:
if self.type in ["out_invoice", "in_invoice"]:
return "Rechnung"
return "Gutschrift/Rechnungskorrektur"

Expand All @@ -81,22 +84,17 @@ def datev_invoice_id(self):
def datev_order_id(self):
self.ensure_one()
origin = self.invoice_origin or ""
if self.move_type not in (
"in_invoice",
"in_refund",
"out_invoice",
"out_refund",
):
if self.type not in ("in_invoice", "in_refund", "out_invoice", "out_refund",):
return self.datev_sanitize(origin)

# Use the correct setting
if self.move_type.startswith("in_"):
if self.type.startswith("in_"):
ref_field = self.sudo().company_id.datev_vendor_order_ref
else:
ref_field = self.sudo().company_id.datev_customer_order_ref

# Show the original move because ref is a combined value for refund
if ref_field == "partner" and self.move_type.endswith("_refund"):
if ref_field == "partner" and self.type.endswith("_refund"):
return self.datev_sanitize(self.reversed_entry_id.name or origin)

# Show the partner reference from the orders stored in ref
Expand Down
9 changes: 4 additions & 5 deletions datev_export_xml/models/datev_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# @author Guenter Selbert <guenter.selbert@sewisoft.de>
# @author Thorsten Vocks
# @author Grzegorz Grzelak
# Copyright 2023 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import datetime
Expand Down Expand Up @@ -187,7 +188,7 @@ def get_invoices(self):
("amount_untaxed", "!=", 0),
("amount_total", "!=", 0),
("state", "in", ("posted", "open")),
("move_type", "in", list_invoice_type),
("type", "in", list_invoice_type),
("company_id", "=", self.company_id.id),
]
if self.company_id.datev_export_state:
Expand Down Expand Up @@ -281,7 +282,7 @@ def export_zip_invoice(self, invoice_ids=None):
invoice_ids = self.env.context.get("active_ids")

invoices = self.env["account.move"].browse(invoice_ids)
types = invoices.mapped("move_type")
types = invoices.mapped("type")

if all(x.startswith("in_") for x in types):
export_type = "in"
Expand Down Expand Up @@ -364,9 +365,7 @@ def action_pending(self):
raise ValidationError(
_("It's not allowed to set an already running export to pending!")
)
r.write(
{"state": "pending", "exception_info": None,}
)
r.write({"state": "pending", "exception_info": None})

def action_draft(self):
for r in self:
Expand Down
8 changes: 3 additions & 5 deletions datev_export_xml/models/datev_pdf_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
# @author Guenter Selbert <guenter.selbert@sewisoft.de>
# @author Thorsten Vocks
# @author Grzegorz Grzelak
# Copyright 2023 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import base64
import logging

from odoo import api, models

_logger = logging.getLogger(__name__)


class DatevPdfGenerator(models.AbstractModel):
_name = "datev.pdf.generator"
Expand Down Expand Up @@ -47,7 +45,7 @@ def generate_pdf(self, invoice):

# Otherwise generate a new once
report = self.env["ir.actions.report"].search(
[("model", "=", "account.move"), ("report_name", "=", self.report_name()),],
[("model", "=", "account.move"), ("report_name", "=", self.report_name())],
)
if report:
return report._render(invoice.ids)[0]
return report.render(invoice.ids)[0]
11 changes: 4 additions & 7 deletions datev_export_xml/models/datev_xml_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
# @author Guenter Selbert <guenter.selbert@sewisoft.de>
# @author Thorsten Vocks
# @author Grzegorz Grzelak
# Copyright 2023 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging
import re

from lxml import etree

from odoo import _, api, models, tools
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)


class DatevXmlGenerator(models.AbstractModel):
_name = "datev.xml.generator"
Expand All @@ -27,12 +25,11 @@ def check_xml_file(self, doc_name, root, xsd=None):
if not xsd:
xsd = "Document_v050.xsd"

schema = tools.file_open(xsd, subdir="addons/datev_export_xml/xsd_files")
schema = tools.file_open(f"datev_export_xml/xsd_files/{xsd}")
try:
schema = etree.XMLSchema(etree.parse(schema))
schema.assertValid(root)
except (etree.DocumentInvalid, etree.XMLSyntaxError) as e:
_logger.warning(etree.tostring(root))
raise UserError(
_(
"Wrong Data in XML file!\nTry to solve the problem with "
Expand All @@ -47,7 +44,7 @@ def check_xml_file(self, doc_name, root, xsd=None):
def generate_xml_document(self, invoices, check_xsd=True):
template = self.env.ref("datev_export_xml.export_invoice_document")
root = etree.fromstring(
template._render({"docs": invoices, "company": self.env.company}),
template.render({"docs": invoices, "company": self.env.company}),
parser=etree.XMLParser(remove_blank_text=True),
)

Expand All @@ -63,7 +60,7 @@ def generate_xml_invoice(self, invoice, check_xsd=True):
doc_name = re.sub(r"[^a-zA-Z0-9_\-.()]", "", f"{invoice.name}.xml")
template = self.env.ref("datev_export_xml.export_invoice")
root = etree.fromstring(
template._render({"doc": invoice}),
template.render({"doc": invoice}),
parser=etree.XMLParser(remove_blank_text=True),
)

Expand Down
3 changes: 0 additions & 3 deletions datev_export_xml/models/datev_zip_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@

import base64
import io
import logging
import zipfile

from odoo import _, api, models
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)


class DatevZipGenerator(models.AbstractModel):
_name = "datev.zip.generator"
Expand Down
1 change: 1 addition & 0 deletions datev_export_xml/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Thorsten Vocks (OpenBIG.org)
* Guenter Selbert (sewisoft.de)
* initOS GmbH (initOS.com)
* Tecnativa - Carolina Fernandez
1 change: 1 addition & 0 deletions datev_export_xml/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ <h2>Contributors</h2>
<li>Thorsten Vocks (OpenBIG.org)</li>
<li>Guenter Selbert (sewisoft.de)</li>
<li>initOS GmbH (initOS.com)</li>
<li>Tecnativa - Carolina Fernandez</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
Loading

0 comments on commit 13f67b1

Please sign in to comment.