Skip to content

Commit

Permalink
[IMP] datev_export_xml: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinafernandez-tecnativa committed Dec 11, 2023
1 parent 690009a commit 5d9702c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 84 deletions.
8 changes: 2 additions & 6 deletions datev_export_xml/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
"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 @@ -29,8 +27,6 @@
"views/res_config_settings_views.xml",
"views/templates.xml",
],
"demo": [
"demo/export_data.xml",
],
"demo": ["demo/export_data.xml",],
"installable": True,
}
15 changes: 3 additions & 12 deletions datev_export_xml/models/datev_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ def name_get(self):
datev_filename = fields.Char(
"ZIP filename", readonly=True, related="attachment_id.name"
)
datev_filesize = fields.Char(
"Filesize",
compute="_compute_datev_filesize",
)
datev_filesize = fields.Char("Filesize", compute="_compute_datev_filesize",)

invoice_ids = fields.Many2many(comodel_name="account.move", string="Invoices")
invoices_count = fields.Integer(
Expand Down Expand Up @@ -213,10 +210,7 @@ def get_zip(self):

self.write({"state": "running", "exception_info": None})
with self.env.cr.savepoint():
zip_file = self.generate_zip(
self.invoice_ids,
self.check_xsd,
)
zip_file = self.generate_zip(self.invoice_ids, self.check_xsd,)
if not self.manually_document_selection:
description = _(
"Filtered Export of {} Documents\nDate Range: {}-{}\nTypes: {}"
Expand Down Expand Up @@ -371,10 +365,7 @@ def action_pending(self):
_("It's not allowed to set an already running export to pending!")
)
r.write(
{
"state": "pending",
"exception_info": None,
}
{"state": "pending", "exception_info": None,}
)

def action_draft(self):
Expand Down
5 changes: 1 addition & 4 deletions datev_export_xml/models/datev_pdf_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,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]
8 changes: 2 additions & 6 deletions datev_export_xml/models/datev_xml_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def generate_xml_document(self, invoices, check_xsd=True):

if check_xsd:
self.check_xml_file(
"document.xml",
root,
"Document_v050.xsd",
"document.xml", root, "Document_v050.xsd",
)

return "document.xml", etree.tostring(root)
Expand All @@ -71,9 +69,7 @@ def generate_xml_invoice(self, invoice, check_xsd=True):

if check_xsd:
self.check_xml_file(
doc_name,
root,
"Belegverwaltung_online_invoice_v050.xsd",
doc_name, root, "Belegverwaltung_online_invoice_v050.xsd",
)

return doc_name, etree.tostring(root)
8 changes: 2 additions & 6 deletions datev_export_xml/models/datev_zip_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ def generate_zip(self, invoices, check_xsd):
with io.BytesIO() as s, zipfile.ZipFile(s, mode="w") as zip_file:
xml_document_data = self.generate_xml_document(invoices, check_xsd)
zip_file.writestr(
xml_document_data[0],
xml_document_data[1],
zipfile.ZIP_DEFLATED,
xml_document_data[0], xml_document_data[1], zipfile.ZIP_DEFLATED,
)

for invoice in invoices.with_context(progress_iter=True):
Expand All @@ -62,9 +60,7 @@ def generate_zip(self, invoices, check_xsd):
attachment = self.generate_pdf(invoice)
if attachment:
zip_file.writestr(
invoice.datev_filename(),
attachment,
zipfile.ZIP_DEFLATED,
invoice.datev_filename(), attachment, zipfile.ZIP_DEFLATED,
)

zip_file.close()
Expand Down
12 changes: 4 additions & 8 deletions datev_export_xml/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,17 @@ class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

datev_default_period = fields.Selection(
related="company_id.datev_default_period",
readonly=False,
related="company_id.datev_default_period", readonly=False,
)

datev_export_state = fields.Boolean(
related="company_id.datev_export_state",
readonly=False,
related="company_id.datev_export_state", readonly=False,
)

datev_vendor_order_ref = fields.Selection(
related="company_id.datev_vendor_order_ref",
readonly=False,
related="company_id.datev_vendor_order_ref", readonly=False,
)

datev_customer_order_ref = fields.Selection(
related="company_id.datev_customer_order_ref",
readonly=False,
related="company_id.datev_customer_order_ref", readonly=False,
)
59 changes: 17 additions & 42 deletions datev_export_xml/tests/test_datev_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,7 @@ def create_customer_datev_export_manually(self, invoice):

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

Expand Down Expand Up @@ -346,8 +343,7 @@ def _run_test_invoice(self, doc, invoice):

