diff --git a/CHANGELOG b/CHANGELOG index 64816348..9813b64d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,10 @@ - Nouveau module BDS - Nouveau module clubs +* Version 0.3.3 - ??? + +- Les catégories d'articles K-Fêt peuvent être exemptées de subvention COF + * Version 0.3.2 - 04/11/2019 - Bugfix: modifier un compte K-Fêt ne supprime plus nom/prénom diff --git a/kfet/forms.py b/kfet/forms.py index 2a7f111a..b6fad26f 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -236,7 +236,7 @@ class CheckoutStatementUpdateForm(forms.ModelForm): class CategoryForm(forms.ModelForm): class Meta: model = ArticleCategory - fields = ["name", "has_addcost"] + fields = ["name", "has_addcost", "has_reduction"] # ----- diff --git a/kfet/migrations/0070_articlecategory_has_reduction.py b/kfet/migrations/0070_articlecategory_has_reduction.py new file mode 100644 index 00000000..c657dfdd --- /dev/null +++ b/kfet/migrations/0070_articlecategory_has_reduction.py @@ -0,0 +1,22 @@ +# Generated by Django 2.2.7 on 2019-11-27 12:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("kfet", "0069_happy_new_year"), + ] + + operations = [ + migrations.AddField( + model_name="articlecategory", + name="has_reduction", + field=models.BooleanField( + default=True, + help_text="Si oui, la réduction COF s'applique aux articles de cette catégorie", + verbose_name="réduction COF", + ), + ), + ] diff --git a/kfet/models.py b/kfet/models.py index a2d776b9..814f857a 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -464,6 +464,12 @@ class ArticleCategory(models.Model): "appliquée aux articles de " "cette catégorie.", ) + has_reduction = models.BooleanField( + "réduction COF", + default=True, + help_text="Si oui, la réduction COF s'applique" + " aux articles de cette catégorie", + ) def __str__(self): return self.name diff --git a/kfet/templates/kfet/category.html b/kfet/templates/kfet/category.html index 0a8b58be..5692725c 100644 --- a/kfet/templates/kfet/category.html +++ b/kfet/templates/kfet/category.html @@ -26,6 +26,7 @@ Nom Nombre d'articles Peut être majorée + Réduction COF appliquée @@ -38,6 +39,7 @@ {{ category.articles.all|length }} {{ category.has_addcost | yesno:"Oui,Non"}} + {{ category.has_reduction | yesno:"Oui,Non"}} {% endfor %} diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index ff24fcb4..c5c48d0d 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -661,7 +661,7 @@ $(document).ready(function() { }); $after.after(article_html); // Pour l'autocomplétion - articlesList.push([article['name'],article['id'],article['category_id'],article['price'], article['stock'],article['category__has_addcost']]); + articlesList.push([article['name'],article['id'],article['category_id'],article['price'], article['stock'],article['category__has_addcost'],article['category__has_reduction']]); } function getArticles() { @@ -851,7 +851,7 @@ $(document).ready(function() { && article_data[5]) amount_euro -= settings['addcost_amount'] * nb; var reduc_divisor = 1; - if (account_data['is_cof']) + if (account_data['is_cof'] && article_data[6]) reduc_divisor = 1 + settings['subvention_cof'] / 100; return (amount_euro / reduc_divisor).toFixed(2); } @@ -874,7 +874,7 @@ $(document).ready(function() { .attr('data-opeindex', index) .find('.number').text('('+nb+'/'+article_data[4]+')').end() .find('.name').text(article_data[0]).end() - .find('.amount').text(amountToUKF(amount_euro, account_data['is_cof']), false); + .find('.amount').text(amountToUKF(amount_euro, account_data['is_cof'], false)); basket_container.prepend(article_basket_html); if (is_low_stock(id, nb)) article_basket_html.find('.lowstock') diff --git a/kfet/tests/test_views.py b/kfet/tests/test_views.py index 432a77e8..34127cb5 100644 --- a/kfet/tests/test_views.py +++ b/kfet/tests/test_views.py @@ -1726,6 +1726,15 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase): price=Decimal("2.5"), stock=20, ) + # Another Article, price=2.5, stock=20, no COF reduction + self.article_no_reduction = Article.objects.create( + category=ArticleCategory.objects.create( + name="Category_no_reduction", has_reduction=False, + ), + name="Article_no_reduction", + price=Decimal("2.5"), + stock=20, + ) # An Account, trigramme=000, balance=50 # Do not assume user is cof, nor not cof. self.account = self.accounts["user"] @@ -2079,6 +2088,35 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase): self.article.refresh_from_db() self.assertEqual(self.article.stock, 18) + def test_purchase_no_reduction(self): + kfet_config.set(kfet_reduction_cof=Decimal("20")) + self.account.cofprofile.is_cof = True + self.account.cofprofile.save() + data = dict( + self.base_post_data, + **{ + "form-TOTAL_FORMS": "2", + "form-0-type": "purchase", + "form-0-amount": "", + "form-0-article": str(self.article_no_reduction.pk), + "form-0-article_nb": "1", + "form-1-type": "purchase", + "form-1-amount": "", + "form-1-article": str(self.article.pk), + "form-1-article_nb": "1", + } + ) + + resp = self.client.post(self.url, data) + self._assertResponseOk(resp) + + operation_group = OperationGroup.objects.get() + self.assertEqual(operation_group.amount, Decimal("-4.50")) + operation = Operation.objects.get(article=self.article) + self.assertEqual(operation.amount, Decimal("-2.00")) + operation = Operation.objects.get(article=self.article_no_reduction) + self.assertEqual(operation.amount, Decimal("-2.50")) + def test_invalid_purchase_expects_article(self): data = dict( self.base_post_data, @@ -4028,6 +4066,7 @@ class KPsulArticlesData(ViewTestCaseMixin, TestCase): "category_id", "category__name", "category__has_addcost", + "category__has_reduction", ] ), ) diff --git a/kfet/views.py b/kfet/views.py index c5d5082b..ef124c92 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1056,7 +1056,10 @@ def kpsul_perform_operations(request): to_addcost_for_balance += operation.addcost_amount if operationgroup.on_acc.is_cash: to_checkout_balance += -operation.amount - if operationgroup.on_acc.is_cof: + if ( + operationgroup.on_acc.is_cof + and operation.article.category.has_reduction + ): if is_addcost and operation.article.category.has_addcost: operation.addcost_amount /= cof_grant_divisor operation.amount = operation.amount / cof_grant_divisor @@ -1487,6 +1490,7 @@ def kpsul_articles_data(request): "category_id", "category__name", "category__has_addcost", + "category__has_reduction", ).filter(is_sold=True) return JsonResponse({"articles": list(articles)})