-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] datev_export_xml: Migration to 13.0
- Loading branch information
1 parent
5d9702c
commit 2ef80c2
Showing
12 changed files
with
91 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,19 @@ | |
# @author Guenter Selbert <[email protected]> | ||
# @author Thorsten Vocks <[email protected]> | ||
# @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", | ||
|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
# @author Guenter Selbert <[email protected]> | ||
# @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 | ||
|
@@ -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] | ||
|
@@ -57,20 +58,22 @@ 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() | ||
return sorted(pickings, key=lambda x: x.date, reverse=True)[0].date.date() | ||
|
||
_logger.info("Invoice date used as delivery date.") | ||
return self.invoice_date | ||
|
||
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" | ||
|
||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
# @author Guenter Selbert <[email protected]> | ||
# @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 | ||
|
@@ -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: | ||
|
@@ -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" | ||
|
@@ -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: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,12 @@ | |
# @author Guenter Selbert <[email protected]> | ||
# @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" | ||
|
@@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,16 @@ | |
# @author Guenter Selbert <[email protected]> | ||
# @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" | ||
|
@@ -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 " | ||
|
@@ -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), | ||
) | ||
|
||
|
@@ -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), | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.