From 9b3b47910e6886830f4b3db6fe49edf4e60035b7 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lemburg Date: Wed, 9 Nov 2016 15:35:37 +0100 Subject: [PATCH 1/5] Fix stats display to output values sorted by fare code and price. --- assopy/stats.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/assopy/stats.py b/assopy/stats.py index cd623b91d..c6ef1c7f6 100644 --- a/assopy/stats.py +++ b/assopy/stats.py @@ -190,7 +190,14 @@ def _calc_prices(order_id, items): if price not in tcp[code]['prices']: tcp[code]['prices'][price] = { 'price': price, 'count': 0 } tcp[code]['prices'][price]['count'] += 1 - return tcp.values() + # Replace prices dicts with sorted lists + for code in tcp.keys(): + prices_list = [entry + for price, entry in sorted(tcp[code]['prices'].items())] + tcp[code]['prices'] = prices_list + # Create list sorted by fare code + ticket_sales = [entry for code, entry in sorted(tcp.items())] + return ticket_sales prezzo_biglietti_ricalcolato.template = ''' @@ -199,7 +206,7 @@ def _calc_prices(order_id, items): {% for ticket in data %} - {% for p in ticket.prices.values %} + {% for p in ticket.prices %} {% if forloop.counter == 1 %} From e1fddbd8f7997b881662e29d68419e17e05f4875 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lemburg Date: Wed, 9 Nov 2016 19:26:04 +0100 Subject: [PATCH 2/5] Sort the fare prices descending to better integrate with the budget spreadsheet. --- assopy/stats.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assopy/stats.py b/assopy/stats.py index c6ef1c7f6..3f7daf267 100644 --- a/assopy/stats.py +++ b/assopy/stats.py @@ -193,7 +193,8 @@ def _calc_prices(order_id, items): # Replace prices dicts with sorted lists for code in tcp.keys(): prices_list = [entry - for price, entry in sorted(tcp[code]['prices'].items())] + for price, entry in sorted(tcp[code]['prices'].items(), + reverse=True)] tcp[code]['prices'] = prices_list # Create list sorted by fare code ticket_sales = [entry for code, entry in sorted(tcp.items())] From f319f35d2666bae4dad093b8eccb8c4f95a65520 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lemburg Date: Mon, 19 Aug 2019 21:02:10 +0200 Subject: [PATCH 3/5] Fix invoice exports to work with EUR as well (abstract away the currency). --- conference/debug_panel.py | 22 ++++++++-------- conference/invoicing.py | 26 +++++++++++-------- templates/conference/debugpanel/index.html | 4 +-- .../debugpanel/invoices_export.html | 2 +- tests/test_invoices.py | 4 +-- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/conference/debug_panel.py b/conference/debug_panel.py index 20bea09f0..ad69e3b48 100644 --- a/conference/debug_panel.py +++ b/conference/debug_panel.py @@ -29,8 +29,8 @@ REAL_INVOICE_PREFIX, next_invoice_code_for_year, render_invoice_as_html, - export_invoices_to_2018_tax_report, - export_invoices_to_2018_tax_report_csv, + export_invoices_to_tax_report, + export_invoices_to_tax_report_csv, export_invoices_for_payment_reconciliation, extract_customer_info, ) @@ -187,9 +187,9 @@ def debug_panel_invoice_example(request): @staff_member_required -def debug_panel_invoice_export_for_tax_report_2018(request): +def debug_panel_invoice_export_for_tax_report(request): start_date, end_date = get_start_end_dates(request) - invoices_and_exported = export_invoices_to_2018_tax_report( + invoices_and_exported = export_invoices_to_tax_report( start_date, end_date ) @@ -203,13 +203,13 @@ def debug_panel_invoice_export_for_tax_report_2018(request): @staff_member_required -def debug_panel_invoice_export_for_tax_report_2018_csv(request): +def debug_panel_invoice_export_for_tax_report_csv(request): response = HttpResponse(content_type='text/csv') response['Content-Disposition'] =\ 'attachment; filename="export-invoices.csv"' start_date, end_date = get_start_end_dates(request) - export_invoices_to_2018_tax_report_csv(response, start_date, end_date) + export_invoices_to_tax_report_csv(response, start_date, end_date) return response @@ -274,7 +274,7 @@ class Meta: new_invoice.html = render_invoice_as_html(new_invoice) new_invoice.save() - return redirect('debug_panel_invoice_export_for_tax_report_2018') + return redirect('debug_panel_invoice_export_for_tax_report') else: customer = ( old_invoice.customer @@ -350,11 +350,11 @@ class FareSetup: debug_panel_invoice_force_preview, name="debug_panel_invoice_forcepreview"), url(r'^invoices_export/$', - debug_panel_invoice_export_for_tax_report_2018, - name='debug_panel_invoice_export_for_tax_report_2018'), + debug_panel_invoice_export_for_tax_report, + name='debug_panel_invoice_export_for_tax_report'), url(r'^invoices_export.csv$', - debug_panel_invoice_export_for_tax_report_2018_csv, - name='debug_panel_invoice_export_for_tax_report_2018_csv'), + debug_panel_invoice_export_for_tax_report_csv, + name='debug_panel_invoice_export_for_tax_report_csv'), url(r'^invoices_export_for_accounting.json$', debug_panel_invoice_export_for_payment_reconciliation_json, name='debug_panel_invoice_export_for_payment_reconciliation_json'), diff --git a/conference/invoicing.py b/conference/invoicing.py index 6179f95e3..18ba0086b 100644 --- a/conference/invoicing.py +++ b/conference/invoicing.py @@ -291,7 +291,7 @@ def render_invoice_as_html(invoice): return render_to_string('assopy/invoice.html', ctx) -CSV_2018_REPORT_COLUMNS = [ +CSV_REPORT_COLUMNS = [ 'ID', 'Emit Date', 'Buyer Name', @@ -299,13 +299,16 @@ def render_invoice_as_html(invoice): 'Address', 'Country', 'VAT ID', - 'Net Price in GBP', - 'VAT in GBP', - 'Gross Price in GBP', + 'Currency', + 'Net Price', + 'VAT', + 'Gross Price', ] +# For b/w compatibility +CSV_2018_REPORT_COLUMNS = CSV_REPORT_COLUMNS -def export_invoices_to_2018_tax_report(start_date, end_date=None): +def export_invoices_to_tax_report(start_date, end_date=None): if end_date is None: end_date = datetime.date.today() @@ -329,21 +332,22 @@ def export_invoices_to_2018_tax_report(start_date, end_date=None): output['Country'] = "" output['VAT ID'] = invoice.order.vat_number - output['Net Price in %s' % invoice.local_currency] =\ + output['Currency'] = invoice.local_currency + output['Net Price'] =\ invoice.net_price_in_local_currency - output['VAT in %s' % invoice.local_currency] =\ + output['VAT'] =\ invoice.vat_in_local_currency - output['Gross Price in %s' % invoice.local_currency] =\ + output['Gross Price'] =\ invoice.price_in_local_currency yield invoice, output -def export_invoices_to_2018_tax_report_csv(fp, start_date, end_date=None): - writer = csv.DictWriter(fp, CSV_2018_REPORT_COLUMNS, quoting=csv.QUOTE_ALL) +def export_invoices_to_tax_report_csv(fp, start_date, end_date=None): + writer = csv.DictWriter(fp, CSV_REPORT_COLUMNS, quoting=csv.QUOTE_ALL) writer.writeheader() - for invoice, to_export in export_invoices_to_2018_tax_report( + for invoice, to_export in export_invoices_to_tax_report( start_date, end_date ): writer.writerow(to_export) diff --git a/templates/conference/debugpanel/index.html b/templates/conference/debugpanel/index.html index 5eb039f19..62db60ae2 100644 --- a/templates/conference/debugpanel/index.html +++ b/templates/conference/debugpanel/index.html @@ -18,8 +18,8 @@

