added verbose name to storages to be printed on labels etc.

This commit is contained in:
Stefan Strobel 2024-11-16 13:22:59 +01:00
parent 50ecaa2cc0
commit a77f46d697
7 changed files with 29 additions and 3 deletions

View File

@ -29,7 +29,7 @@ class StorageSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = parts_models.Storage
fields = ['url', 'id', 'name', 'parent_storage', 'responsible', 'full_path']
fields = ['url', 'id', 'name', 'verbose_name', 'parent_storage', 'responsible', 'template', 'full_path']
class ComponentSerializer(serializers.HyperlinkedModelSerializer):
package_data = PackageSerializerNoLink(source='package', read_only=True)

View File

@ -92,7 +92,8 @@ class MyTestForm(forms.Form):
pass
class ChangeStorageForm(forms.Form):
storage_name = forms.CharField(label="storage_name", initial='')
storage_name = forms.CharField(label="Name", initial='')
verbose_name = forms.CharField(label="Verbose Name", initial='')
responsible = AutocompleteForeingKeyField(api_search_url='user-list',
image_field_name=None,
name_field_name='username',

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.5 on 2024-11-16 11:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('parts', '0011_auto_20241110_1242'),
]
operations = [
migrations.AddField(
model_name='storage',
name='verbose_name',
field=models.CharField(blank=True, max_length=100, null=True),
),
]

View File

@ -62,6 +62,7 @@ class Storage(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True)
name = models.CharField(max_length=100, validators=[storage_name_validator])
verbose_name = models.CharField(max_length=100, null=True, blank=True)
parent_storage = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True)
responsible = models.ForeignKey(get_user_model(), on_delete=models.SET_NULL, blank=True, null=True)

View File

@ -484,6 +484,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
context['add_storage_form'] = add_storage_form
change_storage_form = ChangeStorageForm()
change_storage_form.fields['storage_name'].initial = self.object.name
change_storage_form.fields['verbose_name'].initial = self.object.verbose_name
change_storage_form.fields['responsible'].initial = self.object.responsible.id
change_storage_form.fields['is_template'].initial = self.object.is_template
context['change_storage_form'] = change_storage_form
@ -498,6 +499,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
sub_name = f.cleaned_data['storage_name']
try:
Storage.objects.create(name=sub_name,
verbose_name=f.cleaned_data.get('verbose_name'),
parent_storage=self.object,
responsible=f.cleaned_data['responsible'],
is_template=f.cleaned_data['is_template'],
@ -514,6 +516,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
sub_name = f.cleaned_data['storage_name']
try:
self.object.name = f.cleaned_data['storage_name']
self.object.verbose_name = f.cleaned_data.get('verbose_name')
self.object.responsible = f.cleaned_data['responsible']
self.object.is_template = f.cleaned_data['is_template']
self.object.save()

View File

@ -20,6 +20,9 @@
<div class="row">
{% qr_from_text object.get_qr_code size="m" image_format="svg" %}
</div>
<div class="row">
<h4>{{storage.name}}{% if storage.verbose_name %}<small> ({{storage.verbose_name}})</small>{% endif %}</h4>
</div>
<div class="row">
{% 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 %}

View File

@ -40,7 +40,7 @@
<a href="{% url 'parts-stocks-detail' uuid=storage.id %}" class="text-decoration-none">
<li class="list-group-item list-group-item-action justify-content-between align-items-center d-flex">
<div>
<h5>{{storage.name}}</h5>
<h5>{{storage.name}}{% if storage.verbose_name %}<small> ({{storage.verbose_name}})</small>{% endif %}</h5>
Responsible: {{ storage.responsible }}
</div>
<span class="badge bg-primary rounded-pill">{{storage.get_total_stock_amount}}</span>