mirror of
https://github.com/ae-utbm/sith.git
synced 2026-06-13 11:39:25 +00:00
apply review comments
This commit is contained in:
@@ -65,11 +65,15 @@ document.addEventListener("alpine:init", () => {
|
||||
);
|
||||
},
|
||||
|
||||
getTotalRefill() {
|
||||
/**
|
||||
* Get the total of money that would be added to the AE account on basket purchase.
|
||||
*/
|
||||
getTotalAdded() {
|
||||
return this.basket
|
||||
.filter((item) => item.isRefill)
|
||||
.filter((item) => item.isRefill || item.unitPrice < 0)
|
||||
.reduce(
|
||||
(acc: number, item: BasketItem) => acc + item.quantity * item.unitPrice,
|
||||
(acc: number, item: BasketItem) =>
|
||||
acc + Math.abs(item.quantity * item.unitPrice),
|
||||
0,
|
||||
);
|
||||
},
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<template x-if="(getTotalRefill() + {{ customer_amount }}) > {{ settings.SITH_ACCOUNT_MAX_MONEY }}">
|
||||
<template x-if="(getTotalAdded() + {{ customer_amount }}) > {{ settings.SITH_ACCOUNT_MAX_MONEY }}">
|
||||
<div class="alert alert-red">
|
||||
<div class="alert-main">
|
||||
{% trans trimmed limit=settings.SITH_ACCOUNT_MAX_MONEY %}
|
||||
@@ -122,7 +122,7 @@
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-blue"
|
||||
:disabled="(getTotalRefill() + {{ customer_amount }}) > {{ settings.SITH_ACCOUNT_MAX_MONEY }}"
|
||||
:disabled="(getTotalAdded() + {{ customer_amount }}) > {{ settings.SITH_ACCOUNT_MAX_MONEY }}"
|
||||
>
|
||||
<i class="fa fa-check"></i>
|
||||
{% trans %}Validate{% endtrans %}
|
||||
|
||||
+1
-23
@@ -66,29 +66,7 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class BaseEbouticBasketForm(BaseBasketForm):
|
||||
def _check_enough_money(self, *args, **kwargs):
|
||||
# Disable money check
|
||||
...
|
||||
|
||||
def _check_refills(self):
|
||||
"""Check that this basket won't put customer balance above the limit."""
|
||||
refill_type_id = settings.SITH_COUNTER_PRODUCTTYPE_REFILLING
|
||||
total_refill = sum(
|
||||
f.price.amount * f.cleaned_data["quantity"]
|
||||
for f in self.forms
|
||||
if f.price.product.product_type_id == refill_type_id
|
||||
)
|
||||
total_other = sum(
|
||||
f.price.amount * f.cleaned_data["quantity"]
|
||||
for f in self.forms
|
||||
if f.price.product.product_type_id != refill_type_id
|
||||
)
|
||||
limit = settings.SITH_ACCOUNT_MAX_MONEY
|
||||
if (total_refill - total_other + self.customer.amount) > limit:
|
||||
raise ValidationError(
|
||||
_("There cannot be more than %(money)d€ on an AE account")
|
||||
% {"money": limit}
|
||||
)
|
||||
min_result_balance = None # user can pay by card, so no minimum enforced
|
||||
|
||||
|
||||
EbouticBasketForm = forms.formset_factory(
|
||||
|
||||
Reference in New Issue
Block a user