warehouse frontend

This commit is contained in:
hungdztrau123
2024-05-23 16:03:38 +07:00
parent 9d4d0b39a6
commit fa7283cff1
50 changed files with 1286 additions and 37 deletions

View File

@@ -191,6 +191,8 @@ class DocumentFilterSet(FilterSet):
document_type__id__none = ObjectFilter(field_name="document_type", exclude=True)
storage_path__id__none = ObjectFilter(field_name="storage_path", exclude=True)
warehouses__id__none = ObjectFilter(field_name="warehouses", exclude=True)
is_in_inbox = InboxFilter()
@@ -225,6 +227,9 @@ class DocumentFilterSet(FilterSet):
"storage_path": ["isnull"],
"storage_path__id": ID_KWARGS,
"storage_path__name": CHAR_KWARGS,
"warehouses": ["isnull"],
"warehouses__id": ID_KWARGS,
"warehouses__name": CHAR_KWARGS,
"owner": ["isnull"],
"owner__id": ID_KWARGS,
"custom_fields": ["icontains"],

View File

@@ -1,30 +0,0 @@
# Generated by Django 4.2.11 on 2024-05-15 04:18
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('documents', '1046_workflowaction_remove_all_correspondents_and_more'),
]
operations = [
migrations.CreateModel(
name='Warehouse',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=256, unique=True, verbose_name='name')),
('type', models.CharField(blank=True, choices=[(1, 'Warehouse'), (2, 'Shelf'), (3, 'Boxcase')], default=1, max_length=20, null=True)),
('owner', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='owner')),
('parent_warehouse', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='parent_warehouses', to='documents.warehouse')),
],
options={
'verbose_name': 'warehouse',
'verbose_name_plural': 'warehouses',
},
),
]

View File

@@ -0,0 +1,19 @@
# Generated by Django 4.2.11 on 2024-05-20 09:47
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('documents', '1047_warehouse_document_warehouses'),
]
operations = [
migrations.AlterField(
model_name='warehouse',
name='parent_warehouse',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='subwarehouses', to='documents.warehouse'),
),
]

View File

@@ -0,0 +1,19 @@
# Generated by Django 4.2.11 on 2024-05-20 09:50
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('documents', '1048_alter_warehouse_parent_warehouse'),
]
operations = [
migrations.AlterField(
model_name='warehouse',
name='parent_warehouse',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='subwarehouse', to='documents.warehouse'),
),
]

View File

@@ -0,0 +1,19 @@
# Generated by Django 4.2.11 on 2024-05-20 10:12
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('documents', '1049_alter_warehouse_parent_warehouse'),
]
operations = [
migrations.AlterField(
model_name='warehouse',
name='parent_warehouse',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='documents.warehouse'),
),
]

View File

@@ -0,0 +1,45 @@
# Generated by Django 4.2.11 on 2024-05-21 07:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('documents', '1050_alter_warehouse_parent_warehouse'),
]
operations = [
migrations.AlterModelOptions(
name='warehouse',
options={'ordering': ('name',), 'verbose_name': 'warehouse', 'verbose_name_plural': 'warehouses'},
),
migrations.AddField(
model_name='warehouse',
name='is_insensitive',
field=models.BooleanField(default=True, verbose_name='is insensitive'),
),
migrations.AddField(
model_name='warehouse',
name='match',
field=models.CharField(blank=True, max_length=256, verbose_name='match'),
),
migrations.AddField(
model_name='warehouse',
name='matching_algorithm',
field=models.PositiveIntegerField(choices=[(0, 'None'), (1, 'Any word'), (2, 'All words'), (3, 'Exact match'), (4, 'Regular expression'), (5, 'Fuzzy word'), (6, 'Automatic')], default=1, verbose_name='matching algorithm'),
),
migrations.AlterField(
model_name='warehouse',
name='name',
field=models.CharField(max_length=128, verbose_name='name'),
),
migrations.AddConstraint(
model_name='warehouse',
constraint=models.UniqueConstraint(fields=('name', 'owner'), name='documents_warehouse_unique_name_owner'),
),
migrations.AddConstraint(
model_name='warehouse',
constraint=models.UniqueConstraint(condition=models.Q(('owner__isnull', True)), fields=('name',), name='documents_warehouse_name_uniq'),
),
]

View File

@@ -129,7 +129,7 @@ class StoragePath(MatchingModel):
verbose_name = _("storage path")
verbose_name_plural = _("storage paths")
class Warehouse(ModelWithOwner):
class Warehouse(MatchingModel):
WAREHOUSE = "Warehouse"
SHELF = "Shelf"
@@ -140,13 +140,12 @@ class Warehouse(ModelWithOwner):
(BOXCASE, _("Boxcase")),
)
name = models.CharField(_("name"), max_length=256, unique=True)
type = models.CharField(max_length=20, null=True, blank=True,
choices=TYPE_WAREHOUSE,
default=WAREHOUSE,)
parent_warehouse = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name="parent_warehouses" )
parent_warehouse = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True )
class Meta:
class Meta(MatchingModel.Meta):
verbose_name = _("warehouse")
verbose_name_plural = _("warehouses")

View File

@@ -1756,6 +1756,10 @@ class WorkflowSerializer(serializers.ModelSerializer):
class WarehouseSerializer(MatchingModelSerializer, OwnedObjectSerializer):
document_count = serializers.SerializerMethodField()
def get_document_count(self,obj):
document = Document.objects.filter(warehouses=obj).count()
return document
class Meta:
model = Warehouse
@@ -1763,11 +1767,18 @@ class WarehouseSerializer(MatchingModelSerializer, OwnedObjectSerializer):
def to_representation(self, instance):
data = super().to_representation(instance)
document_count = self.get_document_count(instance)
data['document_count'] = document_count
if instance.parent_warehouse:
data['parent_warehouse'] = WarehouseSerializer(instance.parent_warehouse).data
parent_serializer = self.__class__(instance.parent_warehouse)
data['parent_warehouse'] = parent_serializer.data
data['parent_warehouse']['document_count'] = document_count
else:
data['parent_warehouse'] = None
return data
return data

View File

@@ -336,7 +336,7 @@ class DocumentViewSet(
ObjectOwnedOrGrantedPermissionsFilter,
)
filterset_class = DocumentFilterSet
search_fields = ("title", "correspondent__name", "content")
search_fields = ("title", "correspondent__name", "content", "warehouses")
ordering_fields = (
"id",
"title",
@@ -1519,9 +1519,18 @@ class BulkEditObjectsView(PassUserMixin):
"Error performing bulk permissions edit, check logs for more detail.",
)
elif operation == "delete" and object_type == "warehouses":
documents = Document.objects.filter(warehouses__in=object_ids)
documents.delete()
objs.delete()
elif operation == "delete":
objs.delete()
return Response({"result": "OK"})