sign = -1 if invoice.move_type.endswith("_refund") else 1
self.assertEqual(
float(total["net_total_amount"]),
sign * invoice.amount_untaxed,
float(total["net_total_amount"]), sign * invoice.amount_untaxed,
)
self.assertEqual(
float(total["total_gross_amount_excluding_third-party_collection"]),
Expand Down Expand Up @@ -378,12 +374,10 @@ def _run_test_out_refund_datev_export(self, refund):
datev_export = self.create_customer_datev_export(start_date, end_date)
self.assertEqual(datev_export.datev_file, False)
self.assertEqual(
datev_export.client_number,
self.env.company.datev_client_number,
datev_export.client_number, self.env.company.datev_client_number,
)
self.assertEqual(
datev_export.consultant_number,
self.env.company.datev_consultant_number,
datev_export.consultant_number, self.env.company.datev_consultant_number,
)
self.assertEqual(datev_export.state, "draft")
# There is always a first invoice
Expand Down Expand Up @@ -429,12 +423,10 @@ def _run_test_in_refund_datev_export(self, refund, attachment):
attachment = self.update_attachment(attachment, refund)
self.assertEqual(datev_export.datev_file, False)
self.assertEqual(
datev_export.client_number,
self.env.company.datev_client_number,
datev_export.client_number, self.env.company.datev_client_number,
)
self.assertEqual(
datev_export.consultant_number,
self.env.company.datev_consultant_number,
datev_export.consultant_number, self.env.company.datev_consultant_number,
)
self.assertEqual(datev_export.state, "draft")
# There is always a first invoice
Expand Down Expand Up @@ -478,12 +470,10 @@ def _run_test_out_invoice_datev_export(self, invoice):
datev_export = self.create_customer_datev_export(start_date, end_date)
self.assertEqual(datev_export.datev_file, False)
self.assertEqual(
datev_export.client_number,
self.env.company.datev_client_number,
datev_export.client_number, self.env.company.datev_client_number,
)
self.assertEqual(
datev_export.consultant_number,
self.env.company.datev_consultant_number,
datev_export.consultant_number, self.env.company.datev_consultant_number,
)
self.assertEqual(datev_export.state, "draft")
# There is always a first invoice
Expand Down Expand Up @@ -529,12 +519,10 @@ def _run_test_in_invoice_datev_export(self, invoice, attachment):
attachment = self.update_attachment(attachment, invoice)
self.assertEqual(datev_export.datev_file, False)
self.assertEqual(
datev_export.client_number,
self.env.company.datev_client_number,
datev_export.client_number, self.env.company.datev_client_number,
)
self.assertEqual(
datev_export.consultant_number,
self.env.company.datev_consultant_number,
datev_export.consultant_number, self.env.company.datev_consultant_number,
)
self.assertEqual(datev_export.state, "draft")
self.assertEqual(datev_export.invoices_count, 1)
Expand Down Expand Up @@ -575,12 +563,10 @@ def _run_test_out_inv_datev_export_manually(self, invoice):
datev_export = self.create_customer_datev_export_manually(invoice)
self.assertEqual(datev_export.datev_file, False)
self.assertEqual(
datev_export.client_number,
self.env.company.datev_client_number,
datev_export.client_number, self.env.company.datev_client_number,
)
self.assertEqual(
datev_export.consultant_number,
self.env.company.datev_consultant_number,
datev_export.consultant_number, self.env.company.datev_consultant_number,
)
self.assertEqual(datev_export.state, "draft")
self.assertEqual(datev_export.invoices_count, 1)
Expand Down Expand Up @@ -735,31 +721,21 @@ 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,
datev_export.client_number, self.env.company.datev_client_number,
)
self.assertEqual(
datev_export.consultant_number,
self.env.company.datev_consultant_number,
datev_export.consultant_number, self.env.company.datev_consultant_number,
)
self.assertEqual(datev_export.state, "draft")
self.assertEqual(datev_export.date_start, date_start)
Expand All @@ -785,8 +761,7 @@ def test_16_manual_export(self):
)

self.DatevExportObj.with_context(
active_model="account.move",
active_ids=out_invoice.ids,
active_model="account.move", active_ids=out_invoice.ids,
).export_zip_invoice()

in_invoice = self.create_in_invoice(
Expand Down
1 change: 1 addition & 0 deletions setup/datev_export_xml/odoo/addons/datev_export_xml
6 changes: 6 additions & 0 deletions setup/datev_export_xml/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 5d9702c

Please sign in to comment.