diff --git a/digitalglarus/migrations/0022_auto_20161023_0218.py b/digitalglarus/migrations/0022_auto_20161023_0218.py new file mode 100644 index 00000000..cc576832 --- /dev/null +++ b/digitalglarus/migrations/0022_auto_20161023_0218.py @@ -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', + ), + ] diff --git a/digitalglarus/models.py b/digitalglarus/models.py index c809a8b5..c1e50308 100644 --- a/digitalglarus/models.py +++ b/digitalglarus/models.py @@ -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 + free_days = cls.get_ramaining_free_days(user, start_date, end_date) - # 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): diff --git a/digitalglarus/templates/digitalglarus/booking_orders_detail.html b/digitalglarus/templates/digitalglarus/booking_orders_detail.html index 006c6568..9dd8a25c 100644 --- a/digitalglarus/templates/digitalglarus/booking_orders_detail.html +++ b/digitalglarus/templates/digitalglarus/booking_orders_detail.html @@ -44,21 +44,17 @@

Total days {{booking_days}}

{{original_price|floatformat}}CHF

- {% if membership_required_months and membership_required_months_price %} -

Required Membership months: {{membership_required_months}}

-

{{membership_required_months_price|floatformat}}CHF

- {% endif %} {% if free_days %}

Free days {{free_days}}

-

-{{total_discount|floatformat}}CHF

+

-{{total_discount|floatformat}}CHF

{% endif %}

Total

{{final_price|floatformat}}CHF


-

- View my bookings Go to my page +

+ View my bookings
Go to my page

@@ -74,13 +70,9 @@

Total days {{booking_days}}

{{original_price|floatformat}}CHF

- {% if membership_required_months and membership_required_months_price %} -

Required Membership months: {{membership_required_months}}

-

{{membership_required_months_price|floatformat}}CHF

- {% endif %} {% if free_days %}

Free days {{free_days}}

-

-{{total_discount|floatformat}}CHF

+

-{{total_discount|floatformat}}CHF

{% endif %}

Total

diff --git a/digitalglarus/templates/digitalglarus/booking_orders_list.html b/digitalglarus/templates/digitalglarus/booking_orders_list.html index 426fcea1..9fa3d793 100644 --- a/digitalglarus/templates/digitalglarus/booking_orders_list.html +++ b/digitalglarus/templates/digitalglarus/booking_orders_list.html @@ -24,7 +24,6 @@ # Booking dates Days - Membership Required Months Invoice @@ -34,7 +33,6 @@ {{order.id}} {{order.booking.start_date}}-{{order.booking.end_date}} {{order.booking_days}} - {{order.membership_required_months}} View {% endfor %} diff --git a/digitalglarus/templates/digitalglarus/booking_payment.html b/digitalglarus/templates/digitalglarus/booking_payment.html index 07a7739f..1b465282 100644 --- a/digitalglarus/templates/digitalglarus/booking_payment.html +++ b/digitalglarus/templates/digitalglarus/booking_payment.html @@ -151,10 +151,6 @@

Total days: {{booking_days}}

{{original_price|floatformat}}CHF

- {% if membership_required_months and membership_required_months_price %} -

Required Membership months: {{membership_required_months}}

-

{{membership_required_months_price|floatformat}}CHF

- {% endif %}
{% if free_days %}

Free days: {{free_days}}

diff --git a/digitalglarus/templates/digitalglarus/membership_deactivated.html b/digitalglarus/templates/digitalglarus/membership_deactivated.html index 0f30a1ba..0ec0295b 100644 --- a/digitalglarus/templates/digitalglarus/membership_deactivated.html +++ b/digitalglarus/templates/digitalglarus/membership_deactivated.html @@ -32,6 +32,7 @@
{% csrf_token %} + Go back @@ -59,7 +60,7 @@

- Your membership wouldn't be automatically renewed each month. Go back + Your membership wouldn't be automatically renewed each month.

diff --git a/digitalglarus/views.py b/digitalglarus/views.py index 08f0daf5..1a901c80 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -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,