Delete required membership months from booking view. Delete required membership months from booking order view. Delete required membership moths from booking order model. Fixed error on membership date range on order detail.Fixed #2650. Fixed #2652. Checked #2658
This commit is contained in:
parent
35bd78a78b
commit
08d1077ad0
7 changed files with 37 additions and 131 deletions
23
digitalglarus/migrations/0022_auto_20161023_0218.py
Normal file
23
digitalglarus/migrations/0022_auto_20161023_0218.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.4 on 2016-10-23 02:18
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('digitalglarus', '0021_auto_20161017_1958'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='bookingorder',
|
||||
name='membership_required_months',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='bookingorder',
|
||||
name='membership_required_months_price',
|
||||
),
|
||||
]
|
|
@ -128,12 +128,7 @@ class MembershipOrder(Ordereable, models.Model):
|
|||
}
|
||||
|
||||
def get_membership_range_date(self):
|
||||
start_date = self.created_at
|
||||
_, days_in_month = calendar.monthrange(start_date.year,
|
||||
start_date.month)
|
||||
start_date.replace(day=1)
|
||||
end_date = start_date + timedelta(days=days_in_month)
|
||||
return start_date, end_date
|
||||
return self.start_date, self.end_date
|
||||
|
||||
@classmethod
|
||||
def create(cls, data):
|
||||
|
@ -183,18 +178,9 @@ class Booking(models.Model):
|
|||
total_free_days = months * TWO_DAYS + free_days_this_month
|
||||
return total_free_days
|
||||
|
||||
@staticmethod
|
||||
def membership_required_booking_months(start_date, end_date):
|
||||
start_month = start_date.month
|
||||
end_month = end_date.month
|
||||
months = abs(start_month - (end_month + 12) if end_month < start_month
|
||||
else end_month - start_month)
|
||||
return months
|
||||
|
||||
@classmethod
|
||||
def booking_price(cls, user, start_date, end_date):
|
||||
|
||||
TWO_DAYS = 2
|
||||
MAX_MONTH_PRICE = BookingPrice.objects.last().special_month_price
|
||||
MAX_MONTH_DAYS_PROMOTION = 31
|
||||
MIN_MONTH_DAYS_PROMOTION = 19
|
||||
|
@ -209,36 +195,17 @@ class Booking(models.Model):
|
|||
if remanent_days <= MIN_MONTH_DAYS_PROMOTION else MAX_MONTH_PRICE
|
||||
normal_price = months_prices + remanent_days_price
|
||||
|
||||
# Calculating membership required months price for booking
|
||||
required_membership_months = 0
|
||||
membership_booking_price = 0.0
|
||||
# if not BookingOrder.user_has_not_bookings(user):
|
||||
today = datetime.today().date()
|
||||
membership_price = MembershipType.objects.get(name=MembershipType.STANDARD).price
|
||||
required_membership_months = cls.membership_required_booking_months(today, end_date)
|
||||
membership_booking_price = membership_price * required_membership_months
|
||||
|
||||
# TO-DO Fix this, what happens when user has free days from his current membership month
|
||||
if not required_membership_months:
|
||||
free_days = cls.get_ramaining_free_days(user, start_date, end_date)
|
||||
else:
|
||||
free_days = required_membership_months * TWO_DAYS
|
||||
# free_days += free_days_for_required_memberships
|
||||
|
||||
final_booking_price = normal_price - (free_days * price_per_day)
|
||||
|
||||
# Add required membership months to final prices
|
||||
final_booking_price += membership_booking_price
|
||||
|
||||
return normal_price, final_booking_price, free_days,\
|
||||
required_membership_months, membership_booking_price
|
||||
return normal_price, final_booking_price, free_days
|
||||
|
||||
|
||||
class BookingOrder(Ordereable, models.Model):
|
||||
booking = models.OneToOneField(Booking)
|
||||
original_price = models.FloatField()
|
||||
special_month_price = models.FloatField()
|
||||
membership_required_months = models.IntegerField(default=0)
|
||||
membership_required_months_price = models.FloatField(default=0)
|
||||
|
||||
@classmethod
|
||||
def user_has_not_bookings(cls, user):
|
||||
|
|
|
@ -44,21 +44,17 @@
|
|||
</h2>
|
||||
<h2 class="col-xs-6 payment-total text-left">Total days {{booking_days}}</h2>
|
||||
<h2 class="order-sum">{{original_price|floatformat}}CHF</h2>
|
||||
{% if membership_required_months and membership_required_months_price %}
|
||||
<h2 class="col-xs-6 payment-total text-left">Required Membership months: {{membership_required_months}}</h2>
|
||||
<h2 class="order-sum"><span>{{membership_required_months_price|floatformat}}CHF</span></h2>
|
||||
{% endif %}
|
||||
{% if free_days %}
|
||||
<h2 class="col-xs-6 payment-total text-left">Free days {{free_days}} </h2>
|
||||
<h2 class="order-sum">-{{total_discount|floatformat}}CHF</h2>
|
||||
<h2 class="order-sum text-danger">-{{total_discount|floatformat}}CHF</h2>
|
||||
{% endif %}
|
||||
<hr class="greyline-long">
|
||||
<h2 class="col-xs-6 payment-total text-left"> Total</h2>
|
||||
<h2 class="order-result">{{final_price|floatformat}}CHF</h2>
|
||||
<br>
|
||||
|
||||
<p class="order-bottom-text">
|
||||
View my bookings <a href="{% url 'digitalglarus:booking_orders_list' %}">Go to my page</a>
|
||||
<p class="">
|
||||
View my bookings <br/><a class="btn btn-primary btn-sm btn-blck " href="{% url 'digitalglarus:booking_orders_list' %}">Go to my page</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
@ -74,13 +70,9 @@
|
|||
|
||||
<h2 class="col-xs-6 payment-total">Total days {{booking_days}}</h2>
|
||||
<h2 class="order-sum">{{original_price|floatformat}}CHF</h2>
|
||||
{% if membership_required_months and membership_required_months_price %}
|
||||
<h2 class="col-xs-6 payment-total">Required Membership months: {{membership_required_months}}</h2>
|
||||
<h2 class="order-sum"><span>{{membership_required_months_price|floatformat}}CHF</span></h2>
|
||||
{% endif %}
|
||||
{% if free_days %}
|
||||
<h2 class="col-xs-6 payment-total">Free days {{free_days}}</h2>
|
||||
<h2 class="order-sum">-{{total_discount|floatformat}}CHF</h2>
|
||||
<h2 class="order-sum text-danger">-{{total_discount|floatformat}}CHF</h2>
|
||||
{% endif %}
|
||||
<hr class="greyline">
|
||||
<h2 class="col-xs-6 payment-total">Total</h2>
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
<th>#</th>
|
||||
<th>Booking dates</th>
|
||||
<th>Days</th>
|
||||
<th>Membership Required Months</th>
|
||||
<th>Invoice</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -34,7 +33,6 @@
|
|||
<th scope="row">{{order.id}}</th>
|
||||
<td>{{order.booking.start_date}}-{{order.booking.end_date}}</td>
|
||||
<td>{{order.booking_days}}</td>
|
||||
<td>{{order.membership_required_months}}</td>
|
||||
<td><a class="btn btn-xs btn-primary btn-darkgrey" href="{% url 'digitalglarus:booking_orders_detail' order.id %}">View</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
@ -151,10 +151,6 @@
|
|||
<hr class="greyline">
|
||||
<h2 class="col-xs-6 payment-total">Total days: {{booking_days}} </h2>
|
||||
<h2 class="order-sum">{{original_price|floatformat}}CHF</h2>
|
||||
{% if membership_required_months and membership_required_months_price %}
|
||||
<h2 class="col-xs-6 payment-total">Required Membership months: {{membership_required_months}}</h2>
|
||||
<h2 class="order-sum"><span>{{membership_required_months_price|floatformat}}CHF</span></h2>
|
||||
{% endif %}
|
||||
<br/>
|
||||
{% if free_days %}
|
||||
<h2 class="col-xs-6 payment-total">Free days: {{free_days}}</h2>
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
<form method="POST" action="">
|
||||
{% csrf_token %}
|
||||
<button type="button" class="btn btn-primary btn-blue" data-toggle="modal" data-target="#cancel-subscription-modal">Cancel my Membership</button>
|
||||
<a class="btn btn-primary btn-blue" href="{{request.META.HTTP_REFERER}}">Go back</a>
|
||||
|
||||
|
||||
|
||||
|
@ -59,7 +60,7 @@
|
|||
</div>
|
||||
<div class="notice-box text-left">
|
||||
<p class="order-bottom-text">
|
||||
Your membership wouldn't be automatically renewed each month. <a href="{{request.META.HTTP_REFERER}}">Go back</a>
|
||||
Your membership wouldn't be automatically renewed each month.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -109,8 +109,7 @@ class BookingSelectDatesView(LoginRequiredMixin, MembershipRequiredMixin, FormVi
|
|||
|
||||
price_per_day = BookingPrice.objects.get().price_per_day
|
||||
|
||||
original_price, final_price, free_days,\
|
||||
membership_required_months, membership_required_months_price = Booking.\
|
||||
original_price, final_price, free_days = Booking.\
|
||||
booking_price(user, start_date, end_date)
|
||||
|
||||
total_discount = price_per_day * free_days
|
||||
|
@ -119,8 +118,6 @@ class BookingSelectDatesView(LoginRequiredMixin, MembershipRequiredMixin, FormVi
|
|||
'original_price': original_price,
|
||||
'final_price': final_price,
|
||||
'total_discount': total_discount,
|
||||
'membership_required_months_price': membership_required_months_price,
|
||||
'membership_required_months': membership_required_months,
|
||||
'booking_price_per_day': price_per_day,
|
||||
'booking_days': booking_days,
|
||||
'free_days': free_days,
|
||||
|
@ -137,8 +134,7 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
|
|||
membership_redirect_url = reverse_lazy('digitalglarus:membership_pricing')
|
||||
# success_url = reverse_lazy('digitalglarus:booking_payment')
|
||||
booking_needed_fields = ['original_price', 'final_price', 'booking_days', 'free_days',
|
||||
'start_date', 'end_date', 'membership_required_months_price',
|
||||
'membership_required_months', 'booking_price_per_day',
|
||||
'start_date', 'end_date', 'booking_price_per_day',
|
||||
'total_discount', 'is_free']
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
|
@ -179,11 +175,8 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
|
|||
credit_card_data = last_booking_order.get_booking_cc_data() if last_booking_order \
|
||||
and last_booking_order.get_booking_cc_data() \
|
||||
else last_membership_order.get_membership_order_cc_data()
|
||||
# booking_price_per_day = BookingPrice.objects.get().price_per_day
|
||||
# total_discount = booking_price_per_day * booking_data.get('free_days')
|
||||
|
||||
booking_data.update({
|
||||
# 'booking_price_per_day': booking_price_per_day,
|
||||
# 'current_billing_address': self.request.user.billing_addresses.first().to_dict(),
|
||||
'credit_card_data': credit_card_data if credit_card_data else None,
|
||||
'stripe_key': settings.STRIPE_API_PUBLIC_KEY
|
||||
})
|
||||
|
@ -197,9 +190,9 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
|
|||
start_date = data.get('start_date')
|
||||
end_date = data.get('end_date')
|
||||
is_free = context.get('is_free')
|
||||
normal_price, final_price, free_days, membership_required_months,\
|
||||
membership_required_months_price = Booking.\
|
||||
normal_price, final_price, free_days = Booking.\
|
||||
booking_price(self.request.user, start_date, end_date)
|
||||
charge = None
|
||||
|
||||
# if not credit_card_needed:
|
||||
# Get or create stripe customer
|
||||
|
@ -209,44 +202,6 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
|
|||
form.add_error("__all__", "Invalid credit card")
|
||||
return self.render_to_response(self.get_context_data(form=form))
|
||||
|
||||
# if is_free:
|
||||
# billing_address = form.save()
|
||||
|
||||
# # Create Billing Address for User if he does not have one
|
||||
# if not customer.user.billing_addresses.count():
|
||||
# data.update({
|
||||
# 'user': customer.user.id
|
||||
# })
|
||||
# billing_address_user_form = UserBillingAddressForm(data)
|
||||
# billing_address_user_form.is_valid()
|
||||
# billing_address_user_form.save()
|
||||
|
||||
# # Create membership plan
|
||||
# booking_data = {
|
||||
# 'start_date': start_date,
|
||||
# 'end_date': end_date,
|
||||
# 'start_date': start_date,
|
||||
# 'free_days': free_days,
|
||||
# 'price': normal_price,
|
||||
# 'final_price': final_price,
|
||||
# }
|
||||
# booking = Booking.create(booking_data)
|
||||
|
||||
# # Create membership order
|
||||
# order_data = {
|
||||
# 'booking': booking,
|
||||
# 'customer': customer,
|
||||
# 'billing_address': billing_address,
|
||||
# 'amount': final_price,
|
||||
# 'original_price': normal_price,
|
||||
# 'special_month_price': BookingPrice.objects.last().special_month_price,
|
||||
# 'membership_required_months': membership_required_months,
|
||||
# 'membership_required_months_price': membership_required_months_price,
|
||||
# }
|
||||
# order = BookingOrder.create(order_data)
|
||||
|
||||
# return HttpResponseRedirect(self.get_success_url(order.id))
|
||||
|
||||
# If booking is not free, make the stripe charge
|
||||
if not is_free:
|
||||
# Make stripe charge to a customer
|
||||
|
@ -268,24 +223,6 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
|
|||
# Create Billing Address for Membership Order
|
||||
billing_address = form.save()
|
||||
|
||||
# Check if user had to pay membership months in advaced
|
||||
# if membership_required_months:
|
||||
|
||||
# # Get current user membership
|
||||
# membership = Membership.get_by_user(self.request.user)
|
||||
|
||||
# # Create membership order
|
||||
# order_data = {
|
||||
# 'membership': membership,
|
||||
# 'customer': customer,
|
||||
# 'billing_address': billing_address,
|
||||
# 'amount': membership_required_months_price,
|
||||
# 'start_date': start_date,
|
||||
# 'end_date': end_date
|
||||
# }
|
||||
|
||||
# MembershipOrder.create(order_data)
|
||||
|
||||
# Create Billing Address for User if he does not have one
|
||||
if not customer.user.billing_addresses.count():
|
||||
data.update({
|
||||
|
@ -315,8 +252,6 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
|
|||
'amount': final_price,
|
||||
'original_price': normal_price,
|
||||
'special_month_price': BookingPrice.objects.last().special_month_price,
|
||||
'membership_required_months': membership_required_months,
|
||||
'membership_required_months_price': membership_required_months_price,
|
||||
}
|
||||
order = BookingOrder.create(order_data)
|
||||
|
||||
|
@ -607,15 +542,9 @@ class OrdersBookingDetailView(LoginRequiredMixin, DetailView):
|
|||
original_price = booking.price
|
||||
final_price = booking.final_price
|
||||
|
||||
membership_required_months = bookig_order.membership_required_months
|
||||
membership_required_months_price = bookig_order.membership_required_months_price
|
||||
original_price += membership_required_months_price
|
||||
|
||||
context.update({
|
||||
'original_price': original_price,
|
||||
'total_discount': original_price - final_price,
|
||||
'membership_required_months': membership_required_months,
|
||||
'membership_required_months_price': membership_required_months_price,
|
||||
'final_price': final_price,
|
||||
'booking_days': booking_days,
|
||||
'free_days': free_days,
|
||||
|
|
Loading…
Reference in a new issue