summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2023-05-09 17:52:08 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2023-05-09 17:52:08 +0200
commitc3309b29195d6c48914534360883acd543e23e20 (patch)
tree09567953848bbc095e1eaad8abb193993512e2af /ishtar_common
parent88051c68f3fba47bf37aee7b0cb6763f04f33a02 (diff)
downloadIshtar-c3309b29195d6c48914534360883acd543e23e20.tar.bz2
Ishtar-c3309b29195d6c48914534360883acd543e23e20.zip
Fix container search for documents
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/models.py6
-rw-r--r--ishtar_common/views_item.py20
2 files changed, 21 insertions, 5 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index c4beb0bff..fd3a49789 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2569,7 +2569,7 @@ class Organization(Address, Merge, OwnPerms, BaseGenderedType, ValueGetter, Main
),
"precise_town_id": SearchAltName(
pgettext_lazy("key for text search", "precise-town"),
- "precise_town_id__cached_label",
+ "precise_town_id",
),
}
QA_EDIT = QuickAction(
@@ -4056,11 +4056,11 @@ class Document(
),
"warehouse_container": SearchAltName(
pgettext_lazy("key for text search", "warehouse-container"),
- "container__cached_label__iexact",
+ "wcontainer_id",
),
"warehouse_container_ref": SearchAltName(
pgettext_lazy("key for text search", "warehouse-container-reference"),
- "container_ref__cached_label__iexact",
+ "wcontainer_ref_id",
),
"comment": SearchAltName(
pgettext_lazy("key for text search", "comment"), "comment__iexact"
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 31a96f270..e2214d5dc 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -1066,12 +1066,28 @@ def _manage_hierarchic_fields(model, dct, and_reqs):
# TODO: improve query with "IN ()"?
continue
- if req.endswith("precise_town_id__cached_label"):
+ if req.endswith("wcontainer_id") or req.endswith("wcontainer_ref_id"):
+ val = _clean_type_val(dct.pop(req)).strip('"')
+ if val.startswith('"') and val.endswith('"'):
+ val = val[1:-1]
+ vals = [v.replace('"', "") for v in val.split(";")]
+ container_ids = []
+ for val in vals:
+ q = Container.objects.filter(cached_label__iexact=val).values_list(
+ "id", flat=True)
+ if not q.count():
+ continue
+ container_id = q.all()[0]
+ container_ids.append(container_id)
+ req = req[1:] # remove "w"
+ main_req = Q(**{req + "__in": container_ids})
+ and_reqs.append(main_req)
+
+ if req.endswith("precise_town_id"):
val = _clean_type_val(dct.pop(req)).strip('"')
if val.startswith('"') and val.endswith('"'):
val = val[1:-1]
vals = [v.replace('"', "") for v in val.split(";")]
- req = req[:-len("__cached_label")]
town_ids = []
for val in vals:
q = models.Town.objects.filter(cached_label__iexact=val).values_list(