diff --git a/archilance/settings/base.py b/archilance/settings/base.py index 9b25660..0600cb5 100644 --- a/archilance/settings/base.py +++ b/archilance/settings/base.py @@ -111,7 +111,7 @@ WSGI_APPLICATION = 'archilance.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'archilance', + 'NAME': 'archilance2', 'USER': 'postgres', 'PASSWORD': 'postgres', 'HOST': 'localhost', diff --git a/chat/testapp.py b/chat/testapp.py index fe64028..0922d45 100644 --- a/chat/testapp.py +++ b/chat/testapp.py @@ -92,7 +92,7 @@ if __name__ == '__main__': ioloop = IOLoop.instance() application.db = momoko.Pool( - dsn='dbname=archilance user=postgres password=postgres host=localhost', + dsn='dbname=archilance2 user=postgres password=postgres host=localhost', size=1, ioloop=ioloop, ) diff --git a/common/migrations/0005_settings_accountant_send_email.py b/common/migrations/0005_settings_accountant_send_email.py new file mode 100644 index 0000000..01ac195 --- /dev/null +++ b/common/migrations/0005_settings_accountant_send_email.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-08-09 16:56 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0004_auto_20160808_1557'), + ] + + operations = [ + migrations.AddField( + model_name='settings', + name='accountant_send_email', + field=models.EmailField(default='muhtarzubanchi05@gmail.com', max_length=100), + ), + ] diff --git a/common/models.py b/common/models.py index 6557b55..e05368f 100644 --- a/common/models.py +++ b/common/models.py @@ -38,6 +38,7 @@ class MainPage(models.Model): class Settings(models.Model): time_notification = models.IntegerField(default=180) document_send_email = models.EmailField(max_length=100, default="muhtarzubanchi05@gmail.com") + accountant_send_email = models.EmailField(max_length=100, default="muhtarzubanchi05@gmail.com") document_send_description = models.TextField(blank=True) document_send_time_remove = models.IntegerField(default=14) recalculation_spec_time = models.TimeField() diff --git a/common/views.py b/common/views.py index 8460409..104893b 100644 --- a/common/views.py +++ b/common/views.py @@ -46,7 +46,7 @@ class PrintDocumentCreate(BaseMixin, View): } - settings = Settings.objects.all().first().doc + settings = Settings.objects.all().first() subject, from_email, to = 'Заявка на распечатку', 'mukhtar@mukhtar', settings.document_send_email text_content = render_to_string('document_email.txt', ctx_dict) html_content = get_template('document_email.html').render(ctx_dict) diff --git a/users/mixins.py b/users/mixins.py index 6bf0e1b..a1bb811 100644 --- a/users/mixins.py +++ b/users/mixins.py @@ -12,3 +12,9 @@ class CheckForUserMixin(object): else: return HttpResponseForbidden('403 Forbidden') return super().dispatch(request, *args, **kwargs) + + +class OwnershipMixin(object): + + def dispatch(self, request, *args, **kwargs): + pass diff --git a/wallets/admin.py b/wallets/admin.py index aeb721a..ce2eb8f 100644 --- a/wallets/admin.py +++ b/wallets/admin.py @@ -1,5 +1,15 @@ from django.contrib import admin -from .models import InvoiceHistory +from .models import InvoiceHistory, WithDraw -admin.site.register(InvoiceHistory) + +class InvoiceHistoryAdmin(admin.ModelAdmin): + list_display = ('comment', 'sum', 'user','balance',) + + +class WithDrawAdmin(admin.ModelAdmin): + list_display = ('sum','created','user',) + + +admin.site.register(InvoiceHistory, InvoiceHistoryAdmin) +admin.site.register(WithDraw, WithDrawAdmin) diff --git a/wallets/forms.py b/wallets/forms.py new file mode 100644 index 0000000..3e871f3 --- /dev/null +++ b/wallets/forms.py @@ -0,0 +1,13 @@ +from django import forms +from .models import WithDraw + + +class WithDrawForm(forms.ModelForm): + + class Meta: + model = WithDraw + fields = ( + 'sum', + 'yandex_card', + 'user', + ) diff --git a/wallets/migrations/0004_invoicehistory_balance.py b/wallets/migrations/0004_invoicehistory_balance.py new file mode 100644 index 0000000..cf9840d --- /dev/null +++ b/wallets/migrations/0004_invoicehistory_balance.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-08-09 09:22 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wallets', '0003_auto_20160729_1209'), + ] + + operations = [ + migrations.AddField( + model_name='invoicehistory', + name='balance', + field=models.DecimalField(decimal_places=0, default=0, max_digits=10), + ), + ] diff --git a/wallets/migrations/0005_auto_20160809_1727.py b/wallets/migrations/0005_auto_20160809_1727.py new file mode 100644 index 0000000..f27f3ca --- /dev/null +++ b/wallets/migrations/0005_auto_20160809_1727.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-08-09 14:27 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('wallets', '0004_invoicehistory_balance'), + ] + + operations = [ + migrations.CreateModel( + name='WithDraw', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('sum', models.DecimalField(decimal_places=0, max_digits=10)), + ('created', models.DateTimeField(default=django.utils.timezone.now)), + ('yandex_card', models.CharField(max_length=30)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='with_draw', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name_plural': 'Заявки на вывод средств', + 'ordering': ('-created',), + 'verbose_name': 'Заявка на вывод средств', + }, + ), + migrations.AlterModelOptions( + name='invoicehistory', + options={'ordering': ('-created',), 'verbose_name': 'Счет(История)', 'verbose_name_plural': 'Счет(История)'}, + ), + migrations.AlterField( + model_name='invoicehistory', + name='type', + field=models.CharField(blank=True, max_length=20, null=True), + ), + ] diff --git a/wallets/models.py b/wallets/models.py index b815ccd..06b01c7 100644 --- a/wallets/models.py +++ b/wallets/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.db.models import Sum from django.utils import timezone from users.models import User @@ -14,13 +15,36 @@ class InvoiceHistory(models.Model): comment = models.TextField(blank=True) created = models.DateTimeField(default=timezone.now) sum = models.DecimalField(max_digits=10, decimal_places=0, default=0, null=True, blank=True) - type = models.CharField(max_length=20) + balance = models.DecimalField(max_digits=10, decimal_places=0, default=0) + type = models.CharField(max_length=20, blank=True, null=True) user = models.ForeignKey(User, related_name='invoice_history') def __str__(self): - return self.pk + return self.comment + + def save(self, *args, **kwargs): + if self.pk is None: + current_sum_info = InvoiceHistory.objects.filter(user=self.user).aggregate(Sum('sum')) + current_sum = current_sum_info['sum__sum'] or 0 + self.balance = current_sum + self.sum + super().save(*args, **kwargs) class Meta: verbose_name = 'Счет(История)' verbose_name_plural = 'Счет(История)' + ordering = ('-created',) + + +class WithDraw(models.Model): + sum = models.DecimalField(max_digits=10, decimal_places=0) + created = models.DateTimeField(default=timezone.now) + yandex_card = models.CharField(max_length=30) + user = models.ForeignKey(User, related_name='with_draw') + def __str__(self): + return self.yandex_card + + class Meta: + verbose_name = 'Заявка на вывод средств' + verbose_name_plural = 'Заявки на вывод средств' + ordering = ('-created',) diff --git a/wallets/signals.py b/wallets/signals.py new file mode 100644 index 0000000..3afa521 --- /dev/null +++ b/wallets/signals.py @@ -0,0 +1,20 @@ +from django.db.models.signals import post_save +from django.dispatch import receiver +from django.core.mail import send_mail, EmailMultiAlternatives +from django.template.loader import get_template, render_to_string + +from .models import WithDraw + + +@receiver(post_save, sender=WithDraw) +def send_for_accountant(sender, instance, created, **kwargs): + + if created: + ctx_dict = { + 'username': instance.user.username, + } + subject, from_email, to = 'Заявка на распечатку', 'mukhtar@mukhtar', 'muhtarzubanchi05@gmail.com' + text_content = render_to_string('send_for_accountant.txt', ctx_dict) + html_content = get_template('send_for_accountant.html').render(ctx_dict) + msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) + msg.send() diff --git a/wallets/templates/score-detail.html b/wallets/templates/score-detail.html index a7c8d38..8e679fe 100644 --- a/wallets/templates/score-detail.html +++ b/wallets/templates/score-detail.html @@ -5,61 +5,122 @@ {% block content %} -{% include 'partials/header.html' %} -
Ваш счет
-35 000
-| Дата | -Описание | -Поступление/Списание | -Баланс | -
|---|---|---|---|
| 23.01.2016 | -- Оплата этапа 1 по заказу «Сложный долгий заказ» - | -- +35 000 - - | -- 53 000 - - | -
| 23.01.2016 | -- Оплата этапа 1 по заказу «Сложный долгий заказ» - | -- +35 000 - - | -- 53 000 - - | -
Ваш счет
+{{ user_score_balance }}
+ + {% if user_score.is_customer %} +| Дата | +Описание | +Поступление/Списание | +Баланс | +
|---|---|---|---|
| {{ history.created }} | ++ {{ history.comment }} + | ++ {{ history.sum }} + + | ++ {{ history.balance }} + + | +