Unsupported operand type(s) for +: 'NoneType' and 'datetime.timedelta'

I'm getting the above error while executing the following method in my django rest framework project (Django==5.0.4, djangorestframework==3.16.1).

    def activate(
    self,
    subscription_date=None,
    mark_transaction_paid=True,
    no_multiple_subscription=False,
    del_multiple_subscription=False,
):
    if no_multiple_subscription:
        self.deactivate_previous_subscriptions(del_multiple_subscription=del_multiple_subscription)
    current_date = subscription_date or timezone.now()
    next_billing_date = self.plan_cost.next_billing_datetime(current_date)
    self.active = True
    self.cancelled = False
    self.due = False
    self.date_billing_start = current_date
    self.date_billing_end = next_billing_date + timedelta(days=self.plan_cost.plan.grace_period) 
    self.date_billing_next = next_billing_date
    self._add_user_to_group()
    if mark_transaction_paid:
        self.transactions.update(paid=True)
    self.save()

The trace points to this line in the above method:

self.date_billing_end = next_billing_date + timedelta(days=self.plan_cost.plan.grace_period) 

What I've tried :

changed 
current_date = subscription_date or timezone.now() to
current_date = subscription_date or datetime.now()

I'm currently setting up the following package for subscription plan in my Django Saas project

https://github.com/ydaniels/drf-django-flexible-subscriptions/tree/master

The file in the above project where the issue is

https://github.com/ydaniels/drf-django-flexible-subscriptions/blob/master/subscriptions_api/base_models.py

Вернуться на верх