Compare commits

..

No commits in common. "3ec11cf092cfaba70bbe3b8194bf35ebae275e25" and "39b64aeb716b41eb915f6969e761658c06d13d3f" have entirely different histories.

4 changed files with 47 additions and 81 deletions

View File

@ -113,8 +113,10 @@ class AddSubStorageForm(ChangeStorageForm):
class DeleteStockForm(forms.Form): class DeleteStockForm(forms.Form):
stock_uuid = forms.UUIDField() stock_uuid = forms.UUIDField()
class EditStockBaseForm(forms.Form): class EditWatermarkForm(forms.Form):
stock_uuid = forms.UUIDField() 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): def clean(self):
cleaned_data = super().clean() cleaned_data = super().clean()
@ -132,10 +134,6 @@ class EditStockBaseForm(forms.Form):
return cleaned_data 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): def save(self):
stock = self.cleaned_data['stock'] stock = self.cleaned_data['stock']
active = self.cleaned_data['watermark_active'] active = self.cleaned_data['watermark_active']
@ -147,19 +145,26 @@ class EditWatermarkForm(EditStockBaseForm):
stock.watermark = watermark stock.watermark = watermark
stock.save() stock.save()
class EditLotForm(EditStockBaseForm): class EditStockAmountForm(forms.Form):
lot = forms.IntegerField(min_value=0) stock_uuid = forms.UUIDField()
def save(self):
stock = self.cleaned_data['stock']
lot = self.cleaned_data['lot']
stock.lot = lot
stock.save()
class EditStockAmountForm(EditStockBaseForm):
amount = forms.IntegerField(min_value=0) 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): def save(self, increase: bool):
stock = self.cleaned_data['stock'] stock = self.cleaned_data['stock']
amount = self.cleaned_data['amount'] amount = self.cleaned_data['amount']

View File

@ -213,16 +213,6 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
context = self.get_context_data(**kwargs) context = self.get_context_data(**kwargs)
return self.render_to_response(context) 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): def handle_amount_change_post(self, request, increase, **kwargs):
edit_form = EditStockAmountForm(data=request.POST) edit_form = EditStockAmountForm(data=request.POST)
if edit_form.is_valid(): if edit_form.is_valid():
@ -262,8 +252,6 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
return self.handle_del_stock_post(request, **kwargs) return self.handle_del_stock_post(request, **kwargs)
elif 'submit-edit-watermark' in request.POST: elif 'submit-edit-watermark' in request.POST:
return self.handle_update_watermark(request, **kwargs) 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: elif 'submit-amount-reduce' in request.POST:
return self.handle_amount_change_post(request, False, **kwargs) return self.handle_amount_change_post(request, False, **kwargs)
elif 'submit-amount-increase' in request.POST: elif 'submit-amount-increase' in request.POST:

View File

@ -47,16 +47,7 @@ needs following context:
<input type="submit" class="btn btn-primary" name="submit-edit-watermark" value="Update Watermark"> <input type="submit" class="btn btn-primary" name="submit-edit-watermark" value="Update Watermark">
</div> </div>
</form> </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> </div>
</div> </div>
</div> </div>

View File

@ -21,28 +21,13 @@
{% qr_from_text object.get_qr_code size="m" image_format="svg" %} {% qr_from_text object.get_qr_code size="m" image_format="svg" %}
</div> </div>
<div class="row"> <div class="row">
<h4>{{storage.name}} <h4>{{storage.name}}{% if storage.verbose_name %}<small> ({{storage.verbose_name}})</small>{% endif %}</h4>
{% if storage.verbose_name %}
<small>
({{storage.verbose_name}})
</small>
{% endif %}
{% if storage.is_template %}
<small>
(template)
</small>
{% endif %}
</h4>
</div> </div>
<div class="row"> <div class="row">
{% if object.parent_storage %} {% if object.parent_storage %}
<h1>Sub-Storages <a class="btn btn-secondary" href="{% url 'parts-stocks-detail' uuid=object.parent_storage.id %}">Parent Storage</a> <h1>Sub-Storages <a class="btn btn-secondary" href="{% url 'parts-stocks-detail' uuid=object.parent_storage.id %}">Parent Storage</a> {% else %}
{% else %}
<h1>Sub-Storages <a class="btn btn-secondary" href="{% url 'parts-stocks'%}">Stock Overview</a> <h1>Sub-Storages <a class="btn btn-secondary" href="{% url 'parts-stocks'%}">Stock Overview</a>
{% endif %} {% endif %}
{% if storage.template %}
<a class="btn btn-secondary" href="{% url 'parts-stocks-detail' uuid=storage.template.id %}">Template</a>
{% endif %}
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#delete-storage-modal">Delete</button> <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#delete-storage-modal">Delete</button>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#add-sub-modal"><i class="bi bi-plus-circle"></i></button> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#add-sub-modal"><i class="bi bi-plus-circle"></i></button>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#change-modal"><i class="bi bi-pencil-square"></i></button> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#change-modal"><i class="bi bi-pencil-square"></i></button>
@ -99,9 +84,6 @@
<span class="text-secondary"><br>Lot: {{stock.lot}}</span> <span class="text-secondary"><br>Lot: {{stock.lot}}</span>
{% endif %} {% endif %}
</div> </div>
<div class="flex-grow-2 ms-3 d-none d-lg-block">
{% qr_from_text stock.get_qr_code size="6" image_format="svg" %}
</div>
<div class="ms-3"> <div class="ms-3">
Amount: {{stock.amount}} Amount: {{stock.amount}}
{% if stock.watermark >= 0 %} {% if stock.watermark >= 0 %}
@ -133,7 +115,7 @@
{% with add_storage_form as form %} {% with add_storage_form as form %}
{% include 'parts/modals/add-substorage-modal.html' %} {% include 'parts/modals/add-substorage-modal.html' %}
{% endwith %} {% endwith %}
<!-- Modal to change current storage--> <!-- Modal to change current storag-->
{% with change_storage_form as form %} {% with change_storage_form as form %}
{% include 'parts/modals/change-storage-modal.html' %} {% include 'parts/modals/change-storage-modal.html' %}
{% endwith %} {% endwith %}