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 Nov 28, 2023
1 parent c403ec2 commit f5618c9
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 48 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 <[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",
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,
}
20 changes: 8 additions & 12 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 <[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
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,9 +58,9 @@ 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":
elif self.type == "in_invoice":
pickings = self.mapped("invoice_line_ids.purchase_order_id.picking_ids")

if pickings:
Expand All @@ -70,7 +71,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 +82,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 <[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
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 <[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"
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]
5 changes: 3 additions & 2 deletions datev_export_xml/models/datev_xml_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,7 +48,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 +64,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
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
34 changes: 17 additions & 17 deletions datev_export_xml/tests/test_datev_export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (C) 2022-2023 initOS GmbH
# Copyright (C) 2020, Elego Software Solutions GmbH, Berlin
# Copyright 2023 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import base64
import io
Expand Down Expand Up @@ -81,6 +82,7 @@ def setUp(self):
self.refund_date = self.today - timedelta(days=55)
self.start_date = self.today - timedelta(days=34)
self.end_date = self.today - timedelta(days=32)
self.InvoiceObj.search([("state", "=", "posted")]).button_draft()
self.InvoiceObj.with_context(force_delete=True).search([]).unlink()
self.env.company.datev_default_period = "week"

Expand Down Expand Up @@ -143,7 +145,7 @@ def create_out_invoice(self, customer, start_date, end_date):
"invoice_date_due": end_date,
"company_id": self.env.company.id,
"currency_id": self.env.company.currency_id.id,
"move_type": "out_invoice",
"type": "out_invoice",
"invoice_line_ids": [
(
0,
Expand Down Expand Up @@ -178,7 +180,7 @@ def create_out_invoice_with_tax(self, customer, start_date, end_date, tax):
"invoice_date_due": end_date,
"company_id": self.env.company.id,
"currency_id": self.env.company.currency_id.id,
"move_type": "out_invoice",
"type": "out_invoice",
"invoice_line_ids": [
(
0,
Expand Down Expand Up @@ -218,7 +220,7 @@ def create_in_invoice(self, vendor, start_date, end_date):
"invoice_date_due": end_date,
"company_id": self.env.company.id,
"currency_id": self.env.company.currency_id.id,
"move_type": "in_invoice",
"type": "in_invoice",
"invoice_line_ids": [
(
0,
Expand Down Expand Up @@ -293,9 +295,7 @@ def create_customer_datev_export_manually(self, invoice):
return datev_export

def update_attachment(self, attachment, invoice):
attachment.write(
{"res_model": "account.invoice", "res_id": invoice.id,}
)
attachment.write({"res_model": "account.move", "res_id": invoice.id})
return attachment

def _run_test_document(self, doc, invoice):
Expand All @@ -309,7 +309,7 @@ def _run_test_document(self, doc, invoice):

self.assertEqual(
doc(".//property[@key='InvoiceType']").attrib["value"],
"Outgoing" if invoice.move_type.startswith("out_") else "Incoming",
"Outgoing" if invoice.type.startswith("out_") else "Incoming",
)

def _run_test_invoice(self, doc, invoice):
Expand All @@ -322,12 +322,12 @@ def _run_test_invoice(self, doc, invoice):
self.assertEqual(
info["invoice_type"],
"Rechnung"
if invoice.move_type.endswith("_invoice")
if invoice.type.endswith("_invoice")
else "Gutschrift/Rechnungskorrektur",
)
self.assertEqual(info["invoice_date"], invoice.invoice_date.isoformat())

if invoice.move_type.startswith("out_"):
if invoice.type.startswith("out_"):
self.assertEqual(
doc(".//invoice_party/address").attrib["name"],
invoice.partner_id.display_name,
Expand All @@ -341,7 +341,7 @@ def _run_test_invoice(self, doc, invoice):
self.assertEqual(float(line["quantity"]), inv_line.quantity)
self.assertEqual(line["product_id"], inv_line.product_id.default_code)

sign = -1 if invoice.move_type.endswith("_refund") else 1
sign = -1 if invoice.type.endswith("_refund") else 1
self.assertEqual(
float(total["net_total_amount"]), sign * invoice.amount_untaxed,
)
Expand All @@ -362,7 +362,7 @@ def _run_test_invoice(self, doc, invoice):

def _run_test_out_refund_datev_export(self, refund):
line = refund.invoice_line_ids.filtered("product_id")[0]
self.assertEqual(refund.move_type, "out_refund")
self.assertEqual(refund.type, "out_refund")
self.assertEqual(line.account_id, self.account_income)
self.assertEqual(line.price_unit, 120.00)
self.assertEqual(line.quantity, 5.00)
Expand Down Expand Up @@ -409,7 +409,7 @@ def _run_test_out_refund_datev_export(self, refund):

def _run_test_in_refund_datev_export(self, refund, attachment):
line = refund.invoice_line_ids.filtered("product_id")[0]
self.assertEqual(refund.move_type, "in_refund")
self.assertEqual(refund.type, "in_refund")
self.assertEqual(line.account_id, self.account_expense)
self.assertEqual(line.price_unit, 900.00)
self.assertEqual(line.quantity, 1.00)
Expand Down Expand Up @@ -458,7 +458,7 @@ def _run_test_in_refund_datev_export(self, refund, attachment):

def _run_test_out_invoice_datev_export(self, invoice):
line = invoice.invoice_line_ids.filtered("product_id")[0]
self.assertEqual(invoice.move_type, "out_invoice")
self.assertEqual(invoice.type, "out_invoice")
self.assertEqual(line.account_id, self.account_income)
self.assertEqual(line.price_unit, 120.00)
self.assertEqual(line.quantity, 5.00)
Expand Down Expand Up @@ -505,7 +505,7 @@ def _run_test_out_invoice_datev_export(self, invoice):

def _run_test_in_invoice_datev_export(self, invoice, attachment):
line = invoice.invoice_line_ids.filtered("product_id")[0]
self.assertEqual(invoice.move_type, "in_invoice")
self.assertEqual(invoice.type, "in_invoice")
self.assertEqual(line.account_id, self.account_expense)
self.assertEqual(line.price_unit, 900.00)
self.assertEqual(line.quantity, 1.00)
Expand Down Expand Up @@ -553,7 +553,7 @@ def _run_test_in_invoice_datev_export(self, invoice, attachment):

def _run_test_out_inv_datev_export_manually(self, invoice):
line = invoice.invoice_line_ids.filtered("product_id")[0]
self.assertEqual(invoice.move_type, "out_invoice")
self.assertEqual(invoice.type, "out_invoice")
self.assertEqual(line.account_id, self.account_income)
self.assertEqual(line.price_unit, 120.00)
self.assertEqual(line.quantity, 5.00)
Expand Down Expand Up @@ -721,15 +721,15 @@ def test_14_datev_export_without_invoice(self):
# (Invoices/Refunds) you want to export!"
with self.assertRaises(ValidationError):
datev_export = self.DatevExportObj.create(
{"export_type": "out", "export_invoice": False, "export_refund": False,}
{"export_type": "out", "export_invoice": False, "export_refund": False}
)
# 2. when default values are set
# date_start, date_end (based on datev_default_period of current company)
# export_invoice = True,
# export_refund = True,
# check_xsd = True,
# manually_document_selection = Flase
datev_export = self.DatevExportObj.create({"export_type": "out",})
datev_export = self.DatevExportObj.create({"export_type": "out"})
self.assertEqual(datev_export.datev_file, False)
self.assertEqual(
datev_export.client_number, self.env.company.datev_client_number,
Expand Down
3 changes: 2 additions & 1 deletion datev_export_xml/views/datev_export_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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).
-->
<odoo>
Expand Down Expand Up @@ -252,7 +253,7 @@
<field name="amount_residual" />
<field name="currency_id" invisible="1" />
<field name="state" />
<field name="move_type" />
<field name="type" />
</tree>
</field>
</group>
Expand Down
6 changes: 3 additions & 3 deletions datev_export_xml/views/templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
/>

<invoice_party t-call="datev_export_xml.export_party">
<t t-if="doc.move_type in ['out_invoice', 'out_refund']">
<t t-if="doc.type in ['out_invoice', 'out_refund']">
<t t-set="partner" t-value="doc.partner_id" />
<t
t-set="account"
Expand All @@ -100,7 +100,7 @@
</invoice_party>

<supplier_party t-call="datev_export_xml.export_party">
<t t-if="doc.move_type in ['out_invoice', 'out_refund']">
<t t-if="doc.type in ['out_invoice', 'out_refund']">
<t t-set="partner" t-value="doc.company_id.partner_id" />
</t>
<t t-else="">
Expand Down Expand Up @@ -165,7 +165,7 @@
<property
key="InvoiceType"
value="Outgoing"
t-if="doc.move_type in ['out_invoice', 'out_refund']"
t-if="doc.type in ['out_invoice', 'out_refund']"
/>
<property key="InvoiceType" value="Incoming" t-else="" />
</extension>
Expand Down

0 comments on commit f5618c9

Please sign in to comment.