mirror of
https://github.com/ae-utbm/sith.git
synced 2025-02-25 17:07:13 +00:00
Allow transactions on counter when an user has recorded too many products as long as he doesn't record more
This commit is contained in:
parent
a96b374ad7
commit
1978658b9c
@ -1,14 +1,13 @@
|
||||
import { exportToHtml } from "#core:utils/globals";
|
||||
import { BasketItem } from "#counter:counter/basket";
|
||||
import type { CounterConfig, ErrorMessage } from "#counter:counter/types";
|
||||
import type { CounterProductSelect } from "./components/counter-product-select-index";
|
||||
|
||||
exportToHtml("loadCounter", (config: CounterConfig) => {
|
||||
document.addEventListener("alpine:init", () => {
|
||||
Alpine.data("counter", () => ({
|
||||
Alpine.data("counter", (config: CounterConfig) => ({
|
||||
basket: {} as Record<string, BasketItem>,
|
||||
errors: [],
|
||||
customerBalance: config.customerBalance,
|
||||
codeField: undefined,
|
||||
codeField: null as CounterProductSelect | null,
|
||||
alertMessage: {
|
||||
content: "",
|
||||
show: false,
|
||||
@ -121,10 +120,7 @@ exportToHtml("loadCounter", (config: CounterConfig) => {
|
||||
},
|
||||
|
||||
handleCode() {
|
||||
const [quantity, code] = this.codeField.getSelectedProduct() as [
|
||||
number,
|
||||
string,
|
||||
];
|
||||
const [quantity, code] = this.codeField.getSelectedProduct() as [number, string];
|
||||
|
||||
if (this.codeField.getOperationCodes().includes(code.toUpperCase())) {
|
||||
if (code === "ANN") {
|
||||
@ -141,7 +137,6 @@ exportToHtml("loadCounter", (config: CounterConfig) => {
|
||||
},
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
$(() => {
|
||||
/* Accordion UI between basket and refills */
|
||||
|
@ -27,7 +27,13 @@
|
||||
{% block content %}
|
||||
<h4>{{ counter }}</h4>
|
||||
|
||||
<div id="bar-ui" x-data="counter">
|
||||
<div id="bar-ui" x-data="counter({
|
||||
customerBalance: {{ customer.amount }},
|
||||
products: products,
|
||||
customerId: {{ customer.pk }},
|
||||
formInitial: formInitial,
|
||||
cancelUrl: '{{ cancel_url }}',
|
||||
})">
|
||||
<noscript>
|
||||
<p class="important">Javascript is required for the counter UI.</p>
|
||||
</noscript>
|
||||
@ -256,13 +262,7 @@
|
||||
{%- endfor -%}
|
||||
];
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
loadCounter({
|
||||
customerBalance: {{ customer.amount }},
|
||||
products: products,
|
||||
customerId: {{ customer.pk }},
|
||||
formInitial: formInitial,
|
||||
cancelUrl: "{{ cancel_url }}",
|
||||
});
|
||||
loadCounter();
|
||||
});
|
||||
</script>
|
||||
{% endblock script %}
|
@ -681,6 +681,42 @@ class TestCounterClick(TestFullClickBase):
|
||||
-3 - settings.SITH_ECOCUP_LIMIT
|
||||
)
|
||||
|
||||
def test_recordings_when_negative(self):
|
||||
self.refill_user(
|
||||
self.customer,
|
||||
self.cons.selling_price * 3 + Decimal(self.beer.selling_price),
|
||||
)
|
||||
self.customer.customer.recorded_products = settings.SITH_ECOCUP_LIMIT * -10
|
||||
self.customer.customer.save()
|
||||
self.login_in_bar(self.barmen)
|
||||
assert (
|
||||
self.submit_basket(
|
||||
self.customer,
|
||||
[BasketItem(self.dcons.id, 1)],
|
||||
).status_code
|
||||
== 200
|
||||
)
|
||||
assert self.updated_amount(
|
||||
self.customer
|
||||
) == self.cons.selling_price * 3 + Decimal(self.beer.selling_price)
|
||||
assert (
|
||||
self.submit_basket(
|
||||
self.customer,
|
||||
[BasketItem(self.cons.id, 3)],
|
||||
).status_code
|
||||
== 302
|
||||
)
|
||||
assert self.updated_amount(self.customer) == Decimal(self.beer.selling_price)
|
||||
|
||||
assert (
|
||||
self.submit_basket(
|
||||
self.customer,
|
||||
[BasketItem(self.beer.id, 1)],
|
||||
).status_code
|
||||
== 302
|
||||
)
|
||||
assert self.updated_amount(self.customer) == 0
|
||||
|
||||
|
||||
class TestCounterStats(TestCase):
|
||||
@classmethod
|
||||
|
@ -126,6 +126,11 @@ class BaseBasketForm(BaseFormSet):
|
||||
if form.product.is_unrecord_product:
|
||||
self.total_recordings += form.cleaned_data["quantity"]
|
||||
|
||||
# We don't want to block an user that have negative recordings
|
||||
# if he isn't recording anything or reducing it's recording count
|
||||
if self.total_recordings <= 0:
|
||||
return
|
||||
|
||||
if not customer.can_record_more(self.total_recordings):
|
||||
raise ValidationError(_("This user have reached his recording limit"))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user