Revert Bambu Lab cart and price allocation changes
This commit is contained in:
1 parent
8806fc85e5
commit
9f07b07bb7
12 files changed
+7
-1090
No files matched your search
@@ -1,5 +1,3 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from django import forms
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db.models import Q
|
||||
@@ -47,45 +45,6 @@ class MarketplaceOfferForm(forms.ModelForm):
|
||||
return quantity
|
||||
|
||||
|
||||
class BambuCartPricesForm(forms.Form):
|
||||
signature = forms.CharField(widget=forms.HiddenInput)
|
||||
cart_total = forms.DecimalField(
|
||||
label="Warensumme nach allen Rabatten (€)",
|
||||
min_value=0,
|
||||
max_value=Decimal("21474836.47"),
|
||||
decimal_places=2,
|
||||
localize=True,
|
||||
widget=forms.TextInput(attrs={"inputmode": "decimal"}),
|
||||
)
|
||||
|
||||
def __init__(self, *args, plan, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.plan = plan
|
||||
self.initial["signature"] = plan.signature
|
||||
for line in plan.lines:
|
||||
self.fields[line.key] = forms.DecimalField(
|
||||
label=f"Preis für {line.quantity} Stück · {line.variant}",
|
||||
min_value=0,
|
||||
max_value=Decimal("21474836.47"),
|
||||
decimal_places=2,
|
||||
localize=True,
|
||||
widget=forms.TextInput(attrs={"inputmode": "decimal"}),
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
cleaned = super().clean()
|
||||
if cleaned.get("signature") != self.plan.signature:
|
||||
raise forms.ValidationError("Die Bestellliste hat sich geändert. Lade die Seite neu.")
|
||||
total = cleaned.get("cart_total")
|
||||
if total is not None and all(line.key in cleaned for line in self.plan.lines):
|
||||
if total > sum(cleaned[line.key] for line in self.plan.lines):
|
||||
self.add_error(
|
||||
"cart_total",
|
||||
"Die Warensumme darf die Summe der Positionen nicht übersteigen. Prüfe Versand und weitere Artikel.",
|
||||
)
|
||||
return cleaned
|
||||
|
||||
|
||||
def selection_id(value):
|
||||
text = str(value or "")
|
||||
return int(text) if text.isascii() and text.isdecimal() and len(text) < 19 else None
|
||||
|
||||
Reference in new issue
Block a user