Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view to generate invoice for contribution #5331

Merged
merged 7 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/grants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def get_converted_amount(self):
return None

def get_converted_monthly_amount(self):
converted_amount = self.get_converted_amount()
converted_amount = self.get_converted_amount() or 0

total_sub_seconds = Decimal(self.real_period_seconds) * Decimal(self.num_tx_approved)

Expand Down
8 changes: 7 additions & 1 deletion app/grants/templates/grants/detail/tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ <h4 class="m-auto text-center font-weight-semibold">{% trans "No Activity for th
<img src="/dynamic/avatar/{{handle}}" />
</div>
<div class="mt-1 d-inline-block">
<span class="grant-profile font-weight-semibold">{{ handle }}</span>
<span class="grant-profile font-weight-semibold">{{ handle }}</span><br>
{% if handle == request.user.profile.handle %}
<a href="{% url "grants:contribution_invoice" contribution.id %}">Get invoice</a>
{% endif %}
</div>



</a>

{% empty %}
Expand Down
212 changes: 212 additions & 0 deletions app/grants/templates/grants/invoice.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
{% load i18n static %}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
{% include 'shared/head.html' %}
{% include 'shared/cards.html' %}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ deindent these by 1

<style>
.invoice-box {
max-width: 1000px;
margin: 50px auto;
padding: 30px;
border: 1px solid #eee;
box-shadow: 0 0 10px rgba(0, 0, 0, .15);
font-size: 16px;
line-height: 24px;
color: #555;
}

a {
color: #555;
text-decoration: underline;
}

.invoice-box table {
width: 100%;
line-height: inherit;
text-align: left;
}

.invoice-box table td {
padding: 5px;
vertical-align: top;
}

.invoice-box table tr td:nth-child(2) {
text-align: right;
}

.invoice-box table tr.top table td {
padding-bottom: 20px;
}

.invoice-box table tr.top table td.title {
font-size: 45px;
line-height: 45px;
color: #333;
}

.invoice-box table tr.information table td {
padding-bottom: 40px;
}

.invoice-box table tr.heading td {
background: #eee;
border-bottom: 1px solid #ddd;
font-weight: bold;
}

.invoice-box table tr.details td {
padding-bottom: 20px;
}

.invoice-box table tr.item td{
border-bottom: 1px solid #eee;
}

.invoice-box table tr.item.last td {
border-bottom: none;
}

.invoice-box table tr.total td:nth-child(2) {
border-top: 2px solid #eee;
font-weight: bold;
}

@media only screen and (max-width: 600px) {
.invoice-box table tr.top table td {
width: 100%;
display: block;
text-align: center;
}

.invoice-box table tr.information table td {
width: 100%;
display: block;
text-align: center;
}
}

/** RTL **/
.rtl {
direction: rtl
}

.rtl table {
text-align: right;
}

.rtl table tr td:nth-child(2) {
text-align: left;
}
</style>
</head>

<body class="g-font-muli">
<div class="invoice-box">
{% if grant.network != 'mainnet' %}
<div style="color:red; border: 1px red solid; padding: 5px;">
{% trans "Note: This is not a mainnet grant, it is a " %} {{grant.network}} {% trans "grant, and this invoice is only for demonstration purposes." %}
</div>
{% endif %}
<table cellpadding="0" cellspacing="0">
<tr class="top">
<td colspan="2">
<table>
<tr>
<td class="title">
<img src="{% static "v2/images/presskit/GitcoinLogoText.svg" %}" style="width:100%; max-width:300px;">
</td>

<td>
{% trans "Invoice" %} #: {{contribution.pk}}<br>
{% trans "Created" %}: {{contribution.created_on}}<br>
{% trans "Status" %}: {{subscription.status}}<br>
{% trans "For" %}: <a href="{{subscription.grant.url}}">{% trans "Gitcoin Grant" %} {{subscription.grant.pk}}</a> <br>
</td>
</tr>
</table>
</td>
</tr>

<tr class="information">
<td colspan="2">
<table>
<tr>
<td>
{% trans "Prepared by" %} <br>
Gitcoin Core LLC<br>
ConsenSys Inc. <br>
49 Bogart Street Suite 22 <br>
Brooklyn, NY 11206 <br>
</td>

<td>
{% trans "Prepared for Funder" %}: <br>
{{subscription.grant.admin_address}}<br>
@{{subscription.grant.admin_profile.handle}}<br>
{{subscription.grant.admin_profile.email}}<br>
</td>
</tr>
</table>
</td>
</tr>

<tr class="heading">
<td>
{% trans "Payment Method" %}
</td>

<td>
{% trans "Account" %} #
</td>
</tr>

<tr class="details">
<td>
{% trans "Directly to counterparties via Ethereum Blockchain" %}
</td>

<td>
{{subscription.grant.contract_address}}
</td>
</tr>

<tr class="heading">
<td>
Item
</td>

<td>
Price
</td>
</tr>

<tr class="item">
<td>
{% trans "Contribution from " %}{{subscription.contributor_profile.handle}} {{subscription.contributor_address}}<br>
{{subscription.num_tx_approved|floatformat:"0" }} {% trans "period of " %} {{subscription.frequency}} {{subscription.frequency_unit}} ({{subscription.subscription_contribution.count}} / {{subscription.num_tx_approved|floatformat:"0" }})
</td>

<td>
{{ subscription.amount_per_period}} {{subscription.token_symbol}} (${{amount_per_period|default:0.0|floatformat:2}} USD)
<br>
</td>
</tr>


<tr class="total">
<td>
{% if amount_per_period %}
{% trans "Total:" %} ${{amount_per_period|default:0.0|floatformat:'2'}} USD
{%else%}
{% trans "Total:" %} $0.00 USD
{%endif%}
</td>
</tr>
</table>
</div>
</body>
</html>
9 changes: 7 additions & 2 deletions app/grants/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from django.urls import path, re_path

from grants.views import (
grant_details, grant_fund, grant_new, grant_new_v0, grants, leaderboard, milestones, new_matching_partner, profile,
quickstart, subscription_cancel,
grant_details, grant_fund, grant_new, grant_new_v0, grants, invoice, leaderboard, milestones, new_matching_partner,
profile, quickstart, subscription_cancel,
)

app_name = 'grants'
Expand All @@ -42,4 +42,9 @@
re_path(r'^quickstart', quickstart, name='quickstart'),
re_path(r'^leaderboard', leaderboard, name='leaderboard'),
re_path(r'^matching-partners/new', new_matching_partner, name='new_matching_partner'),
path(
'invoice/contribution/<int:contribution_pk>',
invoice,
name='contribution_invoice'
),
]
21 changes: 20 additions & 1 deletion app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from django.core.paginator import Paginator
from django.db.models import Q
from django.http import Http404, JsonResponse
from django.shortcuts import redirect
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.templatetags.static import static
from django.urls import reverse
Expand Down Expand Up @@ -842,3 +842,22 @@ def is_verified(tx_details, tx_hash, tx_amount, network):
)

return get_json_response("Wrong request.", 400)


def invoice(request, contribution_pk):
p_contribution = Contribution.objects.prefetch_related('subscription', 'subscription__grant')
contribution = get_object_or_404(p_contribution, pk=contribution_pk)

# only allow invoice viewing if admin or if grant contributor
has_view_privs = request.user.is_staff or request.user.profile == contribution.subscription.contributor_profile

if not has_view_privs:
raise Http404

params = {
'contribution': contribution,
'subscription': contribution.subscription,
'amount_per_period': contribution.subscription.get_converted_monthly_amount()
}

return TemplateResponse(request, 'grants/invoice.html', params)