Merge branch 'Aufinal/no_reduction_category' into 'master'

Permet d'exclure des catégories de la réduction COF

See merge request klub-dev-ens/gestioCOF!386
This commit is contained in:
Martin Pepin 2019-11-28 14:30:54 +01:00
commit 797f0356f6
8 changed files with 82 additions and 5 deletions

View file

@ -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

View file

@ -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"]
# -----

View file

@ -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",
),
),
]

View file

@ -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

View file

@ -26,6 +26,7 @@
<td>Nom</td>
<td class="text-right">Nombre d'articles</td>
<td class="text-right" data-sorter="yesno">Peut être majorée</td>
<td class="text-right" data-sorter="yesno">Réduction COF appliquée</td>
</tr>
</thead>
<tbody>
@ -38,6 +39,7 @@
</td>
<td class="text-right">{{ category.articles.all|length }}</td>
<td class="text-right">{{ category.has_addcost | yesno:"Oui,Non"}}</td>
<td class="text-right">{{ category.has_reduction | yesno:"Oui,Non"}}</td>
</tr>
{% endfor %}
</tbody>

View file

@ -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')

View file

@ -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",
]
),
)

View file

@ -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)})