def upgrade_plan(member_rental_plan, new_plan): """ Upgrades current plan to ``new_plan``. """ user = member_rental_plan.user amount = get_charge_for_the_rest_of_month(member_rental_plan, new_plan) def invoice_num_func(profile, billing_history): return get_payment_invoice_num( 'rent', 'chng', profile.user.pk, billing_history.pk) take_money( user_or_profile=user, amount=amount, reason='rent', invoice_num_func=invoice_num_func, description="Change Rental Plan", ) member_rental_plan.delete() new_mrp = MemberRentalPlan.objects.create( user=user, plan=new_plan.pk, status=RentalPlanStatus.Active, start_date=datetime.date.today(), ) new_mrp.next_payment_date, new_mrp.next_payment_amount, _ = \ new_mrp.rental_plan.get_next_payment(member_rental_plan.start_date) new_mrp.save() return new_mrp
def test_take_money(self): plan = RentalPlan.objects.get(slug="unlimited1") self.signup_plan(plan) profile = Profile.objects.all()[0] profile.bonus_store_credits = 5 profile.store_credits = 5 profile.save() def invoice_num_func(profile, billing_history): return get_payment_invoice_num( 'rent', 'new', profile.user.pk, billing_history.pk) take_money(user_or_profile=profile, amount=10, reason='rent', invoice_num_func=invoice_num_func, description='desc') bhi = BillingHistory.objects.all()[0] self.assertEqual(bhi.applied_credits, 5) self.assertEqual(bhi.debit, 5) self.assertEqual(bhi.aim_response['amount'], '5.0')