Additional links

diff --git a/templates/conference/debugpanel/invoices_export.html b/templates/conference/debugpanel/invoices_export.html index 512a6da56..dfbdaab41 100644 --- a/templates/conference/debugpanel/invoices_export.html +++ b/templates/conference/debugpanel/invoices_export.html @@ -35,7 +35,7 @@

Invoices (from {{ start_date|date:"Y-m-d" }} to {{ end_date|date:"Y-m-d" }})

- Download the CSV file + Download the CSV file Download as JSON (for payment reco)

diff --git a/tests/test_invoices.py b/tests/test_invoices.py index 94a68e1cd..56b3d172c 100644 --- a/tests/test_invoices.py +++ b/tests/test_invoices.py @@ -606,7 +606,7 @@ def test_export_invoice_csv(client): query_string = query_dict.urlencode() response = client.get( - reverse("debug_panel_invoice_export_for_tax_report_2018_csv") + reverse("debug_panel_invoice_export_for_tax_report_csv") + "?" + query_string ) @@ -660,7 +660,7 @@ def test_export_invoice_csv_before_period(client): query_string = query_dict.urlencode() response = client.get( - reverse("debug_panel_invoice_export_for_tax_report_2018_csv") + reverse("debug_panel_invoice_export_for_tax_report_csv") + "?" + query_string ) From 09a6f140e95820c875923e88a1e25ee8a262d52e Mon Sep 17 00:00:00 2001 From: Marc-Andre Lemburg Date: Mon, 19 Aug 2019 21:16:03 +0200 Subject: [PATCH 4/5] Fix one more reverse URL. --- tests/test_invoices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_invoices.py b/tests/test_invoices.py index 56b3d172c..df231a04f 100644 --- a/tests/test_invoices.py +++ b/tests/test_invoices.py @@ -696,7 +696,7 @@ def test_export_invoice(client): query_string = query_dict.urlencode() response = client.get( - reverse("debug_panel_invoice_export_for_tax_report_2018") + reverse("debug_panel_invoice_export_for_tax_report") + "?" + query_string ) From c829bd339d56dd14eaea8f6afb33993041972107 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lemburg Date: Mon, 19 Aug 2019 22:17:54 +0200 Subject: [PATCH 5/5] Fix test to skip the currency column. --- tests/test_invoices.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_invoices.py b/tests/test_invoices.py index df231a04f..9344e2717 100644 --- a/tests/test_invoices.py +++ b/tests/test_invoices.py @@ -628,6 +628,7 @@ def test_export_invoice_csv(client): next(iter_column) # ignore the address assert next(iter_column) == invoice1.order.country.name assert next(iter_column) == invoice1.order.vat_number + next(iter_column) # ignore the currency assert ( decimal.Decimal(next(iter_column)) == invoice1.net_price_in_local_currency

Price
{{ ticket.code }}