diff --git a/abonapp/locale/ru/LC_MESSAGES/django.po b/abonapp/locale/ru/LC_MESSAGES/django.po index 9e89ca2..cc058bc 100644 --- a/abonapp/locale/ru/LC_MESSAGES/django.po +++ b/abonapp/locale/ru/LC_MESSAGES/django.po @@ -1153,3 +1153,6 @@ msgstr "Отмена" msgid "View" msgstr "Открыть" + +msgid "Auto continue service." +msgstr "Автопродление услуги." diff --git a/abonapp/migrations/0004_auto_20180918_1734.py b/abonapp/migrations/0004_auto_20180918_1734.py new file mode 100644 index 0000000..cf7bba3 --- /dev/null +++ b/abonapp/migrations/0004_auto_20180918_1734.py @@ -0,0 +1,44 @@ +# Generated by Django 2.1 on 2018-09-18 17:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('abonapp', '0003_abon_nas'), + ] + + operations = [ + migrations.AlterModelOptions( + name='abon', + options={'ordering': ('fio',), 'permissions': (('can_buy_tariff', 'Buy service perm'), ('can_add_ballance', 'fill account'), ('can_ping', 'Can ping')), 'verbose_name': 'Abon', 'verbose_name_plural': 'Abons'}, + ), + migrations.AlterModelOptions( + name='abonlog', + options={'ordering': ('-date',)}, + ), + migrations.AlterModelOptions( + name='additionaltelephone', + options={'ordering': ('owner_name',), 'verbose_name': 'Additional telephone', 'verbose_name_plural': 'Additional telephones'}, + ), + migrations.AlterModelOptions( + name='invoiceforpayment', + options={'ordering': ('date_create',), 'verbose_name': 'Debt', 'verbose_name_plural': 'Debts'}, + ), + migrations.AddField( + model_name='abon', + name='autoconnect_service', + field=models.BooleanField(default=False, verbose_name='Automatically connect next service'), + ), + migrations.AlterField( + model_name='abon', + name='is_dynamic_ip', + field=models.BooleanField(default=False, verbose_name='Is dynamic ip'), + ), + migrations.AlterField( + model_name='passportinfo', + name='date_of_acceptance', + field=models.DateField(verbose_name='Date of acceptance'), + ), + ] diff --git a/abonapp/models.py b/abonapp/models.py index 00cfb73..71e5c7d 100644 --- a/abonapp/models.py +++ b/abonapp/models.py @@ -6,7 +6,7 @@ from django.conf import settings from django.core import validators from django.core.validators import RegexValidator from django.db import models, connection, transaction -from django.db.models.signals import post_delete, pre_delete, post_init +from django.db.models.signals import post_delete, pre_delete, post_init, pre_save from django.dispatch import receiver from django.shortcuts import resolve_url from django.utils import timezone @@ -87,7 +87,7 @@ class AbonManager(MyUserManager): class Abon(BaseAccount): - current_tariff = models.ForeignKey(AbonTariff, null=True, blank=True, on_delete=models.SET_NULL) + current_tariff = models.OneToOneField(AbonTariff, null=True, blank=True, on_delete=models.SET_NULL) group = models.ForeignKey(Group, on_delete=models.SET_NULL, blank=True, null=True, verbose_name=_('User group')) ballance = models.FloatField(default=0.0) ip_addresses = models.ManyToManyField(IpLeaseModel, verbose_name=_('Ip addresses')) @@ -96,9 +96,10 @@ class Abon(BaseAccount): house = models.CharField(_('House'), max_length=12, null=True, blank=True) device = models.ForeignKey('devapp.Device', null=True, blank=True, on_delete=models.SET_NULL) dev_port = models.ForeignKey('devapp.Port', null=True, blank=True, on_delete=models.SET_NULL) - is_dynamic_ip = models.BooleanField(default=False) + is_dynamic_ip = models.BooleanField(_('Is dynamic ip'), default=False) nas = models.ForeignKey('nas_app.NASModel', null=True, blank=True, on_delete=models.SET_NULL, verbose_name=_('Network access server'), default=None) + autoconnect_service = models.BooleanField(_('Automatically connect next service'), default=False) MARKER_FLAGS = ( ('icon_donkey', _('Donkey')), @@ -148,7 +149,16 @@ class Abon(BaseAccount): ) self.ballance += amount - def pick_tariff(self, tariff, author, comment=None, deadline=None): + def pick_tariff(self, tariff, author, comment=None, deadline=None) -> None: + """ + Trying to buy a service if enough money. + :param tariff: instance of tariff_app.models.Tariff. + :param author: Instance of accounts_app.models.UserProfile. Who connected this + service. May be None if author is a system. + :param comment: Optional text for logging this pay. + :param deadline: Instance of datetime.datetime. Date when service is expired. + :return: Nothing + """ if not isinstance(tariff, Tariff): raise TypeError @@ -170,22 +180,23 @@ class Abon(BaseAccount): if self.ballance < amount: raise LogicError(_('not enough money')) - new_abtar = AbonTariff.objects.create( - deadline=deadline, tariff=tariff - ) - self.current_tariff = new_abtar + with transaction.atomic(): + new_abtar = AbonTariff.objects.create( + deadline=deadline, tariff=tariff + ) + self.current_tariff = new_abtar - # charge for the service - self.ballance -= amount + # charge for the service + self.ballance -= amount - self.save() + self.save(update_fields=('ballance', 'current_tariff')) - # make log about it - AbonLog.objects.create( - abon=self, amount=-tariff.amount, - author=author, - comment=comment or _('Buy service default log') - ) + # make log about it + AbonLog.objects.create( + abon=self, amount=-tariff.amount, + author=author, + comment=comment or _('Buy service default log') + ) # Destroy the service if the time has come # def bill_service(self, author): @@ -468,8 +479,16 @@ def abon_tariff_post_init(sender, **kwargs): abon_tariff = kwargs["instance"] if getattr(abon_tariff, 'time_start') is None: abon_tariff.time_start = timezone.now() - calc_obj = abon_tariff.tariff.get_calc_type()(abon_tariff) if getattr(abon_tariff, 'deadline') is None: + calc_obj = abon_tariff.tariff.get_calc_type()(abon_tariff) + abon_tariff.deadline = calc_obj.calc_deadline() + + +@receiver(pre_save, sender=AbonTariff) +def abon_tariff_pre_save(sender, **kwargs): + abon_tariff = kwargs["instance"] + if getattr(abon_tariff, 'deadline') is None: + calc_obj = abon_tariff.tariff.get_calc_type()(abon_tariff) abon_tariff.deadline = calc_obj.calc_deadline() diff --git a/abonapp/templates/abonapp/service.html b/abonapp/templates/abonapp/service.html index 3774ddf..a00c3bd 100644 --- a/abonapp/templates/abonapp/service.html +++ b/abonapp/templates/abonapp/service.html @@ -3,6 +3,58 @@ {% block content %}
| {% trans 'Pick a service' %} | +{% trans 'Service' %} | +{% trans 'Price' %} | +{% trans 'Speed In' %} | +{% trans 'Speed Out' %} | +
|---|---|---|---|---|
| + + | ++ {% if can_ch_trf %} + {{ service.title }} + {% else %} + {{ service.title }} + {% endif %} + | +{{ service.amount }} {% trans 'currency' %} | +{{ service.speedIn }} | +{{ service.speedOut }} | +
| + {% trans 'This group has no services' %} + + {% trans 'Tariffs in groups' %} + + | ||||
+@@ -68,58 +124,6 @@+ {% trans 'Auto continue service.' %} + +
{{ abon_tariff.tariff.descr }}
| {% trans 'Pick a service' %} | -{% trans 'Service' %} | -{% trans 'Price' %} | -{% trans 'Speed In' %} | -{% trans 'Speed Out' %} | -
|---|---|---|---|---|
| - - | -- {% if can_ch_trf %} - {{ service.title }} - {% else %} - {{ service.title }} - {% endif %} - | -{{ service.amount }} {% trans 'currency' %} | -{{ service.speedIn }} | -{{ service.speedOut }} | -
| - {% trans 'This group has no services' %} - - {% trans 'Tariffs in groups' %} - - | ||||
If you do not have time to make a Deposit before the service " +"ended, replenish your account and log back into your personal account to " +"connect it.
" +msgstr "" +"Флажок Автопрдление услуги предназначен для того чтоб в следующем " +"месяце автоматически подключилась услуга которая была у вас в прошлом " +"месяце. Подключение произойдёт если на счету достаточно средств.
Если " +"вы не успели внести средства до того как закочилась услуга, пополните счёт и " +"снова войдите в личный кабинет чтоб подключить её.
" + +#: templates/clientsideapp/services.html:46 msgid "" "Attantion! You have not yet a service, for use the services " "please purchase service you want." @@ -254,27 +275,27 @@ msgstr "" "Внимание! У вас нет услуги, для использования ресурсов " "приобретите нужную услугу из представленных тут." -#: templates/clientsideapp/services.html:46 +#: templates/clientsideapp/services.html:57 msgid "Services available for ordering" msgstr "Доступные для заказа услуги" -#: templates/clientsideapp/services.html:68 +#: templates/clientsideapp/services.html:79 msgid "No services available for ordering" msgstr "Нет доступных для заказа услуг" -#: templates/clientsideapp/tasklist.html:7 +#: templates/clientsideapp/tasklist.html:6 msgid "Task history" msgstr "История заявок" -#: templates/clientsideapp/tasklist.html:16 +#: templates/clientsideapp/tasklist.html:15 msgid "The nature of the damage" msgstr "Характер заявки" -#: templates/clientsideapp/tasklist.html:17 +#: templates/clientsideapp/tasklist.html:16 msgid "Expected or real completion date" msgstr "Ожидаемый или реальный срок выполнения" -#: templates/clientsideapp/tasklist.html:43 +#: templates/clientsideapp/tasklist.html:42 msgid "You didn't leave any requests for breakdowns." msgstr "Заявки по вашей учётной записи не найдены" diff --git a/clientsideapp/templates/clientsideapp/services.html b/clientsideapp/templates/clientsideapp/services.html index 45abb0d..265999b 100644 --- a/clientsideapp/templates/clientsideapp/services.html +++ b/clientsideapp/templates/clientsideapp/services.html @@ -24,8 +24,19 @@{{ current_service.tariff.descr }}
+ {% blocktrans trimmed %} + The check box Auto continue service for auto-renewal service + is designed so that the following automatically connected to the service + that you had last month. Connection will occur if the account has enough funds. +If you do not have time to make a Deposit before the service ended, + replenish your account and log back into your personal account to connect it.
+ {% endblocktrans %} diff --git a/clientsideapp/urls.py b/clientsideapp/urls.py index fa6fa18..10ec57a 100644 --- a/clientsideapp/urls.py +++ b/clientsideapp/urls.py @@ -10,5 +10,6 @@ urlpatterns = [ path('services/