Skip to content

Commit

Permalink
patrons: fix subscriptions renewal problem.
Browse files Browse the repository at this point in the history
The method to retrieve patrons without valid subscriptions doesn't
works as expected. Each day, a new subscription will be added for all
patrons linked to patron_type requiring a subscription, even if they
have a valid one.

Closes #1317

Co-Authored-by: Renaud Michotte <[email protected]>
Co-Authored-by: lauren-d <[email protected]>
  • Loading branch information
zannkukai and lauren-d committed Nov 5, 2020
1 parent 9247147 commit 7d905f8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions rero_ils/modules/patrons/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,7 @@ def get_patrons_without_subscription(cls, patron_type_pid):
"""Get patrons linked to patron_type that haven't any subscription."""
query = PatronsSearch() \
.filter('term', patron__type__pid=patron_type_pid) \
.filter('bool', must_not=[
Q('exists', field="patron__subscriptions")])
.exclude('exists', field='patron.subscriptions')
for res in query.source('pid').scan():
yield Patron.get_record_by_pid(res.pid)

Expand Down
4 changes: 2 additions & 2 deletions tests/api/patrons/test_patrons_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def test_patron_has_valid_subscriptions(
patron_sion.add_subscription(patron_type_grown_sion, start, end)
# !! As `add_subscription` use the method `Patron.update`, then the signal
# `after_record_update` are send by invenio_records and the patron
# listener `reate_subscription_patron_transaction` is called. This
# listener `create_subscription_patron_transaction` is called. This
# listener found that user doesn't have any subscription and add a valid
# one for this patron. So after `add_subscription` call, i just removed
# one for this patron. So after `add_subscription` call, I just removed
# the valid subscription created.
del patron_sion['patron']['subscriptions'][1]
assert not patron_sion.has_valid_subscription
Expand Down

0 comments on commit 7d905f8

Please sign in to comment.