Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscription: adds listener methods to create a subscription if needed #868

Merged

Conversation

zannkukai
Copy link
Contributor

When a patron is create/updated, if the patron is linked to a patron type requiring a subscription,
we need to create a subscription transaction if the patron doesn"t have any current one.
This is the purpose of this PR.

  • Adds a listerner method for patron signals : after_record_create, after_record_update
  • Adds unit tests

How to test?

  • Edit a patron_type to have one with a yearly subscription

  • Create a new patron and assign it with this patron_type

  • Check the patron fee tabs, you should see a new subscription fee

  • Update this patron to assign it to a patron_type without subscription

  • Update again this patron to re-assign it the patron_type with a subscription

  • No new fee should be assign to the patron

  • Search for a patron previously linked to the patron_type with subscription

  • Edit this patron

  • Check this patron has now a subscription fee.

Code review check list

  • Commit message template compliance.
  • Commit message without typos.
  • File names.
  • Functions names.
  • Functions docstrings.
  • Unnecessary commited files?
  • Extracted translations?

@zannkukai zannkukai added the WIP label Mar 27, 2020
@zannkukai zannkukai self-assigned this Mar 27, 2020
@zannkukai zannkukai force-pushed the zan-#1362-listener-create-subscription branch 8 times, most recently from 6947836 to bc5f6a8 Compare March 31, 2020 14:55
@zannkukai zannkukai removed the WIP label Mar 31, 2020
@zannkukai zannkukai force-pushed the zan-#1362-listener-create-subscription branch from bc5f6a8 to 6abf0b5 Compare March 31, 2020 16:49
rero_ils/modules/patrons/listener.py Show resolved Hide resolved
rero_ils/modules/patrons/api.py Outdated Show resolved Hide resolved
rero_ils/modules/patrons/listener.py Show resolved Hide resolved
rero_ils/modules/utils.py Show resolved Hide resolved
tests/unit/test_utils.py Outdated Show resolved Hide resolved
Copy link

@BadrAly BadrAly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest something like this:

    def get_transactions_pids_for_patron(cls, patron_pid, status=None, count=False):
        query = PatronTransactionsSearch()\
            .filter("term", patron__pid=patron_pid)
        if status:
            query = query.filter("term", status=status)
        if count:
        	return query.source("pid").count()
        results = query.source("pid").scan()
        for result in results:
            yield result.pid

so you can replace get_number_of_open_transactions by
get_transactions_pids_for_patron(self.pid, status="open", count=True)
This will address also the comment of Peter regarding the list and keep the nice function you have created to return the open transactions for a patron

EDIT: (Renaud Michotte)
After testing, we can"t use yield and return in the same function. If Python found usage of yield in a function it always return a generator despite if yield is not reached.
I will create two separate functions

@zannkukai zannkukai force-pushed the zan-#1362-listener-create-subscription branch from 6abf0b5 to 56c7438 Compare April 1, 2020 08:23
@zannkukai zannkukai requested review from BadrAly and rerowep April 1, 2020 08:23
rero_ils/modules/patrons/api.py Outdated Show resolved Hide resolved
@zannkukai zannkukai force-pushed the zan-#1362-listener-create-subscription branch from 56c7438 to 85c0151 Compare April 2, 2020 18:55
@zannkukai zannkukai requested a review from BadrAly April 2, 2020 18:56
@zannkukai zannkukai force-pushed the zan-#1362-listener-create-subscription branch from 85c0151 to aa4acf8 Compare April 2, 2020 19:23
@zannkukai zannkukai force-pushed the zan-#1362-listener-create-subscription branch from aa4acf8 to d40a6cb Compare April 6, 2020 12:32
Copy link

@BadrAly BadrAly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some typos, you can fix if you resend the commit. otherwise, it is acceptable.
tow_years_later -> two_years_later
linke -> link

@zannkukai zannkukai force-pushed the zan-#1362-listener-create-subscription branch from d40a6cb to 674288d Compare April 6, 2020 14:33
@zannkukai zannkukai force-pushed the zan-#1362-listener-create-subscription branch from 674288d to b9a1542 Compare April 6, 2020 20:26
@zannkukai zannkukai force-pushed the zan-#1362-listener-create-subscription branch 2 times, most recently from cff453e to fa99d3e Compare April 7, 2020 10:19
rero_ils/modules/patron_transactions/api.py Outdated Show resolved Hide resolved
tests/unit/conftest.py Outdated Show resolved Hide resolved
When a patron is create/updated, if the patron is linked to a patron type requiring a subscription,
we need to create a subscription transaction if the patron doesn"t have any current one.
This is the purpose of this PR.

* Adds a listener method for patron signals : after_record_create, after_record_update
* Adds unit tests

Co-Authored-by: Renaud Michotte <[email protected]>
@zannkukai zannkukai force-pushed the zan-#1362-listener-create-subscription branch from fa99d3e to 26d3030 Compare April 7, 2020 13:43
@zannkukai zannkukai merged commit e71562c into rero:US1297 Apr 7, 2020
@zannkukai zannkukai deleted the zan-#1362-listener-create-subscription branch April 21, 2020 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants