Skip to content

Commit

Permalink
acquisition: improve sorting for vendors and orders
Browse files Browse the repository at this point in the history
* Uses analyzers for sorting

Co-Authored-by: Lauren-D <[email protected]>
  • Loading branch information
lauren-d committed Oct 12, 2023
1 parent 33053ce commit 13c86c1
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 21 deletions.
33 changes: 28 additions & 5 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,7 @@ def _(x):
},
record_serializers_aliases={
'json': 'application/json',
'rero': 'application/rero+json'
},
search_serializers={
'application/json': 'rero_ils.modules.serializers:json_v1_search',
Expand Down Expand Up @@ -2016,7 +2017,6 @@ def _(x):
_('library'): and_term_filter('library.pid'),
_('vendor'): and_term_filter('vendor.pid'),
_('type'): and_term_filter('type'),
_('status'): and_term_filter('status'),
_('account'): and_term_filter('order_lines.account.pid'),
_('budget'): and_term_filter('budget.pid'),
_('order_date'): range_filter(
Expand All @@ -2032,6 +2032,9 @@ def _(x):
end_date_math='/d'
)
},
post_filters={
_('status'): terms_filter('status'),
}
),
entities=dict(
aggs=dict(
Expand Down Expand Up @@ -2365,6 +2368,22 @@ def _(x):
fields=['-receipts.receipt_date'], title='Receipt date',
default_order='desc'
)
RECORDS_REST_SORT_OPTIONS['acq_orders']['order_date_new'] = dict(
fields=['-order_date'], title='Order date (newest)',
default_order='desc'
)
RECORDS_REST_SORT_OPTIONS['acq_orders']['order_date_old'] = dict(
fields=['order_date'], title='Order date (oldest)',
default_order='asc'
)
RECORDS_REST_SORT_OPTIONS['acq_orders']['reference_asc'] = dict(
fields=['reference.sort'], title='Reference (asc)',
default_order='asc'
)
RECORDS_REST_SORT_OPTIONS['acq_orders']['reference_desc'] = dict(
fields=['-reference.sort'], title='Reference (desc)',
default_order='desc'
)
RECORDS_REST_DEFAULT_SORT['acq_orders'] = dict(
query='bestmatch', noquery='receipt_date')

Expand Down Expand Up @@ -2590,12 +2609,16 @@ def _(x):
query='bestmatch', noquery='name')

# ------ VENDORS SORT
RECORDS_REST_SORT_OPTIONS['vendors']['name'] = dict(
fields=['vendor_name'], title='Vendor name',
RECORDS_REST_SORT_OPTIONS['vendors']['name_asc'] = dict(
fields=['name.sort'], title='Vendor name (asc)',
default_order='asc'
)
RECORDS_REST_SORT_OPTIONS['vendors']['name_desc'] = dict(
fields=['-name.sort'], title='Vendor name (desc)',
default_order='desc'
)
RECORDS_REST_DEFAULT_SORT['vendors'] = dict(
query='bestmatch', noquery='name')
query='bestmatch', noquery='name_asc')

# ------ PATRON TRANSACTION SORT
RECORDS_REST_SORT_OPTIONS['patron_transaction_events']['created'] = dict(
Expand Down Expand Up @@ -3038,7 +3061,7 @@ def _(x):
'base_url': os.environ.get('RERO_ILS_MEF_CONCEPTS_URL', 'https://mef.rero.ch/api/concepts'),
'sources': ['idref'],
'filters': [
{'idref.bnf_type': 'genre/forme Rameau'}
{'idref.bnf_type': 'genre/forme Rameau'}
]
},
'places': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@
}
},
"form": {
"hide": true,
"navigation": {
"essential": true
},
"templateOptions": {
"wrappers": [
"card"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
"raw": {
"type": "keyword",
"ignore_above": 256
},
"sort": {
"type": "keyword",
"normalizer": "sort_normalizer",
"ignore_above": 256
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion rero_ils/modules/acquisition/acq_receipt_lines/dumpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ def dump(self, record, data):
if notes := record.get('notes', []):
data['notes'] = [note['content'] for note in notes]

order_line = record.order_line
# Add acq_account information's: pid
data['acq_account'] = {'pid': order_line.account_pid}
# Add document information's: pid, formatted title and ISBN identifiers
# (remove None values from document metadata)
document = record.order_line.document
document = order_line.document
identifiers = document.get_identifiers(
filters=[IdentifierType.ISBN],
with_alternatives=True
Expand Down
10 changes: 5 additions & 5 deletions rero_ils/modules/acquisition/acq_receipt_lines/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def _postprocess_search_hit(self, hit: dict) -> None:
:param hit: the dictionary representing an ElasticSearch search hit.
"""
metadata = hit.get('metadata', {})
if doc_pid := metadata.get('document', {}).get('pid'):
document = Document.get_record_by_pid(doc_pid)
metadata['document'] = document.dumps(
dumper=document_acquisition_dumper)
# metadata = hit.get('metadata', {})
# if doc_pid := metadata.get('document', {}).get('pid'):
# document = Document.get_record_by_pid(doc_pid)
# metadata['document'] = document.dumps(
# dumper=document_acquisition_dumper)
super()._postprocess_search_hit(hit)


Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/documents/serializers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from rero_ils.modules.organisations.api import OrganisationsSearch
from rero_ils.modules.serializers import JSONSerializer

from ..dumpers import document_replace_refs_dumper
from ..dumpers import document_replace_refs_dumper, TitleDumper
from ..dumpers.indexer import IndexerDumper
from ..extensions import TitleExtension

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"validation": {
"validators": {
"valueAlreadyExists": {
"term": "vendor_name"
"term": "name.raw"
}
},
"messages": {
Expand Down
13 changes: 9 additions & 4 deletions rero_ils/modules/vendors/mappings/v7/vendors/vendor-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
},
"name": {
"type": "text",
"copy_to": "vendor_name"
},
"vendor_name": {
"type": "keyword"
"fields": {
"raw": {
"type": "keyword"
},
"sort": {
"type": "keyword",
"normalizer": "sort_normalizer"
}
}
},
"notes": {
"properties": {
Expand Down

0 comments on commit 13c86c1

Please sign in to comment.