summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_warehouse/forms.py48
-rw-r--r--archaeological_warehouse/migrations/0121_auto_20240110_1511.py23
-rw-r--r--archaeological_warehouse/models.py5
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_container.html1
-rw-r--r--archaeological_warehouse/views.py12
-rw-r--r--changelog/en/changelog_2022-06-15.md1
-rw-r--r--changelog/fr/changelog_2023-01-25.md1
-rw-r--r--locale/fr/LC_MESSAGES/django.po4
8 files changed, 68 insertions, 27 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py
index acb2a2e50..f083785b5 100644
--- a/archaeological_warehouse/forms.py
+++ b/archaeological_warehouse/forms.py
@@ -337,6 +337,7 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form):
"parent": models.Container,
}
reference = forms.CharField(label=_("Ref."), max_length=200)
+ code = forms.CharField(label=_("Code"), max_length=200, required=False)
old_reference = forms.CharField(
label=_("Old reference"), required=False, max_length=200
)
@@ -407,28 +408,32 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form):
def clean(self):
cleaned_data = self.cleaned_data
warehouse = cleaned_data.get("location")
- q = models.Container.objects.filter(
- reference=cleaned_data.get("reference"),
- location__pk=warehouse,
- container_type_id=cleaned_data.get("container_type"),
- parent_id=cleaned_data.get("parent"),
- )
- pk = None
- if "pk" in cleaned_data and cleaned_data["pk"]:
- pk = int(cleaned_data["pk"])
- q = q.exclude(pk=pk)
- if q.count():
- raise forms.ValidationError(
- _("This reference already exists for " "this warehouse.")
- )
- if (
- pk
- and cleaned_data.get("parent", None)
- and pk == int(cleaned_data.get("parent"))
- ):
- raise forms.ValidationError(
- _("A container cannot be a parent of " "himself.")
+ for ref_attr in ("reference", "code"):
+ ref = cleaned_data.get(ref_attr, None)
+ if not ref:
+ continue
+ q = models.Container.objects.filter(
+ location__pk=warehouse,
+ container_type_id=cleaned_data.get("container_type"),
+ parent_id=cleaned_data.get("parent"),
)
+ q = q.filter(**{ref_attr: ref})
+ pk = None
+ if "pk" in cleaned_data and cleaned_data["pk"]:
+ pk = int(cleaned_data["pk"])
+ q = q.exclude(pk=pk)
+ if q.count():
+ raise forms.ValidationError(
+ _("This reference/code already exists for this warehouse.")
+ )
+ if (ref_attr == "reference" # only check parent for reference
+ and pk
+ and cleaned_data.get("parent", None)
+ and pk == int(cleaned_data.get("parent"))
+ ):
+ raise forms.ValidationError(
+ _("A container cannot be a parent of himself.")
+ )
return cleaned_data
def save(self, user):
@@ -509,6 +514,7 @@ class ContainerSelect(DocumentItemSelect):
responsibility_name = get_warehouse_field(label=_("Warehouse (responsibility)"))
container_type = forms.ChoiceField(label=_("Container type"), choices=[])
reference = forms.CharField(label=_("Ref."))
+ code = forms.CharField(label=_("Code"))
old_reference = forms.CharField(label=_("Old reference"))
comment = forms.CharField(label=_("Comment"))
contain_containers = forms.NullBooleanField(label=_("Contain containers"))
diff --git a/archaeological_warehouse/migrations/0121_auto_20240110_1511.py b/archaeological_warehouse/migrations/0121_auto_20240110_1511.py
new file mode 100644
index 000000000..495dc2633
--- /dev/null
+++ b/archaeological_warehouse/migrations/0121_auto_20240110_1511.py
@@ -0,0 +1,23 @@
+# Generated by Django 2.2.24 on 2024-01-10 15:11
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archaeological_warehouse', '0120_auto_20231115_1617'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='container',
+ name='code',
+ field=models.TextField(blank=True, default='', verbose_name='Code'),
+ ),
+ migrations.AddField(
+ model_name='historicalcontainer',
+ name='code',
+ field=models.TextField(blank=True, default='', verbose_name='Code'),
+ ),
+ ]
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index e04643c87..b28d0223c 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -876,6 +876,7 @@ class Container(
IMAGE_PREFIX = "containers/"
BASE_SEARCH_VECTORS = [
SearchVectorConfig("reference", "raw"),
+ SearchVectorConfig("code", "raw"),
SearchVectorConfig("container_type__label"),
SearchVectorConfig("cached_location"),
SearchVectorConfig("old_reference", "raw"),
@@ -952,6 +953,9 @@ class Container(
"reference": SearchAltName(
pgettext_lazy("key for text search", "reference"), "reference__iexact"
),
+ "code": SearchAltName(
+ pgettext_lazy("key for text search", "code"), "code__iexact"
+ ),
"old_reference": SearchAltName(
pgettext_lazy("key for text search", "old-reference"),
"old_reference__iexact",
@@ -1144,6 +1148,7 @@ class Container(
on_delete=models.PROTECT,
)
reference = models.TextField(_("Container ref."))
+ code = models.TextField(_("Code"), blank=True, default="")
comment = models.TextField(_("Comment"), blank=True, default="")
cached_location = models.TextField(
_("Cached location"), blank=True, default="", db_index=True
diff --git a/archaeological_warehouse/templates/ishtar/sheet_container.html b/archaeological_warehouse/templates/ishtar/sheet_container.html
index eed28ca5b..ff0cd0de7 100644
--- a/archaeological_warehouse/templates/ishtar/sheet_container.html
+++ b/archaeological_warehouse/templates/ishtar/sheet_container.html
@@ -123,6 +123,7 @@
{% if item.responsibility != item.location %}
{% field_flex_detail "Responsibility" item.responsibility %}
{% endif %}
+ {% field_flex "Code" item.code %}
{% field_flex "Old reference" item.old_reference %}
{% with calculated_weight_percent=item.get_calculated_weight_percent%}
{% trans "Measured weight (kg)" as weight_kg_trans %}
diff --git a/archaeological_warehouse/views.py b/archaeological_warehouse/views.py
index 982d7dea2..c608f50a0 100644
--- a/archaeological_warehouse/views.py
+++ b/archaeological_warehouse/views.py
@@ -150,7 +150,7 @@ def autocomplete_container(request, warehouse_id=None):
except ValueError:
containers = []
# exact ref
- query = query & Q(reference__unaccent__iexact=term)
+ query = query & (Q(reference__unaccent__iexact=term) | Q(code__unaccent__iexact=term))
containers += list(
models.Container.objects.filter(query).values("id", "cached_label")[:limit]
)
@@ -166,6 +166,7 @@ def autocomplete_container(request, warehouse_id=None):
(c[0], unidecode(c[1]).lower())
for c in models.ContainerType.objects.values_list("id", "label")
]
+ # manage container type search term
for container_type_id, value in container_types:
value = unidecode(value).lower()
if value in unidecode(term).lower(): # container_type is in search q
@@ -235,7 +236,9 @@ def autocomplete_container(request, warehouse_id=None):
group_2 = splitted[idx:]
extra = Q(
container_type__label__unaccent__iexact=" ".join(group_1),
- reference__unaccent__iexact=" ".join(group_2),
+ ) & (
+ Q(reference__unaccent__iexact=" ".join(group_2)) |
+ Q(code__unaccent__iexact=" ".join(group_2))
)
query = base_query & extra
ids = {c["id"] for c in containers}
@@ -250,8 +253,8 @@ def autocomplete_container(request, warehouse_id=None):
if len(containers) < 15:
query = base_query
for q in splitted:
- extra = Q(reference__unaccent__iexact=q)
- query = query & extra
+ extra = Q(reference__unaccent__iexact=q) | Q(code__unaccent__iexact=q)
+ query &= extra
ids = {c["id"] for c in containers}
containers += list(
models.Container.objects.filter(query)
@@ -266,6 +269,7 @@ def autocomplete_container(request, warehouse_id=None):
Q(container_type__label__unaccent__icontains=q)
| Q(container_type__reference__unaccent__icontains=q)
| Q(reference__unaccent__icontains=q)
+ | Q(code__unaccent__icontains=q)
| Q(cached_label__unaccent__icontains=q)
)
if not warehouse_id:
diff --git a/changelog/en/changelog_2022-06-15.md b/changelog/en/changelog_2022-06-15.md
index b0486623c..19767fb1e 100644
--- a/changelog/en/changelog_2022-06-15.md
+++ b/changelog/en/changelog_2022-06-15.md
@@ -6,6 +6,7 @@ v4.0.XX - 2099-12-31
- add coordinates display
- get coordinates from geolocalisation
- geo sheet: display point buffer
+- Container: new field Code (forms, sheet, search index and autocomplete) (#5704)'
#### Imports #####
- pre-import forms
diff --git a/changelog/fr/changelog_2023-01-25.md b/changelog/fr/changelog_2023-01-25.md
index 19344b32f..106207f96 100644
--- a/changelog/fr/changelog_2023-01-25.md
+++ b/changelog/fr/changelog_2023-01-25.md
@@ -6,6 +6,7 @@ v4.0.XX - 2099-12-31
- affichage des coordonnées
- obtention des coordonnées depuis la géolocalisation
- fiche géographique: affichage du tampon du point
+- Contenant : nouveau champ Code (formulaires, fiche, index de recherche et autocomplétion) (#5704)
#### Imports #####
diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po
index 649700118..2080c133b 100644
--- a/locale/fr/LC_MESSAGES/django.po
+++ b/locale/fr/LC_MESSAGES/django.po
@@ -6257,8 +6257,8 @@ msgstr "Attributions culturelles"
#: archaeological_operations/forms.py:1154
#: archaeological_operations/forms.py:1382
#: archaeological_operations/forms.py:1821
-msgid "This reference already exists."
-msgstr "Cette référence existe déjà."
+msgid "This reference/code already exists."
+msgstr "Cette référence/ce code existe déjà."
#: archaeological_operations/forms.py:1198
msgid "Would you like to close this operation?"