diff --git a/yuyu/admin/billing_setting/templates/billing_setting/index.html b/yuyu/admin/billing_setting/templates/billing_setting/index.html index 718e1be..3bb3b1b 100644 --- a/yuyu/admin/billing_setting/templates/billing_setting/index.html +++ b/yuyu/admin/billing_setting/templates/billing_setting/index.html @@ -28,7 +28,8 @@

Please make sure all price is already configured before enable billing

Enable - Reset Billing Data + Reset All Billing Data + Reset Transaction Data
{% endif %} diff --git a/yuyu/admin/billing_setting/urls.py b/yuyu/admin/billing_setting/urls.py index 52e9526..dd131b5 100644 --- a/yuyu/admin/billing_setting/urls.py +++ b/yuyu/admin/billing_setting/urls.py @@ -19,6 +19,7 @@ urlpatterns = [ url(r'^enable_billing$', views.EnableBillingView.as_view(), name='enable_billing'), url(r'^disable_billing$', views.DisableBillingView.as_view(), name='disable_billing'), url(r'^reset_billing$', views.ResetBillingView.as_view(), name='reset_billing'), + url(r'^reset_transaction$', views.ResetTransactionView.as_view(), name='reset_transaction'), url(r'^update_setting/$', views.UpdateSettingView.as_view(), name='update_setting'), ] diff --git a/yuyu/admin/billing_setting/views.py b/yuyu/admin/billing_setting/views.py index c60f933..307349a 100644 --- a/yuyu/admin/billing_setting/views.py +++ b/yuyu/admin/billing_setting/views.py @@ -111,3 +111,15 @@ class ResetBillingView(views.APIView): exceptions.handle(self.request, _("Unable to reset billing")) return shortcuts.redirect("horizon:admin:billing_setting:index") + +class ResetTransactionView(views.APIView): + invoice_uc = InvoiceUseCase() + + def get(self, request, *args, **kwargs): + try: + self.invoice_uc.reset_transaction(request) + messages.success(request, _("Data successfully Reset.")) + except Exception: + exceptions.handle(self.request, + _("Unable to reset transaction")) + return shortcuts.redirect("horizon:admin:billing_setting:index") \ No newline at end of file diff --git a/yuyu/admin/notification_center/views.py b/yuyu/admin/notification_center/views.py index 28209ca..b9b50d7 100644 --- a/yuyu/admin/notification_center/views.py +++ b/yuyu/admin/notification_center/views.py @@ -41,7 +41,7 @@ class IndexView(tables.DataTableView): if hasattr(self, "table"): context[self.context_object_name] = self.table - context['select_list'], _ = api.keystone.tenant_list(self.request, user=self.request.user.id) + context['select_list'], _ = api.keystone.tenant_list(self.request) context['current_tenant_id'] = self.request.GET.get('tenant_id', None) return context @@ -67,6 +67,7 @@ class ReadAllView(views.APIView): try: notifications = self.notification_uc.get_list(self.request, filter_selection=self.kwargs['selection']) + for n in notifications: if not n["is_read"]: self.notification_uc.set_read(request, n['id']) diff --git a/yuyu/admin/projects_balance/views.py b/yuyu/admin/projects_balance/views.py index 919e34f..8db1da4 100644 --- a/yuyu/admin/projects_balance/views.py +++ b/yuyu/admin/projects_balance/views.py @@ -34,7 +34,7 @@ class IndexView(tables.DataTableView): def get_data(self): try: data = [] - project_list, has_more = api.keystone.tenant_list(self.request, user=self.request.user.id) + project_list, has_more = api.keystone.tenant_list(self.request) for d in self.balance_uc.list(self.request): project = list(filter(lambda x: x.id == d['project']['tenant_id'], project_list)) project_name = 'Unknown Project' diff --git a/yuyu/admin/projects_invoice/templates/projects_invoice/cost_download.html b/yuyu/admin/projects_invoice/templates/projects_invoice/cost_download.html new file mode 100644 index 0000000..4a8a4c6 --- /dev/null +++ b/yuyu/admin/projects_invoice/templates/projects_invoice/cost_download.html @@ -0,0 +1,139 @@ + + + Invoice Download + {% include '_stylesheets.html' %} + + + +
+
+
+ +
+
+
+
+
+
{{ setting.company_logo }}
+
+
+
+
+

