Skip to content

Commit

Permalink
RECORDS: can_delete fix for item and patron tyspes
Browse files Browse the repository at this point in the history
* FIX Fixes es query for finding item and patron types links
closes #227

Signed-off-by: Aly Badr <[email protected]>
  • Loading branch information
Aly Badr authored and rerowep committed Mar 25, 2019
1 parent a954f7a commit 0d66a54
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
27 changes: 13 additions & 14 deletions rero_ils/modules/item_types/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from functools import partial

from elasticsearch_dsl import Q
from invenio_search.api import RecordsSearch

from .models import ItemTypeIdentifier
Expand Down Expand Up @@ -65,19 +66,6 @@ class ItemType(IlsRecord):
fetcher = item_type_id_fetcher
provider = ItemTypeProvider

# @property
# def can_delete(self):
# """Record can be deleted."""
# from ..documents_items.api import DocumentsSearch

# search = (
# DocumentsSearch()
# .filter('term', **{'itemslist.item_type_pid': self.pid})
# .source()
# .scan()
# )
# return search.count() == 0

@classmethod
def get_pid_by_name(cls, name):
"""Get pid by name."""
Expand Down Expand Up @@ -123,7 +111,18 @@ def get_number_of_items(self):
def get_number_of_circ_policies(self):
"""Get number of circulation policies."""
results = CircPoliciesSearch().filter(
'term', settings__patron_type__pid=self.pid).source().count()
'nested',
path='settings',
query=Q(
'bool',
must=[
Q(
'match',
settings__item_type__pid=self.pid
)
]
)
).source().count()
return results

def get_links_to_me(self):
Expand Down
29 changes: 13 additions & 16 deletions rero_ils/modules/patron_types/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from functools import partial

from elasticsearch_dsl import Q
from invenio_search.api import RecordsSearch

from .models import PatronTypeIdentifier
Expand Down Expand Up @@ -66,21 +67,6 @@ class PatronType(IlsRecord):
fetcher = patron_type_id_fetcher
provider = PatronTypeProvider

# @property
# def can_delete(self):
# """Record can be deleted."""
# from ..patrons.api import PatronsSearch

# count = len(
# list(
# PatronsSearch()
# .filter('term', **{'patron_type_pid': self.pid})
# .source()
# .scan()
# )
# )
# return count == 0

@classmethod
def exist_name_and_organisation_pid(cls, name, organisation_pid):
"""Check if the name is unique on organisation."""
Expand All @@ -106,7 +92,18 @@ def get_number_of_patrons(self):
def get_number_of_circ_policies(self):
"""Get number of circulation policies."""
results = CircPoliciesSearch().filter(
'term', settings__item_type__pid=self.pid).source().count()
'nested',
path='settings',
query=Q(
'bool',
must=[
Q(
'match',
settings__patron_type__pid=self.pid
)
]
)
).source().count()
return results

def get_links_to_me(self):
Expand Down

0 comments on commit 0d66a54

Please sign in to comment.