From 613b8d1b88815754bafec1d0f7c56b84130962a5 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 30 Mar 2017 19:26:32 +0300 Subject: [PATCH] license: always call check_one_profile on license save --- project/customer/models.py | 11 +++++------ project/customer/utils.py | 1 + project/myauth/views.py | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/project/customer/models.py b/project/customer/models.py index bb63013..4802697 100644 --- a/project/customer/models.py +++ b/project/customer/models.py @@ -445,25 +445,24 @@ 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'] - now_ = datetime.now() 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.company.active = True - self.company.save() - self.status = consts.LICENSE_PAID - utils.check_one_profile(self.company, License, now_, manual=True) - super(License, self).save(*args, **kwargs) + # дополнительные действия, связанные с сохранением лицензии + utils.check_one_profile(self.company, License, now_, manual=True) + def set_paid(self, paid_date=None): self.paid_date = paid_date or date.today() self.status = consts.LICENSE_PAID diff --git a/project/customer/utils.py b/project/customer/utils.py index d1231c4..4f1b4ed 100644 --- a/project/customer/utils.py +++ b/project/customer/utils.py @@ -27,6 +27,7 @@ def check_one_profile(profile, License, now_, manual=False): user_email = profile.users.get().email + # если профиль только что активирован if profile.active and not profile_was_active: template_name = 'myauth/license_activated.txt' subject = u'Документор: Профиль активирован' diff --git a/project/myauth/views.py b/project/myauth/views.py index be50c3b..5c5ecdb 100644 --- a/project/myauth/views.py +++ b/project/myauth/views.py @@ -99,7 +99,6 @@ def confirm_registered_email(request, key): license = License.objects.create_test_period_license(company=user.profile) emails.send_welcome_email.delay(new_user.email, confirm_url) user.profile.confirmed = True - user.profile.active = True user.profile.save() auth.logout(request)