|
|
|
|
@ -447,22 +447,38 @@ class License(models.Model): |
|
|
|
|
def save(self, *args, **kwargs): |
|
|
|
|
now_ = datetime.now() |
|
|
|
|
|
|
|
|
|
if not self.__prev_paid_date and self.paid_date: |
|
|
|
|
max_date_license = License.objects.filter(company=self.company).aggregate(Max('date_to'))['date_to__max'] |
|
|
|
|
|
|
|
|
|
if max_date_license < now_.date(): |
|
|
|
|
max_date_license = now_.date() - timedelta(days=1) |
|
|
|
|
|
|
|
|
|
self.date_from = max_date_license + relativedelta(days=1) |
|
|
|
|
self.date_to = self.date_from + relativedelta(months=self.term, days=-1) |
|
|
|
|
|
|
|
|
|
self.status = consts.LICENSE_PAID |
|
|
|
|
# бесплатные лицензии |
|
|
|
|
if self.payform in [consts.PAYFORM_FREE,]: |
|
|
|
|
# только если ещё не задана `дата начала` |
|
|
|
|
if not self.date_from: |
|
|
|
|
self.set_period(now_) |
|
|
|
|
|
|
|
|
|
# платные лицензии |
|
|
|
|
elif self.payform in [consts.PAYFORM_BEZNAL, consts.PAYFORM_CARD,]: |
|
|
|
|
# если `дата оплаты` задана только что |
|
|
|
|
if not self.__prev_paid_date and self.paid_date: |
|
|
|
|
self.set_period(now_) |
|
|
|
|
self.status = consts.LICENSE_PAID |
|
|
|
|
|
|
|
|
|
super(License, self).save(*args, **kwargs) |
|
|
|
|
|
|
|
|
|
# дополнительные действия, связанные с сохранением лицензии |
|
|
|
|
utils.check_one_profile(self.company, License, now_, manual=True) |
|
|
|
|
|
|
|
|
|
def set_period(self, now_): |
|
|
|
|
max_date_license = License.objects.filter(company=self.company).aggregate(Max('date_to'))['date_to__max'] |
|
|
|
|
|
|
|
|
|
if max_date_license < now_.date(): |
|
|
|
|
max_date_license = now_.date() - timedelta(days=1) |
|
|
|
|
|
|
|
|
|
self.date_from = max_date_license + relativedelta(days=1) |
|
|
|
|
|
|
|
|
|
if self.term == consts.LICENSE_TEST_PERIOD_TERM: |
|
|
|
|
# это для админки. иначе использовать License.objects.create_test_period_license |
|
|
|
|
self.date_to = self.date_from + relativedelta(days = consts.LICENSE_TEST_PERIOD_DAYS - 1) |
|
|
|
|
else: |
|
|
|
|
self.date_to = self.date_from + relativedelta(months=self.term, days=-1) |
|
|
|
|
|
|
|
|
|
def set_paid(self): |
|
|
|
|
self.status = consts.LICENSE_PAID |
|
|
|
|
|
|
|
|
|
|