Fix selling ordering bug that created "not enough money" errors

* Add tests
* Add tests for cons/dcons
This commit is contained in:
2025-01-10 16:35:42 +01:00
parent 6ee2e8c5da
commit a4c6439981
3 changed files with 95 additions and 2 deletions

View File

@ -194,7 +194,11 @@ class CounterClick(CounterTabsMixin, CanViewMixin, SingleObjectMixin, FormView):
with transaction.atomic():
self.request.session["last_basket"] = []
for form in formset:
# We sort items from cheap to expensive
# This is important because some items have a negative price
# Negative priced items gives money to the customer and should
# be processed first so that we don't throw a not enough money error
for form in sorted(formset, key=lambda form: form.product.price):
self.request.session["last_basket"].append(
f"{form.cleaned_data['quantity']} x {form.product.name}"
)