From cadaf4313128c9b7d88be24ef5a8163afe0af447 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 24 Mar 2017 18:50:57 -0300 Subject: [PATCH 01/15] Remove is_checkout field from Operation model --- kfet/models.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kfet/models.py b/kfet/models.py index 419cd0a0..e54ca0cd 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -510,12 +510,14 @@ class Operation(models.Model): DEPOSIT = 'deposit' WITHDRAW = 'withdraw' INITIAL = 'initial' + EDIT = 'edit' TYPE_ORDER_CHOICES = ( (PURCHASE, 'Achat'), (DEPOSIT, 'Charge'), (WITHDRAW, 'Retrait'), (INITIAL, 'Initial'), + (EDIT, 'Édition'), ) group = models.ForeignKey( @@ -527,7 +529,6 @@ class Operation(models.Model): amount = models.DecimalField( max_digits = 6, decimal_places = 2, blank = True, default = 0) - is_checkout = models.BooleanField(default = True) # Optional article = models.ForeignKey( Article, on_delete = models.PROTECT, @@ -549,6 +550,14 @@ class Operation(models.Model): max_digits = 6, decimal_places = 2, blank = True, null = True, default = None) + @property + def is_checkout(self): + return (self.type == DEPOSIT or + self.type == WITHDRAW or + (self.type == PURCHASE and self.group and + self.group.on_acc.is_cash) + ) + class GlobalPermissions(models.Model): class Meta: managed = False From d7740e66fe9397797a110b66a30aa38eabec5d1d Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 24 Mar 2017 20:52:49 -0300 Subject: [PATCH 02/15] adapt code to is_checkout removal --- kfet/forms.py | 4 +- kfet/migrations/0048_auto_20170324_2313.py | 23 +++++++ kfet/models.py | 6 +- kfet/static/kfet/js/history.js | 19 ++++-- kfet/templates/kfet/kpsul.html | 73 +++++++++++++++++----- kfet/views.py | 20 +++--- 6 files changed, 105 insertions(+), 40 deletions(-) create mode 100644 kfet/migrations/0048_auto_20170324_2313.py diff --git a/kfet/forms.py b/kfet/forms.py index 0c563b04..d00dfc46 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -313,11 +313,10 @@ class KPsulOperationForm(forms.ModelForm): widget = forms.HiddenInput()) class Meta: model = Operation - fields = ['type', 'amount', 'is_checkout', 'article', 'article_nb'] + fields = ['type', 'amount', 'article', 'article_nb'] widgets = { 'type': forms.HiddenInput(), 'amount': forms.HiddenInput(), - 'is_checkout': forms.HiddenInput(), 'article_nb': forms.HiddenInput(), } @@ -333,7 +332,6 @@ class KPsulOperationForm(forms.ModelForm): "Un achat nécessite un article et une quantité") if article_nb < 1: raise ValidationError("Impossible d'acheter moins de 1 article") - self.cleaned_data['is_checkout'] = True elif type_ope and type_ope in [Operation.DEPOSIT, Operation.WITHDRAW]: if not amount or article or article_nb: raise ValidationError("Bad request") diff --git a/kfet/migrations/0048_auto_20170324_2313.py b/kfet/migrations/0048_auto_20170324_2313.py new file mode 100644 index 00000000..636fda65 --- /dev/null +++ b/kfet/migrations/0048_auto_20170324_2313.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0047_auto_20170104_1528'), + ] + + operations = [ + migrations.RemoveField( + model_name='operation', + name='is_checkout', + ), + migrations.AlterField( + model_name='operation', + name='type', + field=models.CharField(max_length=8, choices=[('purchase', 'Achat'), ('deposit', 'Charge'), ('withdraw', 'Retrait'), ('initial', 'Initial'), ('edit', 'Édition')]), + ), + ] diff --git a/kfet/models.py b/kfet/models.py index e54ca0cd..c902c5d8 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -552,9 +552,9 @@ class Operation(models.Model): @property def is_checkout(self): - return (self.type == DEPOSIT or - self.type == WITHDRAW or - (self.type == PURCHASE and self.group and + return (self.type == Operation.DEPOSIT or + self.type == Operation.WITHDRAW or + (self.type == Operation.PURCHASE and self.group and self.group.on_acc.is_cash) ) diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index 291c106d..8559f050 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -31,13 +31,22 @@ function KHistory(options={}) { if (ope['type'] == 'purchase') { infos1 = ope['article_nb']; infos2 = ope['article__name']; - } else if (ope['type'] == 'initial') { - infos1 = parsed_amount.toFixed(2)+'€'; - infos2 = 'Initial'; } else { infos1 = parsed_amount.toFixed(2)+'€'; - infos2 = (ope['type'] == 'deposit') ? 'Charge' : 'Retrait'; - infos2 = ope['is_checkout'] ? infos2 : 'Édition'; + switch (ope['type']) { + case 'initial': + infos2 = 'Initial'; + break; + case 'withdraw': + infos2 = 'Retrait'; + break; + case 'deposit': + infos2 = 'Charge'; + break; + case 'edit': + infos2 = 'Édition'; + break; + } } $ope_html diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 7c0437fa..3d11ddec 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -794,15 +794,27 @@ $(document).ready(function() { updateBasketRel(); } - function addDeposit(amount, is_checkout=1) { + function addDeposit(amount) { var deposit_basket_html = $(item_basket_default_html); var amount = parseFloat(amount).toFixed(2); - var index = addDepositToFormset(amount, is_checkout); - var text = is_checkout ? 'Charge' : 'Édition'; + var index = addDepositToFormset(amount); deposit_basket_html .attr('data-opeindex', index) .find('.number').text(amount+"€").end() - .find('.name').text(text).end() + .find('.name').text('Charge').end() + .find('.amount').text(amountToUKF(amount, account_data['is_cof'])); + basket_container.prepend(deposit_basket_html); + updateBasketRel(); + } + + function addEdit(amount) { + var deposit_basket_html = $(item_basket_default_html); + var amount = parseFloat(amount).toFixed(2); + var index = addEditToFormset(amount); + deposit_basket_html + .attr('data-opeindex', index) + .find('.number').text(amount+"€").end() + .find('.name').text('Édition').end() .find('.amount').text(amountToUKF(amount, account_data['is_cof'])); basket_container.prepend(deposit_basket_html); updateBasketRel(); @@ -910,10 +922,9 @@ $(document).ready(function() { // Ask deposit or withdraw // ----- - function askDeposit(is_checkout=1) { - var title = is_checkout ? 'Montant de la charge' : "Montant de l'édition"; + function askDeposit() { $.confirm({ - title: title, + title: 'Montant de la charge', content: '', backgroundDismiss: true, animation:'top', @@ -923,7 +934,34 @@ $(document).ready(function() { var amount = this.$content.find('input').val(); if (!$.isNumeric(amount) || amount <= 0) return false; - addDeposit(amount, is_checkout); + addDeposit(amount); + }, + onOpen: function() { + var that = this + this.$content.find('input').on('keydown', function(e) { + if (e.keyCode == 13) { + e.preventDefault(); + that.$confirmButton.click(); + } + }); + }, + onClose: function() { this._lastFocused = (articleSelect.val() ? articleNb : articleSelect) ; } + }); + } + + function askEdit() { + $.confirm({ + title: "Montant de l'édition", + content: '', + backgroundDismiss: true, + animation:'top', + closeAnimation:'bottom', + keyboardEnabled: true, + confirm: function() { + var amount = this.$content.find('input').val(); + if (!$.isNumeric(amount)) + return false; + addEdit(amount); }, onOpen: function() { var that = this @@ -988,7 +1026,7 @@ $(document).ready(function() { var mngmt_total_forms = 1; var prefix_regex = /__prefix__/; - function addOperationToFormset(type, amount, article='', article_nb='', is_checkout=1) { + function addOperationToFormset(type, amount, article='', article_nb='') { var operation_html = operation_empty_html.clone(); var index = mngmt_total_forms; @@ -998,8 +1036,7 @@ $(document).ready(function() { .find('#id_form-__prefix__-type').val(type).end() .find('#id_form-__prefix__-amount').val((parseFloat(amount)).toFixed(2)).end() .find('#id_form-__prefix__-article').val(article).end() - .find('#id_form-__prefix__-article_nb').val(article_nb).end() - .find('#id_form-__prefix__-is_checkout').val(is_checkout); + .find('#id_form-__prefix__-article_nb').val(article_nb).end(); mngmt_total_forms_input.val(index+1); mngmt_total_forms++; @@ -1014,12 +1051,16 @@ $(document).ready(function() { return index; } - function addDepositToFormset(amount, is_checkout=1) { - return addOperationToFormset('deposit', amount, '', '', is_checkout); + function addDepositToFormset(amount) { + return addOperationToFormset('deposit', amount, '', ''); } - function addWithdrawToFormset(amount, is_checkout=1) { - return addOperationToFormset('withdraw', amount, '', '', is_checkout); + function addEditToFormset(amount) { + return addOperationToFormset('edit', amount, '', ''); + } + + function addWithdrawToFormset(amount) { + return addOperationToFormset('withdraw', amount, '', ''); } function addPurchaseToFormset(article_id, article_nb, amount=0) { @@ -1295,7 +1336,7 @@ $(document).ready(function() { return false; case 119: // F8 - Edition - askDeposit(0); + askEdit(); return false; case 120: // F9 - Addcost diff --git a/kfet/views.py b/kfet/views.py index 4622f5d8..971e4ba5 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -138,8 +138,7 @@ def account_create_special(request): ope = Operation.objects.create( group = opegroup, type = Operation.INITIAL, - amount = amount, - is_checkout = False) + amount = amount) messages.success(request, 'Compte créé : %s' % account.trigramme) return redirect('kfet.account.create') except Account.UserHasAccount as e: @@ -960,10 +959,7 @@ def kpsul_perform_operations(request): operation.amount -= operation.addcost_amount to_addcost_for_balance += operation.addcost_amount if operationgroup.on_acc.is_cash: - operation.is_checkout = True to_checkout_balance += -operation.amount - else: - operation.is_checkout = False if operationgroup.on_acc.is_cof: if is_addcost: operation.addcost_amount = operation.addcost_amount / cof_grant_divisor @@ -972,12 +968,12 @@ def kpsul_perform_operations(request): else: if operationgroup.on_acc.is_cash: data['errors']['account'] = 'Charge et retrait impossible sur LIQ' - to_checkout_balance += operation.amount + if operation.type != Operation.EDIT: + to_checkout_balance += operation.amount operationgroup.amount += operation.amount if operation.type == Operation.DEPOSIT: required_perms.add('kfet.perform_deposit') - if (not operation.is_checkout - and operation.type in [Operation.DEPOSIT, Operation.WITHDRAW]): + if operation.type == Operation.EDIT: required_perms.add('kfet.edit_balance_account') need_comment = True if operationgroup.on_acc.is_cof: @@ -1073,7 +1069,6 @@ def kpsul_perform_operations(request): 'id': operation.pk, 'type': operation.type, 'amount': operation.amount, 'addcost_amount': operation.addcost_amount, 'addcost_for__trigramme': is_addcost and addcost_for.trigramme or None, - 'is_checkout': operation.is_checkout, 'article__name': operation.article and operation.article.name or None, 'article_nb': operation.article_nb, 'group_id': operationgroup.pk, @@ -1163,11 +1158,11 @@ def kpsul_cancel_operations(request): .order_by('at') .last()) if not last_statement or last_statement.at < ope.group.at: - if ope.type == Operation.PURCHASE: + if ope.is_checkout: if ope.group.on_acc.is_cash: to_checkouts_balances[ope.group.checkout] -= - ope.amount - else: - to_checkouts_balances[ope.group.checkout] -= ope.amount + else: + to_checkouts_balances[ope.group.checkout] -= ope.amount # Pour les stocks d'articles # Les stocks d'articles dont il y a eu un inventaire depuis la date @@ -1328,7 +1323,6 @@ def history_json(request): 'type' : ope.type, 'amount' : ope.amount, 'article_nb' : ope.article_nb, - 'is_checkout' : ope.is_checkout, 'addcost_amount': ope.addcost_amount, 'canceled_at' : ope.canceled_at, 'article__name': From 608e67fe6ac96d9254280ba7421ef98bc3696fd0 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 24 Mar 2017 21:23:04 -0300 Subject: [PATCH 03/15] Add RunPython script to migration --- kfet/migrations/0049_auto_20170325_0110.py | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 kfet/migrations/0049_auto_20170325_0110.py diff --git a/kfet/migrations/0049_auto_20170325_0110.py b/kfet/migrations/0049_auto_20170325_0110.py new file mode 100644 index 00000000..0620dd7a --- /dev/null +++ b/kfet/migrations/0049_auto_20170325_0110.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +def adapt_operation_types(apps, schema_editor): + Operation = apps.get_model("kfet", "Operation") + + for ope in Operation.objects.all(): + if (not ope.is_checkout and + ope.type in ['deposit', 'withdraw']): + ope.type = 'edit' + ope.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0048_article_hidden'), + ] + + operations = [ + migrations.AlterField( + model_name='operation', + name='type', + field=models.CharField(choices=[('purchase', 'Achat'), ('deposit', 'Charge'), ('withdraw', 'Retrait'), ('initial', 'Initial'), ('edit', 'Édition')], max_length=8), + ), + migrations.RunPython(adapt_operation_types), + migrations.RemoveField( + model_name='operation', + name='is_checkout', + ), + ] From 5f3f0440840839de8d8ba72768d3671f6f6c1b6a Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 24 Mar 2017 23:27:55 -0300 Subject: [PATCH 04/15] Add revert function to migration --- kfet/migrations/0049_auto_20170325_0110.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/kfet/migrations/0049_auto_20170325_0110.py b/kfet/migrations/0049_auto_20170325_0110.py index 0620dd7a..29d15676 100644 --- a/kfet/migrations/0049_auto_20170325_0110.py +++ b/kfet/migrations/0049_auto_20170325_0110.py @@ -6,12 +6,22 @@ from django.db import migrations, models def adapt_operation_types(apps, schema_editor): Operation = apps.get_model("kfet", "Operation") + edits = Operation.objects.filter( + is_checkout=False, + type__in=['withdraw', 'deposit']) - for ope in Operation.objects.all(): - if (not ope.is_checkout and - ope.type in ['deposit', 'withdraw']): - ope.type = 'edit' - ope.save() + for ope in edits: + ope.type = 'edit' + ope.save() + + +def revert_operation_types(apps, schema_editor): + Operation = apps.get_model("kfet", "Operation") + + for ope in Operation.objects.filter(type='edit'): + ope.type = 'deposit' if ope.amount > 0 else 'withdraw' + ope.is_checkout = False + ope.save() class Migration(migrations.Migration): @@ -26,7 +36,7 @@ class Migration(migrations.Migration): name='type', field=models.CharField(choices=[('purchase', 'Achat'), ('deposit', 'Charge'), ('withdraw', 'Retrait'), ('initial', 'Initial'), ('edit', 'Édition')], max_length=8), ), - migrations.RunPython(adapt_operation_types), + migrations.RunPython(adapt_operation_types, revert_operation_types), migrations.RemoveField( model_name='operation', name='is_checkout', From 794527772fdece6a479705f4d5ec307c0911d72a Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 24 Mar 2017 23:41:33 -0300 Subject: [PATCH 05/15] Add more explicit migration name --- .../{0049_auto_20170325_0110.py => 0049_remove_checkout.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename kfet/migrations/{0049_auto_20170325_0110.py => 0049_remove_checkout.py} (100%) diff --git a/kfet/migrations/0049_auto_20170325_0110.py b/kfet/migrations/0049_remove_checkout.py similarity index 100% rename from kfet/migrations/0049_auto_20170325_0110.py rename to kfet/migrations/0049_remove_checkout.py From bc0affc038e36d5ce820de22cb9393e0ee3db72e Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 25 Mar 2017 09:56:36 -0300 Subject: [PATCH 06/15] Remove autocomplete leftovers --- kfet/templates/kfet/kpsul.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 55caac13..5e5ce87d 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -1062,7 +1062,7 @@ $(document).ready(function() { function askDeposit() { $.confirm({ title: 'Montant de la charge', - content: '', + content: '', backgroundDismiss: true, animation:'top', closeAnimation:'bottom', @@ -1089,7 +1089,7 @@ $(document).ready(function() { function askEdit() { $.confirm({ title: "Montant de l'édition", - content: '', + content: '', backgroundDismiss: true, animation:'top', closeAnimation:'bottom', @@ -1116,7 +1116,7 @@ $(document).ready(function() { function askWithdraw() { $.confirm({ title: 'Montant du retrait', - content: '', + content: '', backgroundDismiss: true, animation:'top', closeAnimation:'bottom', From d8f572bb01d7537e8d0c6bacb7399c9e4b28562d Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 25 Mar 2017 09:57:44 -0300 Subject: [PATCH 07/15] Remove group check in is_checkout --- kfet/models.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kfet/models.py b/kfet/models.py index db7381e5..f9cc321b 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -569,8 +569,7 @@ class Operation(models.Model): def is_checkout(self): return (self.type == Operation.DEPOSIT or self.type == Operation.WITHDRAW or - (self.type == Operation.PURCHASE and self.group and - self.group.on_acc.is_cash) + (self.type == Operation.PURCHASE and self.group.on_acc.is_cash) ) def __str__(self): From 14e0d8090f4f352a95214c12892beed4c2105111 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 25 Mar 2017 10:01:35 -0300 Subject: [PATCH 08/15] Add euros symbols --- kfet/models.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kfet/models.py b/kfet/models.py index f9cc321b..77d37317 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -575,10 +575,10 @@ class Operation(models.Model): def __str__(self): templates = { self.PURCHASE: "{nb} {article.name} ({amount}€)", - self.DEPOSIT: "charge ({amount})", - self.WITHDRAW: "retrait ({amount})", - self.INITIAL: "initial ({amount})", - self.EDIT: "édition ({amount})", + self.DEPOSIT: "charge ({amount}€)", + self.WITHDRAW: "retrait ({amount}€)", + self.INITIAL: "initial ({amount}€)", + self.EDIT: "édition ({amount}€)", } return templates[self.type].format(nb=self.article_nb, article=self.article, From f645121fb1c7d6876d6ca0ca2e8d0360ce089525 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 25 Mar 2017 10:39:53 -0300 Subject: [PATCH 09/15] Add error when editing LIQ --- kfet/static/kfet/js/kfet.js | 6 ++++++ kfet/views.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/kfet/static/kfet/js/kfet.js b/kfet/static/kfet/js/kfet.js index f0e7a316..8236b3e9 100644 --- a/kfet/static/kfet/js/kfet.js +++ b/kfet/static/kfet/js/kfet.js @@ -86,6 +86,12 @@ function getErrorsHtml(data) { content += '
  • Montant invalide
  • '; content += ''; } + if ('account' in data['errors']) { + content += 'Général'; + content += '
      '; + content += '
    • Opération invalide sur le compte '+data['errors']['account']+'
    • '; + content += '
    '; + } return content; } diff --git a/kfet/views.py b/kfet/views.py index 23d3c703..e87dde9b 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1017,7 +1017,8 @@ def kpsul_perform_operations(request): to_articles_stocks[operation.article] -= operation.article_nb else: if operationgroup.on_acc.is_cash: - data['errors']['account'] = 'Charge et retrait impossible sur LIQ' + data['errors']['account'] = 'LIQ' + return JsonResponse(data, status=400) if operation.type != Operation.EDIT: to_checkout_balance += operation.amount operationgroup.amount += operation.amount From 9a081ddae07fb1cb9d711fdb1730fd00cb3a8e93 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 25 Mar 2017 10:43:02 -0300 Subject: [PATCH 10/15] PEP8 on Operation model --- kfet/models.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/kfet/models.py b/kfet/models.py index 77d37317..9d4a9536 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -522,7 +522,7 @@ class OperationGroup(models.Model): class Operation(models.Model): PURCHASE = 'purchase' - DEPOSIT = 'deposit' + DEPOSIT = 'deposit' WITHDRAW = 'withdraw' INITIAL = 'initial' EDIT = 'edit' @@ -536,34 +536,34 @@ class Operation(models.Model): ) group = models.ForeignKey( - OperationGroup, on_delete = models.PROTECT, - related_name = "opes") + OperationGroup, on_delete=models.PROTECT, + related_name="opes") type = models.CharField( - choices = TYPE_ORDER_CHOICES, - max_length = choices_length(TYPE_ORDER_CHOICES)) + choices=TYPE_ORDER_CHOICES, + max_length=choices_length(TYPE_ORDER_CHOICES)) amount = models.DecimalField( - max_digits = 6, decimal_places = 2, - blank = True, default = 0) + max_digits=6, decimal_places=2, + blank=True, default=0) # Optional article = models.ForeignKey( - Article, on_delete = models.PROTECT, - related_name = "operations", - blank = True, null = True, default = None) + Article, on_delete=models.PROTECT, + related_name="operations", + blank=True, null=True, default=None) article_nb = models.PositiveSmallIntegerField( - blank = True, null = True, default = None) + blank=True, null=True, default=None) canceled_by = models.ForeignKey( - Account, on_delete = models.PROTECT, - related_name = "+", - blank = True, null = True, default = None) + Account, on_delete=models.PROTECT, + related_name="+", + blank=True, null=True, default=None) canceled_at = models.DateTimeField( - blank = True, null = True, default = None) + blank=True, null=True, default=None) addcost_for = models.ForeignKey( - Account, on_delete = models.PROTECT, - related_name = "addcosts", - blank = True, null = True, default = None) + Account, on_delete=models.PROTECT, + related_name="addcosts", + blank=True, null=True, default=None) addcost_amount = models.DecimalField( - max_digits = 6, decimal_places = 2, - blank = True, null = True, default = None) + max_digits=6, decimal_places=2, + blank=True, null=True, default=None) @property def is_checkout(self): @@ -584,6 +584,7 @@ class Operation(models.Model): article=self.article, amount=self.amount) + class GlobalPermissions(models.Model): class Meta: managed = False From 06a89055c4ed951eb78b8ece725a08efca5387a3 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 25 Mar 2017 10:46:18 -0300 Subject: [PATCH 11/15] Simpler migration --- kfet/migrations/0049_remove_checkout.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/kfet/migrations/0049_remove_checkout.py b/kfet/migrations/0049_remove_checkout.py index 29d15676..8328c9c4 100644 --- a/kfet/migrations/0049_remove_checkout.py +++ b/kfet/migrations/0049_remove_checkout.py @@ -6,13 +6,9 @@ from django.db import migrations, models def adapt_operation_types(apps, schema_editor): Operation = apps.get_model("kfet", "Operation") - edits = Operation.objects.filter( + Operation.objects.filter( is_checkout=False, - type__in=['withdraw', 'deposit']) - - for ope in edits: - ope.type = 'edit' - ope.save() + type__in=['withdraw', 'deposit']).update(type='edit') def revert_operation_types(apps, schema_editor): From 946182f1fef54f72f3498900acfc659765f60ad2 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sun, 26 Mar 2017 15:06:45 -0300 Subject: [PATCH 12/15] Simpler migration revert --- kfet/migrations/0049_remove_checkout.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kfet/migrations/0049_remove_checkout.py b/kfet/migrations/0049_remove_checkout.py index 8328c9c4..d2eae10c 100644 --- a/kfet/migrations/0049_remove_checkout.py +++ b/kfet/migrations/0049_remove_checkout.py @@ -13,11 +13,9 @@ def adapt_operation_types(apps, schema_editor): def revert_operation_types(apps, schema_editor): Operation = apps.get_model("kfet", "Operation") - - for ope in Operation.objects.filter(type='edit'): - ope.type = 'deposit' if ope.amount > 0 else 'withdraw' - ope.is_checkout = False - ope.save() + edits = Operation.objects.filter(type='edit') + edits.filter(amount__gt=0).update(type='deposit') + edits.filter(amount__lte=0).update(type='withdraw') class Migration(migrations.Migration): From 1d8e084a196c393d0da7c7753a8378ba06d36b83 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 31 Mar 2017 14:37:00 -0300 Subject: [PATCH 13/15] websocket update when addcost --- kfet/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kfet/views.py b/kfet/views.py index e87dde9b..3c78601f 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1119,7 +1119,7 @@ def kpsul_perform_operations(request): ope_data = { 'id': operation.pk, 'type': operation.type, 'amount': operation.amount, 'addcost_amount': operation.addcost_amount, - 'addcost_for__trigramme': is_addcost and addcost_for.trigramme or None, + 'addcost_for__trigramme': operation.addcost_for and addcost_for.trigramme or None, 'article__name': operation.article and operation.article.name or None, 'article_nb': operation.article_nb, 'group_id': operationgroup.pk, From 271654b44792266fa0fe5950e6795051534bbb6b Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 1 Apr 2017 08:47:09 -0300 Subject: [PATCH 14/15] No need for intermediate error reporting --- kfet/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/kfet/views.py b/kfet/views.py index f2ea1599..b4d1328b 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1018,7 +1018,6 @@ def kpsul_perform_operations(request): else: if operationgroup.on_acc.is_cash: data['errors']['account'] = 'LIQ' - return JsonResponse(data, status=400) if operation.type != Operation.EDIT: to_checkout_balance += operation.amount operationgroup.amount += operation.amount From 91a057873d2f8f51ab939fc0d63ee94b45890de9 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 1 Apr 2017 18:10:51 -0300 Subject: [PATCH 15/15] Merge migrations --- kfet/migrations/0049_remove_checkout.py | 38 ------------------------- kfet/migrations/0050_remove_checkout.py | 23 +++++++++++++++ 2 files changed, 23 insertions(+), 38 deletions(-) delete mode 100644 kfet/migrations/0049_remove_checkout.py create mode 100644 kfet/migrations/0050_remove_checkout.py diff --git a/kfet/migrations/0049_remove_checkout.py b/kfet/migrations/0049_remove_checkout.py deleted file mode 100644 index d2eae10c..00000000 --- a/kfet/migrations/0049_remove_checkout.py +++ /dev/null @@ -1,38 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models - - -def adapt_operation_types(apps, schema_editor): - Operation = apps.get_model("kfet", "Operation") - Operation.objects.filter( - is_checkout=False, - type__in=['withdraw', 'deposit']).update(type='edit') - - -def revert_operation_types(apps, schema_editor): - Operation = apps.get_model("kfet", "Operation") - edits = Operation.objects.filter(type='edit') - edits.filter(amount__gt=0).update(type='deposit') - edits.filter(amount__lte=0).update(type='withdraw') - - -class Migration(migrations.Migration): - - dependencies = [ - ('kfet', '0048_article_hidden'), - ] - - operations = [ - migrations.AlterField( - model_name='operation', - name='type', - field=models.CharField(choices=[('purchase', 'Achat'), ('deposit', 'Charge'), ('withdraw', 'Retrait'), ('initial', 'Initial'), ('edit', 'Édition')], max_length=8), - ), - migrations.RunPython(adapt_operation_types, revert_operation_types), - migrations.RemoveField( - model_name='operation', - name='is_checkout', - ), - ] diff --git a/kfet/migrations/0050_remove_checkout.py b/kfet/migrations/0050_remove_checkout.py new file mode 100644 index 00000000..f9c374ca --- /dev/null +++ b/kfet/migrations/0050_remove_checkout.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0049_merge'), + ] + + operations = [ + migrations.RemoveField( + model_name='operation', + name='is_checkout', + ), + migrations.AlterField( + model_name='operation', + name='type', + field=models.CharField(choices=[('purchase', 'Achat'), ('deposit', 'Charge'), ('withdraw', 'Retrait'), ('initial', 'Initial'), ('edit', 'Édition')], max_length=8), + ), + ]