From ad3895fa07a6c7cd8ce1d16d88dbeef6e5fc6cff Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Sun, 1 Aug 2021 22:16:33 -0400 Subject: [PATCH 1/4] latex_invoices.py: don't decode() a str These functions all return str's not bytes. Therefore there is no need to decode them. --- bindings/python/example_scripts/latex_invoices.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bindings/python/example_scripts/latex_invoices.py b/bindings/python/example_scripts/latex_invoices.py index 829021adfc..52755da3dc 100644 --- a/bindings/python/example_scripts/latex_invoices.py +++ b/bindings/python/example_scripts/latex_invoices.py @@ -115,19 +115,19 @@ def invoice_to_lco(invoice): add_str = u"" owner = invoice.GetOwner() if owner.GetName() != "": - add_str += owner.GetName().decode("UTF-8") + "\n" + add_str += owner.GetName() + "\n" addr = owner.GetAddr() if addr.GetName() != "": - add_str += addr.GetName().decode("UTF-8") + "\n" + add_str += addr.GetName() + "\n" if addr.GetAddr1() != "": - add_str += addr.GetAddr1().decode("UTF-8") + "\n" + add_str += addr.GetAddr1() + "\n" if addr.GetAddr2() != "": - add_str += addr.GetAddr2().decode("UTF-8") + "\n" + add_str += addr.GetAddr2() + "\n" if addr.GetAddr3() != "": - add_str += addr.GetAddr3().decode("UTF-8") + "\n" + add_str += addr.GetAddr3() + "\n" if addr.GetAddr4() != "": - add_str += addr.GetAddr4().decode("UTF-8") + "\n" + add_str += addr.GetAddr4() + "\n" lco_out += write_variable("toaddress2", add_str) @@ -167,7 +167,7 @@ def invoice_to_lco(invoice): line_str = u"\Artikel{" line_str += un line_str += u"}{" - line_str += descr.decode("UTF-8") + line_str += descr line_str += u"}{" line_str += uprice line_str += u"}" From ba4852a9da5912af5441facc7c7e5e7684332c2c Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Sun, 1 Aug 2021 22:17:11 -0400 Subject: [PATCH 2/4] latex_invoices.py: use default locale Don't hardcode a locale. Empty string means to use the user's locale (e.g. $LANG) --- bindings/python/example_scripts/latex_invoices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/python/example_scripts/latex_invoices.py b/bindings/python/example_scripts/latex_invoices.py index 52755da3dc..84fd5d216d 100644 --- a/bindings/python/example_scripts/latex_invoices.py +++ b/bindings/python/example_scripts/latex_invoices.py @@ -147,7 +147,7 @@ def invoice_to_lco(invoice): # Write the entries ent_str = u"" - locale.setlocale(locale.LC_ALL, "de_DE") + locale.setlocale(locale.LC_ALL, "") for n, ent in enumerate(invoice.GetEntries()): line_str = u"" From 3ed6b4dab9d8635c4e7616e2c135af683e29f768 Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Sun, 1 Aug 2021 22:17:41 -0400 Subject: [PATCH 3/4] latex_invoices.py: write takes string not bytes write() fails if you give it bytes, so don't encode --- bindings/python/example_scripts/latex_invoices.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bindings/python/example_scripts/latex_invoices.py b/bindings/python/example_scripts/latex_invoices.py index 84fd5d216d..f494fb1318 100644 --- a/bindings/python/example_scripts/latex_invoices.py +++ b/bindings/python/example_scripts/latex_invoices.py @@ -160,7 +160,7 @@ def invoice_to_lco(invoice): n = ent.GetQuantity() uprice = locale.currency(price).rstrip(" EUR") - un = unicode( + un = str( int(float(n.num()) / n.denom()) ) # choose best way to format numbers according to locale @@ -288,7 +288,6 @@ def main(argv=None): # Opening output file f = open(output_file_name, "w") - lco_str = lco_str.encode("latin1") f.write(lco_str) f.close() From 5f721614ad08ee10d1f102382cb4fd252dfbf99b Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Sun, 1 Aug 2021 22:29:00 -0400 Subject: [PATCH 4/4] Remove unneeded .decode() from Invoice*.tex.templ These values are already str's, don't decode them --- bindings/python/example_scripts/Invoice.tex.tmpl | 12 ++++++------ bindings/python/example_scripts/Invoice_2.tex.tmpl | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bindings/python/example_scripts/Invoice.tex.tmpl b/bindings/python/example_scripts/Invoice.tex.tmpl index a5248cca9f..a16b03743a 100644 --- a/bindings/python/example_scripts/Invoice.tex.tmpl +++ b/bindings/python/example_scripts/Invoice.tex.tmpl @@ -130,13 +130,13 @@ \Euro %--------------------------------------------------------------------------- \begin{letter}{% {% endraw %} -{{ invoice.GetOwner().GetName().decode("UTF-8") }} \\ -{{ invoice.GetOwner().GetAddr().GetAddr1().decode("UTF-8") }} \\ -{{ invoice.GetOwner().GetAddr().GetAddr2().decode("UTF-8") }} \\ -{{ invoice.GetOwner().GetAddr().GetAddr3().decode("UTF-8") }} +{{ invoice.GetOwner().GetName() }} \\ +{{ invoice.GetOwner().GetAddr().GetAddr1() }} \\ +{{ invoice.GetOwner().GetAddr().GetAddr2() }} \\ +{{ invoice.GetOwner().GetAddr().GetAddr3() }} {# if Addr4 is declared put a linebreak here #} {% if invoice.GetOwner().GetAddr().GetAddr4() %} \\ {% endif %} -{{ invoice.GetOwner().GetAddr().GetAddr4().decode("UTF-8") }} {% raw %} +{{ invoice.GetOwner().GetAddr().GetAddr4() }} {% raw %} } %--------------------------------------------------------------------------- % Weitere Optionen @@ -156,7 +156,7 @@ Ich erlaube mir, Ihnen folgende Beträge in Rechnung zu stellen: {%- for ent in invoice.GetEntries() -%} {{- '\Artikel' -}} {{- '{' -}} {{- ent.GetQuantity() -}} {{- '}' -}} - {{- '{' -}} {{- ent.GetDescription().decode("UTF-8") -}} {{- '}' -}} + {{- '{' -}} {{- ent.GetDescription() -}} {{- '}' -}} {{- '{' -}} {{- ent.GetInvPrice().to_double() -}} {{- '}' -}} {%- endfor -%} {#- **************** JINJA2 Entries END ********************** -#} diff --git a/bindings/python/example_scripts/Invoice_2.tex.tmpl b/bindings/python/example_scripts/Invoice_2.tex.tmpl index 0c94fc7e17..ea2e7e33ef 100644 --- a/bindings/python/example_scripts/Invoice_2.tex.tmpl +++ b/bindings/python/example_scripts/Invoice_2.tex.tmpl @@ -134,13 +134,13 @@ \Euro %--------------------------------------------------------------------------- \begin{letter}{ {%- endraw -%} -{{- invoice.GetOwner().GetName().decode("UTF-8") -}} \\ -{{- invoice.GetOwner().GetAddr().GetAddr1().decode("UTF-8") -}} \\ -{{- invoice.GetOwner().GetAddr().GetAddr2().decode("UTF-8") -}} \\ -{{- invoice.GetOwner().GetAddr().GetAddr3().decode("UTF-8") -}} +{{- invoice.GetOwner().GetName() -}} \\ +{{- invoice.GetOwner().GetAddr().GetAddr1() -}} \\ +{{- invoice.GetOwner().GetAddr().GetAddr2() -}} \\ +{{- invoice.GetOwner().GetAddr().GetAddr3() -}} {# if Addr4 is declared put a linebreak here #} {%- if invoice.GetOwner().GetAddr().GetAddr4() -%} \\ {%- endif -%} -{{- invoice.GetOwner().GetAddr().GetAddr4().decode("UTF-8") -}} {%- raw -%} +{{- invoice.GetOwner().GetAddr().GetAddr4() -}} {%- raw -%} } %--------------------------------------------------------------------------- % Weitere Optionen @@ -167,7 +167,7 @@ Ich erlaube mir, Ihnen folgende Beträge in Rechnung zu stellen: {%- for ent in invoice.GetEntries() %} {{ loop.index }} & {{- locale.format("%.2f", ent.GetQuantity().to_double()) -}} & - {{- ent.GetDescription().decode("UTF-8") -}} & + {{- ent.GetDescription() -}} & \EUR{ {{- locale.format("%.2f", ent.GetInvPrice().to_double()) -}} } & \EUR{ {{- locale.format("%.2f", ent.GetInvPrice().to_double() * ent.GetQuantity().to_double()) -}} } \\ \hline {%- endfor -%}