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 { BasketItem } from "#counter:counter/basket";
|
||||||
import type { CounterConfig, ErrorMessage } from "#counter:counter/types";
|
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", () => {
|
||||||
document.addEventListener("alpine:init", () => {
|
Alpine.data("counter", (config: CounterConfig) => ({
|
||||||
Alpine.data("counter", () => ({
|
|
||||||
basket: {} as Record<string, BasketItem>,
|
basket: {} as Record<string, BasketItem>,
|
||||||
errors: [],
|
errors: [],
|
||||||
customerBalance: config.customerBalance,
|
customerBalance: config.customerBalance,
|
||||||
codeField: undefined,
|
codeField: null as CounterProductSelect | null,
|
||||||
alertMessage: {
|
alertMessage: {
|
||||||
content: "",
|
content: "",
|
||||||
show: false,
|
show: false,
|
||||||
@ -121,10 +120,7 @@ exportToHtml("loadCounter", (config: CounterConfig) => {
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleCode() {
|
handleCode() {
|
||||||
const [quantity, code] = this.codeField.getSelectedProduct() as [
|
const [quantity, code] = this.codeField.getSelectedProduct() as [number, string];
|
||||||
number,
|
|
||||||
string,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (this.codeField.getOperationCodes().includes(code.toUpperCase())) {
|
if (this.codeField.getOperationCodes().includes(code.toUpperCase())) {
|
||||||
if (code === "ANN") {
|
if (code === "ANN") {
|
||||||
@ -140,7 +136,6 @@ exportToHtml("loadCounter", (config: CounterConfig) => {
|
|||||||
this.codeField.widget.focus();
|
this.codeField.widget.focus();
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$(() => {
|
$(() => {
|
||||||
|
@ -27,7 +27,13 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<h4>{{ counter }}</h4>
|
<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>
|
<noscript>
|
||||||
<p class="important">Javascript is required for the counter UI.</p>
|
<p class="important">Javascript is required for the counter UI.</p>
|
||||||
</noscript>
|
</noscript>
|
||||||
@ -256,13 +262,7 @@
|
|||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
];
|
];
|
||||||
window.addEventListener("DOMContentLoaded", () => {
|
window.addEventListener("DOMContentLoaded", () => {
|
||||||
loadCounter({
|
loadCounter();
|
||||||
customerBalance: {{ customer.amount }},
|
|
||||||
products: products,
|
|
||||||
customerId: {{ customer.pk }},
|
|
||||||
formInitial: formInitial,
|
|
||||||
cancelUrl: "{{ cancel_url }}",
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock script %}
|
{% endblock script %}
|
@ -681,6 +681,42 @@ class TestCounterClick(TestFullClickBase):
|
|||||||
-3 - settings.SITH_ECOCUP_LIMIT
|
-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):
|
class TestCounterStats(TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -126,6 +126,11 @@ class BaseBasketForm(BaseFormSet):
|
|||||||
if form.product.is_unrecord_product:
|
if form.product.is_unrecord_product:
|
||||||
self.total_recordings += form.cleaned_data["quantity"]
|
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):
|
if not customer.can_record_more(self.total_recordings):
|
||||||
raise ValidationError(_("This user have reached his recording limit"))
|
raise ValidationError(_("This user have reached his recording limit"))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user