Further improve stuff nad add model fro print jobs
This commit is contained in:
parent
38bca5caf9
commit
c4a26f8a98
@ -16,10 +16,12 @@ class AutoCompleteWidget(widgets.Input):
|
|||||||
|
|
||||||
def get_context(self, name, value, attrs):
|
def get_context(self, name, value, attrs):
|
||||||
context = super().get_context(name, value, attrs)
|
context = super().get_context(name, value, attrs)
|
||||||
try:
|
if value is not None:
|
||||||
instance = self.foreign_model.objects.get(id=uuid.UUID(value))
|
try:
|
||||||
except Exception as ex:
|
instance = self.foreign_model.objects.get(id=uuid.UUID(value))
|
||||||
print(ex)
|
except Exception as ex:
|
||||||
|
instance = None
|
||||||
|
else:
|
||||||
instance = None
|
instance = None
|
||||||
|
|
||||||
image = None
|
image = None
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2022-01-01 12:50
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('parts', '0007_stock_lot'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='stock',
|
||||||
|
name='lot',
|
||||||
|
field=models.CharField(blank=True, default='', max_length=255),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='QrPrintJob',
|
||||||
|
fields=[
|
||||||
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
|
||||||
|
('qrdata', models.CharField(blank=True, max_length=256)),
|
||||||
|
('text', models.TextField(blank=True, max_length=512)),
|
||||||
|
('print_count', models.PositiveIntegerField(default=1, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(32)])),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
@ -5,6 +5,7 @@ from django.contrib.auth.models import User as AuthUser
|
|||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.validators import RegexValidator
|
from django.core.validators import RegexValidator
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@ -227,7 +228,7 @@ class Stock(models.Model):
|
|||||||
storage = models.ForeignKey(Storage, on_delete=models.PROTECT, blank=True, null=True)
|
storage = models.ForeignKey(Storage, on_delete=models.PROTECT, blank=True, null=True)
|
||||||
amount = models.PositiveIntegerField()
|
amount = models.PositiveIntegerField()
|
||||||
watermark = models.IntegerField() # negative is no watermark
|
watermark = models.IntegerField() # negative is no watermark
|
||||||
lot = models.CharField(max_length=255, null=True, blank=True)
|
lot = models.CharField(max_length=255, null=False, blank=True)
|
||||||
|
|
||||||
def atomic_increment(self, increment):
|
def atomic_increment(self, increment):
|
||||||
if self.amount + increment < 0:
|
if self.amount + increment < 0:
|
||||||
@ -266,6 +267,18 @@ class DistributorNum(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.component.name + '@' + self.distributor.name + ': ' + self.distributor_part_number
|
return self.component.name + '@' + self.distributor.name + ': ' + self.distributor_part_number
|
||||||
|
|
||||||
|
class QrPrintJob(models.Model):
|
||||||
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True)
|
||||||
|
user = models.ForeignKey(AuthUser, on_delete=models.CASCADE, null=False, blank=False)
|
||||||
|
qrdata = models.CharField(max_length=256, blank=True, null=False)
|
||||||
|
text = models.TextField(max_length=512, blank=True, null=False)
|
||||||
|
print_count = models.PositiveIntegerField(default=1, validators=[MinValueValidator(0), MaxValueValidator(32)])
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
super().clean()
|
||||||
|
if self.qrdata == '' and self.text == '':
|
||||||
|
raise ValidationError('Either QR Data or text must be set')
|
||||||
|
|
||||||
# These functions ensure that the uploaded images are deleted if the model is deleted or the image file is changed.
|
# These functions ensure that the uploaded images are deleted if the model is deleted or the image file is changed.
|
||||||
@receiver(models.signals.post_delete, sender=Component)
|
@receiver(models.signals.post_delete, sender=Component)
|
||||||
@receiver(models.signals.post_delete, sender=Distributor)
|
@receiver(models.signals.post_delete, sender=Distributor)
|
||||||
|
@ -119,7 +119,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<form action="" method="post">
|
<form action="" method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{comp_form|crispy}}
|
{{comp_form|crispy}}
|
||||||
<input type="submit" name="submit-edit-component" value="Submit">
|
<input type="submit" name="submit-edit-component" value="Submit">
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<input autocomplete="off" id="{{widget.attrs.id}}-search-input" data-ac-url="{{custom.search_url}}" data-bs-toggle="dropdown" class="form-control{% if widget.errors %} is-invalid{% endif %}" type="text" placeholder="Search...">
|
<input autocomplete="off" id="{{widget.attrs.id}}" data-ac-url="{{custom.search_url}}" data-bs-toggle="dropdown" type="text" placeholder="Search..." class="{{widget.attrs.class}}">
|
||||||
<ul id="{{widget.attrs.id}}-ac-ul" class="dropdown-menu">
|
<ul id="{{widget.attrs.id}}-ac-ul" class="dropdown-menu">
|
||||||
</ul>
|
</ul>
|
||||||
<div class="d-flex align-items-center" id="{{widget.attrs.id}}-dflex-container">
|
<div class="d-flex align-items-center" id="{{widget.attrs.id}}-dflex-container">
|
||||||
|
Loading…
Reference in New Issue
Block a user