'Checks and sets the state of the subscription'

def check_status(self):

    if (not self.active):
        return 'Inactive'
    if self.expiry:
        if (datetime.now() > datetime.combine(self.expiry, time.min)):
            self.deactivate()
            return 'Expired'
    if (not self.cycle_end):
        self.renew()
    cycle_end = self.cycle_end
    if (datetime.now().date() >= cycle_end):
        cycle_start = self.get_cycle_start()
        grace = 3
        if ((datetime.now().date() - cycle_end) > timedelta(days=grace)):
            return self.deactivate()
        try:
            conf = ModuleSetting.get_for_module('treeio.sales', 'order_fulfil_status')[0]
            order_fulfil_status = SaleStatus.objects.get(pk=long(conf.value))
        except Exception:
            order_fulfil_status = None
        if self.orderedproduct_set.filter(order__datetime__gte=cycle_start).filter(order__status=order_fulfil_status):
            return 'Paid'
        elif self.orderedproduct_set.filter(order__datetime__gte=cycle_start):
            return 'Invoiced'
        else:
            self.invoice()
            return 'Invoiced'
    else:
        return 'Active'
