diff --git a/cashonly/core/admin.py b/cashonly/core/admin.py index 6773aa0..f8ce117 100644 --- a/cashonly/core/admin.py +++ b/cashonly/core/admin.py @@ -32,12 +32,13 @@ class AccountForm(forms.ModelForm): class AccountAdmin(admin.ModelAdmin): - list_display = ('user', 'card_number', 'credit', 'transaction_link') + list_display = ('user', 'card_number', 'credit', 'debit_limit', + 'transaction_link') form = AccountForm readonly_fields = ('user', 'credit',) fieldsets = ( (None, { - 'fields': ('user', 'card_number', 'credit'), + 'fields': ('user', 'card_number', 'credit', 'debit_limit'), }), (ugettext_lazy('credit change'), { 'fields': ('credit_change', 'credit_change_comment'), diff --git a/cashonly/core/migrations/0003_debit_limit_null_default.py b/cashonly/core/migrations/0003_debit_limit_null_default.py new file mode 100644 index 0000000..57e839f --- /dev/null +++ b/cashonly/core/migrations/0003_debit_limit_null_default.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-02-17 21:54 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cashonly_core', '0002_account_debit_limit'), + ] + + operations = [ + migrations.AlterField( + model_name='account', + name='debit_limit', + field=models.DecimalField(blank=True, decimal_places=2, default=None, max_digits=5, null=True, verbose_name='debit limit'), + ), + ] diff --git a/cashonly/core/models.py b/cashonly/core/models.py index bab75a3..6569741 100644 --- a/cashonly/core/models.py +++ b/cashonly/core/models.py @@ -35,7 +35,9 @@ class Account(models.Model): verbose_name=_('debit limit'), max_digits=5, decimal_places=2, - default=settings.CASHONLY_DEFAULT_DEBIT_LIMIT, + default=None, + blank=True, + null=True, ) def __str__(self): diff --git a/cashonly/core/services.py b/cashonly/core/services.py index caba6e4..945038f 100644 --- a/cashonly/core/services.py +++ b/cashonly/core/services.py @@ -5,6 +5,7 @@ from django.utils.translation import ugettext_noop from django.db.models.signals import pre_save, post_save, pre_delete from django.dispatch import receiver from django.db import transaction +from django.conf import settings import PIL.Image import io @@ -44,7 +45,11 @@ class AccountManager: total_value = sum(map(lambda p: p.price * products[p], products.keys())) - if self.account.credit - total_value >= self.account.debit_limit * -1: + if self.account.debit_limit is not None: + debit_limit = self.account.debit_limit + else: + debit_limit = settings.CASHONLY_DEFAULT_DEBIT_LIMIT + if self.account.credit - total_value >= debit_limit * -1: desc = '' for product in products.keys(): if not product.active: