Skip to content

Commit

Permalink
add information about the end date of plan into Order
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Sep 1, 2018
1 parent 5cf0c42 commit 5fdecd1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
23 changes: 23 additions & 0 deletions plans/migrations/0002_auto_20180901_1744.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.0.8 on 2018-09-01 15:44

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('plans', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='order',
name='plan_extended_from',
field=models.DateField(blank=True, null=True, verbose_name='The plan was extended from this date'),
),
migrations.AddField(
model_name='order',
name='plan_extended_until',
field=models.DateField(blank=True, null=True, verbose_name='The plan was extended until this date'),
),
]
12 changes: 12 additions & 0 deletions plans/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,16 @@ class Order(models.Model):
created = models.DateTimeField(_('created'), db_index=True)
completed = models.DateTimeField(
_('completed'), null=True, blank=True, db_index=True)
plan_extended_from = models.DateField(
_('The plan was extended from this date'),
null=True,
blank=True,
)
plan_extended_until = models.DateField(
_('The plan was extended until this date'),
null=True,
blank=True,
)
amount = models.DecimalField(
_('amount'), max_digits=7, decimal_places=2, db_index=True)
tax = models.DecimalField(_('tax'), max_digits=4, decimal_places=2, db_index=True, null=True,
Expand Down Expand Up @@ -467,7 +477,9 @@ def is_ready_for_payment(self):

def complete_order(self):
if self.completed is None:
self.plan_extended_from = self.user.userplan.expire
status = self.user.userplan.extend_account(self.plan, self.pricing)
self.plan_extended_until = self.user.userplan.expire
self.completed = now()
if status:
self.status = Order.STATUS.COMPLETED
Expand Down
6 changes: 6 additions & 0 deletions plans/templates/plans/order_detail_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
<th>{% trans "VAT" %}</th>
<th>{% trans "VAT total" %}</th>
<th>{% trans "Total" %}</th>
<th>{% trans "Order completed" %}</th>
<th>{% trans "Plan valid from" %}</th>
<th>{% trans "Plan valid until" %}</th>
</thead>
<tbody>
<td>{{ order.name }}</td>
<td>{{ order.amount }} {{ order.currency }}</td>
<td>{% ifequal order.tax None %}n/a{% else %}{{ order.tax }} %{% endifequal %}</td>
<td>{% ifequal order.tax_total None %}n/a{% else %}{{ order.tax_total }} {{ order.currency }}{% endifequal %}</td>
<td class="number total">{{ order.total }} {{ order.currency }}</td>
<td class="date">{{ order.completed|date|default:"-" }}</td>
<td class="date">{{ order.plan_extended_from|date|default:"-" }}</td>
<td class="date">{{ order.plan_extended_until|date|default:"-" }}</td>
</tbody>
</table>

Expand Down
4 changes: 4 additions & 0 deletions plans/templates/plans/order_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ <h1>{% trans "List of orders" %}</h1>
<th>{% trans 'Status' context 'order status' %}</th>
<th>{% trans 'Completed' context 'order completed' %}</th>
<th>{% trans 'Total' context 'total amount, value' %}</th>
<th>{% trans 'Plan valid from' %}</th>
<th>{% trans 'Plan valid until' %}</th>
</tr>
</thead>
<tbody>
Expand All @@ -28,6 +30,8 @@ <h1>{% trans "List of orders" %}</h1>
<td class="status">{{ order.get_status_display }}</td>
<td class="date">{{ order.completed|date|default:"-" }}</td>
<td class="number">{{ order.total }}&nbsp;{{ CURRENCY }}</td>
<td class="date">{{ order.plan_extended_from|date|default:"-" }}</td>
<td class="date">{{ order.plan_extended_until|date|default:"-" }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit 5fdecd1

Please sign in to comment.