feature/#26_enhance_storage_stock_display #37

Merged
sst merged 18 commits from feature/#26_enhance_storage_stock_display into develop 2025-02-03 22:20:05 +01:00
3 changed files with 47 additions and 30 deletions
Showing only changes of commit 3aa4225acb - Show all commits

View File

@ -113,10 +113,8 @@ class AddSubStorageForm(ChangeStorageForm):
class DeleteStockForm(forms.Form):
stock_uuid = forms.UUIDField()
class EditWatermarkForm(forms.Form):
class EditStockBaseForm(forms.Form):
stock_uuid = forms.UUIDField()
watermark_active = forms.BooleanField(required=False) #If it is false, the webbrowser won't send it at all. Therefore we have to set it to required=False
watermark = forms.IntegerField(min_value=0)
def clean(self):
cleaned_data = super().clean()
@ -134,6 +132,10 @@ class EditWatermarkForm(forms.Form):
return cleaned_data
class EditWatermarkForm(EditStockBaseForm):
watermark_active = forms.BooleanField(required=False) #If it is false, the webbrowser won't send it at all. Therefore we have to set it to required=False
watermark = forms.IntegerField(min_value=0)
def save(self):
stock = self.cleaned_data['stock']
active = self.cleaned_data['watermark_active']
@ -145,26 +147,20 @@ class EditWatermarkForm(forms.Form):
stock.watermark = watermark
stock.save()
class EditStockAmountForm(forms.Form):
class EditLotForm(EditStockBaseForm):
lot = forms.IntegerField(min_value=0)
def save(self):
stock = self.cleaned_data['stock']
lot = self.cleaned_data['lot']
stock.lot = lot
stock.save()
class EditStockAmountForm(EditStockBaseForm):
stock_uuid = forms.UUIDField()
amount = forms.IntegerField(min_value=0)
def clean(self):
cleaned_data = super().clean()
id = cleaned_data.get("stock_uuid")
if not id:
raise ValidationError("No stock UUID given")
stock = None
try:
stock = parts_models.Stock.objects.get(id=id)
except:
raise ValidationError("Stock with uuid %s does not exist" % (id))
cleaned_data['stock'] = stock
return cleaned_data
def save(self, increase: bool):
stock = self.cleaned_data['stock']
amount = self.cleaned_data['amount']

View File

@ -213,6 +213,16 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
context = self.get_context_data(**kwargs)
return self.render_to_response(context)
def handle_update_lot(self, request, **kwargs):
edit_form = EditLotForm(data=request.POST)
if edit_form.is_valid():
edit_form.save()
else:
pass # Todo: Handle error
context = self.get_context_data(**kwargs)
return self.render_to_response(context)
def handle_amount_change_post(self, request, increase, **kwargs):
edit_form = EditStockAmountForm(data=request.POST)
if edit_form.is_valid():
@ -252,6 +262,8 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
return self.handle_del_stock_post(request, **kwargs)
elif 'submit-edit-watermark' in request.POST:
return self.handle_update_watermark(request, **kwargs)
elif 'submit-edit-lot' in request.POST:
return self.handle_update_lot(request, **kwargs)
elif 'submit-amount-reduce' in request.POST:
return self.handle_amount_change_post(request, False, **kwargs)
elif 'submit-amount-increase' in request.POST:

View File

@ -47,6 +47,15 @@ needs following context:
<input type="submit" class="btn btn-primary" name="submit-edit-watermark" value="Update Watermark">
</div>
</form>
<form method="post">
{% csrf_token %}
<input type="hidden" name="stock_uuid" value="{{stock.id}}">
<div class="input-group mb-3">
<input type="text" name="lot" id="ch-stk-lot-{{stock.id}}" class="form-control" value="{{stock.lot}}" required>
<input type="submit" class="btn btn-primary" name="submit-edit-lot" value="Update Lot">
</div>
</form>
</div>
</div>
</div>
</div>