def get(self, request, *args, **kwargs): adapter = Adapter(self.request.user) monthly_spend = adapter.get_monthly_spend() quote = Quote(monthly_adwords_spend=monthly_spend) quote.set_user_details(request.user, commit=False) quote.calculate_quote(commit=False) quote.set_type_automatic(commit=False) quote.save() request.session['quote_pk'] = quote.pk return super().get(request, *args, **kwargs)
def get_payment_amount_required(self, force_recalculate=False): if hasattr(self, '_payment_amount_required') and not force_recalculate: return self._payment_amount_required now = datetime.datetime.now() if now.time() < datetime.time(hour=3): raise TooEarlyError( 'Data is only available for the previous day from 3AM.' ' Please try again later.') adapter = Adapter(self) monthly_spend = adapter.get_monthly_spend() spend_since_last_billed = adapter.get_spend_for_period( self.payment_last_taken_at, now.date()) self._payment_amount_required = (spend_since_last_billed * get_pricing().get_fee(monthly_spend) / 100) print("Step Final") return self._payment_amount_required