+ invoice
+ order #{{ invoice.id }} +

+
+
+
+
+
+
+
+ {{ setting.company_name }}
+ {{ setting.company_address }} +
+
+
+
+ Invoice Month:
+ {{ invoice.start_date|date:'M Y' }} +
+
+ Invoice State:
+ {{ invoice.state_text }} +
+
+ Subtotal
+ {{ invoice.subtotal_money }} +
+
+ {% if invoice.state != 1 %} + Tax
+ {{ invoice.tax_money }} +
+
+ Total
+ {{ invoice.total_money }} +
+
+ {% endif %} +
+
+
+
+
+

ORDER SUMMARY

+
+
+
+
{{ instance_cost_table.render }}
+ +
{{ volume_cost_table.render }}
+
{{ floating_ip_cost_table.render }}
+
{{ router_cost_table.render }}
+
{{ snapshot_cost_table.render }}
+
{{ image_cost_table.render }}
+
+
+
+
+
+
+ +
+
+
+ + {% include 'horizon/_scripts.html' %} + + + diff --git a/yuyu/admin/projects_invoice/templates/projects_invoice/cost_tabs.html b/yuyu/admin/projects_invoice/templates/projects_invoice/cost_tabs.html index e7c51db..bee7606 100644 --- a/yuyu/admin/projects_invoice/templates/projects_invoice/cost_tabs.html +++ b/yuyu/admin/projects_invoice/templates/projects_invoice/cost_tabs.html @@ -14,7 +14,7 @@
{% include 'admin/projects_invoice/manage_invoice_modal.html' with invoice=invoice project_balance_amount=project_balance_amount %} - + Download PDF
@@ -79,36 +79,3 @@ {% endif %} {% endblock %} -{% block js %} - {{ block.super }} - - - -{% endblock %} diff --git a/yuyu/admin/projects_invoice/templates/projects_invoice/invoice.html b/yuyu/admin/projects_invoice/templates/projects_invoice/invoice.html index 8401242..7ba4d00 100644 --- a/yuyu/admin/projects_invoice/templates/projects_invoice/invoice.html +++ b/yuyu/admin/projects_invoice/templates/projects_invoice/invoice.html @@ -7,17 +7,4 @@
{% include 'admin/projects_invoice/base_invoice.html' %} -{% endblock %} -{% block js %} - {{ block.super }} - - - {% endblock %} \ No newline at end of file diff --git a/yuyu/admin/projects_invoice/urls.py b/yuyu/admin/projects_invoice/urls.py index 18cf879..b0dbff0 100644 --- a/yuyu/admin/projects_invoice/urls.py +++ b/yuyu/admin/projects_invoice/urls.py @@ -19,6 +19,7 @@ urlpatterns = [ url(r'^$', views.IndexView.as_view(), name='index'), url(r'^invoice/detail/(?P[^/]+)/(?P[^/]+)/$', views.InvoiceView.as_view(), name='invoice_detail'), url(r'^invoice/usage/(?P[^/]+)/(?P[^/]+)/$', views.UsageCostTabView.as_view(), name='usage_cost'), + url(r'^invoice/usage/print/(?P[^/]+)/(?P[^/]+)/$', views.UsageCostView.as_view(), name='usage_cost_print'), url(r'^invoice/finish/(?P[^/]+)/$', views.FinishInvoice.as_view(), name='finish_invoice'), url(r'^invoice/rollback_to_unpaid/(?P[^/]+)/$', views.RollbackToUnpaidInvoice.as_view(), name='rollback_to_unpaid'), diff --git a/yuyu/admin/projects_invoice/views.py b/yuyu/admin/projects_invoice/views.py index a938630..c75f58a 100644 --- a/yuyu/admin/projects_invoice/views.py +++ b/yuyu/admin/projects_invoice/views.py @@ -46,7 +46,7 @@ class IndexView(tables.DataTableView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context['project_list'], _ = api.keystone.tenant_list(self.request, user=self.request.user.id) + context['project_list'], _ = api.keystone.tenant_list(self.request) context['current_project_id'] = self.request.GET.get('project_id', self.request.user.project_id) context['current_project_name'] = self.request.GET.get('project_name', self.request.user.project_id) return context @@ -129,6 +129,7 @@ class UsageCostTabView(tabs.TabbedTableView): context = super().get_context_data(**kwargs) balance = self.balance_uc.retrieve_by_project(self.request, self.kwargs['project_id']) context['invoice'] = self.request.invoice + context['project_id'] = self.kwargs['project_id'] context['project_balance_amount'] = Money(amount=balance['amount'], currency=balance['amount_currency']) if balance else 0 return context @@ -138,10 +139,12 @@ class UsageCostView(tables.MultiTableView): table_classes = ( InstanceCostTable, VolumeCostTable, FloatingIpCostTable, RouterCostTable, SnapshotCostTable, ImageCostTable) page_title = _("Usage Cost") - template_name = "admin/projects_invoice/cost_tables.html" + template_name = "admin/projects_invoice/cost_download.html" invoice_uc = InvoiceUseCase() balance_uc = BalanceUseCase() + setting_uc = SettingUseCase() + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -154,6 +157,7 @@ class UsageCostView(tables.MultiTableView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) balance = self.balance_uc.retrieve_by_project(self.request, self.kwargs['project_id']) + context['setting'] = self.setting_uc.get_settings(self.request) context['invoice'] = self.request.invoice context['project_balance_amount'] = Money(amount=balance['amount'], currency=balance['amount_currency']) if balance else 0 diff --git a/yuyu/cases/invoice_use_case.py b/yuyu/cases/invoice_use_case.py index 8e7c0d4..e9223ff 100644 --- a/yuyu/cases/invoice_use_case.py +++ b/yuyu/cases/invoice_use_case.py @@ -109,6 +109,9 @@ class InvoiceUseCase: def reset_billing(self, request): yuyu_client.post(request, f"invoice/reset_billing/", {}) + + def reset_transaction(self, request): + yuyu_client.post(request, f"invoice/reset_transaction_data/", {}) def finish_invoice(self, request, id, skip_balance): response = yuyu_client.get(request, f"invoice/{id}/finish/?skip_balance={skip_balance}") diff --git a/yuyu/cases/notification_use_case.py b/yuyu/cases/notification_use_case.py index 6d84c27..a3333ab 100644 --- a/yuyu/cases/notification_use_case.py +++ b/yuyu/cases/notification_use_case.py @@ -3,7 +3,7 @@ from openstack_dashboard.dashboards.yuyu.core import yuyu_client class NotificationCenterUseCase: def get_list(self, request, filter_selection=None): - if filter_selection is None: + if filter_selection is None or filter_selection == 'None': return yuyu_client.get(request, f"notification/").json() return yuyu_client.get(request, f"notification/?tenant_id={filter_selection}").json() diff --git a/yuyu/project/usage_cost/templates/usage_cost/cost_download.html b/yuyu/project/usage_cost/templates/usage_cost/cost_download.html new file mode 100644 index 0000000..4a8a4c6 --- /dev/null +++ b/yuyu/project/usage_cost/templates/usage_cost/cost_download.html @@ -0,0 +1,139 @@ + + + Invoice Download + {% include '_stylesheets.html' %} + + + +
+
+
+ +
+
+
+
+
+
{{ setting.company_logo }}
+
+
+
+
+

+ invoice
+ order #{{ invoice.id }} +

+
+
+
+
+
+
+
+ {{ setting.company_name }}
+ {{ setting.company_address }} +
+
+
+
+ Invoice Month:
+ {{ invoice.start_date|date:'M Y' }} +
+
+ Invoice State:
+ {{ invoice.state_text }} +
+
+ Subtotal
+ {{ invoice.subtotal_money }} +
+
+ {% if invoice.state != 1 %} + Tax
+ {{ invoice.tax_money }} +
+
+ Total
+ {{ invoice.total_money }} +
+
+ {% endif %} +
+
+
+
+
+

ORDER SUMMARY

+
+
+
+
{{ instance_cost_table.render }}
+ +
{{ volume_cost_table.render }}
+
{{ floating_ip_cost_table.render }}
+
{{ router_cost_table.render }}
+
{{ snapshot_cost_table.render }}
+
{{ image_cost_table.render }}
+
+
+
+
+
+
+ +
+
+
+ + {% include 'horizon/_scripts.html' %} + + + diff --git a/yuyu/project/usage_cost/templates/usage_cost/index_tabs.html b/yuyu/project/usage_cost/templates/usage_cost/index_tabs.html index 7aa9036..8f232ab 100644 --- a/yuyu/project/usage_cost/templates/usage_cost/index_tabs.html +++ b/yuyu/project/usage_cost/templates/usage_cost/index_tabs.html @@ -18,7 +18,7 @@
- + Download PDF
@@ -81,42 +81,3 @@

You don't have any usage yet


{% endif %} {% endblock %} - -{% block js %} - {{ block.super }} - - - -{% endblock %} diff --git a/yuyu/project/usage_cost/urls.py b/yuyu/project/usage_cost/urls.py index b57a22b..3a3f885 100644 --- a/yuyu/project/usage_cost/urls.py +++ b/yuyu/project/usage_cost/urls.py @@ -17,4 +17,5 @@ from openstack_dashboard.dashboards.yuyu.project.usage_cost import views urlpatterns = [ url(r'^$', views.IndexViewTab.as_view(), name='index'), + url(r'^download/$', views.DownloadView.as_view(), name='download'), ] diff --git a/yuyu/project/usage_cost/views.py b/yuyu/project/usage_cost/views.py index 2953609..706ddd4 100644 --- a/yuyu/project/usage_cost/views.py +++ b/yuyu/project/usage_cost/views.py @@ -17,6 +17,7 @@ from djmoney.money import Money from horizon import exceptions, tables, tabs from openstack_dashboard import api from openstack_dashboard.dashboards.yuyu.cases.invoice_use_case import InvoiceUseCase +from openstack_dashboard.dashboards.yuyu.cases.setting_use_case import SettingUseCase from openstack_dashboard.dashboards.yuyu.core.usage_cost.tables import InstanceCostTable, VolumeCostTable, \ FloatingIpCostTable, RouterCostTable, SnapshotCostTable, ImageCostTable from openstack_dashboard.dashboards.yuyu.core.usage_cost.tabs import UsageCostTabs @@ -51,13 +52,14 @@ class IndexViewTab(tabs.TabbedTableView): return context -class IndexView(tables.MultiTableView): +class DownloadView(tables.MultiTableView): table_classes = ( InstanceCostTable, VolumeCostTable, FloatingIpCostTable, RouterCostTable, SnapshotCostTable, ImageCostTable) page_title = _("Usage Cost") - template_name = "project/usage_cost/cost_tables.html" + template_name = "project/usage_cost/cost_download.html" invoice_uc = InvoiceUseCase() + setting_uc = SettingUseCase() def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -71,12 +73,14 @@ class IndexView(tables.MultiTableView): invoice_id = request.invoice_list[0]['id'] request.invoice = self.invoice_uc.get_invoice(self.request, invoice_id) if request.has_invoice else {} - return super(IndexView, self).get(request, *args, **kwargs) + return super(DownloadView, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['invoice_list'] = self.request.invoice_list context['invoice'] = self.request.invoice + context['setting'] = self.setting_uc.get_settings(self.request) + return context def _get_flavor_name(self, flavor_id):