Skip to content

Commit

Permalink
[FIX] datev_export_xml: Count the number of files for the threshold i…
Browse files Browse the repository at this point in the history
…nstead
  • Loading branch information
fkantelberg committed Jun 24, 2024
1 parent bd7aee7 commit 33accf4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion datev_export_xml/models/datev_zip_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def generate_zip(self, invoices, check_xsd):

package_limit = self.env.company.datev_package_limit * 1024 * 1024
included = invoices.browse()
file_counter = 0

buf = io.BytesIO()
zip_file = zipfile.ZipFile(buf, mode="w", compression=zipfile.ZIP_DEFLATED)
Expand All @@ -56,23 +57,26 @@ def generate_zip(self, invoices, check_xsd):
# create xml file for invoice
xml_invoice_data = self.generate_xml_invoice(invoice, check_xsd)
zip_file.writestr(invoice.datev_filename(".xml"), xml_invoice_data[1])
file_counter += 1

# attach pdf file for vendor bills
attachment = self.generate_pdf(invoice)
if attachment:
zip_file.writestr(invoice.datev_filename(), attachment)
file_counter += 1

included |= invoice

# The file can grow slightly bigger than the limit
if buf.tell() > package_limit or len(included) >= 4500:
if buf.tell() > package_limit or file_counter >= 4800:
# Finalize the file
zip_file.writestr(*self.generate_xml_document(included, check_xsd))
zip_file.close()

Check warning on line 74 in datev_export_xml/models/datev_zip_generator.py

View check run for this annotation

Codecov / codecov/patch

datev_export_xml/models/datev_zip_generator.py#L73-L74

Added lines #L73 - L74 were not covered by tests

yield base64.b64encode(buf.getvalue()), included

Check warning on line 76 in datev_export_xml/models/datev_zip_generator.py

View check run for this annotation

Codecov / codecov/patch

datev_export_xml/models/datev_zip_generator.py#L76

Added line #L76 was not covered by tests

# Open next zip and increment
file_counter = 0
buf = io.BytesIO()
included = invoices.browse()
zip_file = zipfile.ZipFile(

Check warning on line 82 in datev_export_xml/models/datev_zip_generator.py

View check run for this annotation

Codecov / codecov/patch

datev_export_xml/models/datev_zip_generator.py#L79-L82

Added lines #L79 - L82 were not covered by tests
Expand Down

0 comments on commit 33accf4

Please sign in to comment.