Compare commits
4 Commits
39b64aeb71
...
3ec11cf092
Author | SHA1 | Date | |
---|---|---|---|
3ec11cf092 | |||
e4e7456a5d | |||
6eaef98c86 | |||
3aa4225acb |
@ -113,10 +113,8 @@ class AddSubStorageForm(ChangeStorageForm):
|
|||||||
class DeleteStockForm(forms.Form):
|
class DeleteStockForm(forms.Form):
|
||||||
stock_uuid = forms.UUIDField()
|
stock_uuid = forms.UUIDField()
|
||||||
|
|
||||||
class EditWatermarkForm(forms.Form):
|
class EditStockBaseForm(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()
|
||||||
@ -134,6 +132,10 @@ class EditWatermarkForm(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']
|
||||||
@ -145,26 +147,19 @@ class EditWatermarkForm(forms.Form):
|
|||||||
stock.watermark = watermark
|
stock.watermark = watermark
|
||||||
stock.save()
|
stock.save()
|
||||||
|
|
||||||
class EditStockAmountForm(forms.Form):
|
class EditLotForm(EditStockBaseForm):
|
||||||
stock_uuid = forms.UUIDField()
|
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):
|
||||||
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']
|
||||||
|
@ -213,6 +213,16 @@ 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():
|
||||||
@ -252,6 +262,8 @@ 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:
|
||||||
|
@ -47,7 +47,16 @@ 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>
|
@ -21,13 +21,28 @@
|
|||||||
{% 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}}{% if storage.verbose_name %}<small> ({{storage.verbose_name}})</small>{% endif %}</h4>
|
<h4>{{storage.name}}
|
||||||
|
{% 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> {% else %}
|
<h1>Sub-Storages <a class="btn btn-secondary" href="{% url 'parts-stocks-detail' uuid=object.parent_storage.id %}">Parent Storage</a>
|
||||||
|
{% 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>
|
||||||
@ -84,6 +99,9 @@
|
|||||||
<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 %}
|
||||||
@ -115,7 +133,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 storag-->
|
<!-- Modal to change current storage-->
|
||||||
{% 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 %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user