-
Notifications
You must be signed in to change notification settings - Fork 18
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
transition: implement extension of a loan #55
transition: implement extension of a loan #55
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noted a few things down that got my attention, as an initial step to further discussion, I am not fully aware of all the necessities so please feel free to comment further.
@@ -18,7 +18,7 @@ | |||
from ..utils import parse_date | |||
|
|||
|
|||
def _ensure_valid_loan_duration(loan): | |||
def _ensure_valid_loan_duration(loan, from_end_date=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from_end_date
is not used anywhere in the function.
@@ -90,6 +93,11 @@ | |||
duration_validate=is_loan_duration_valid, | |||
item_available=is_item_available | |||
), | |||
extension=dict( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the extension policies, I noticed that the initialisation of it, happens at utils.py
, and it is a static one. I would suggest to replace the functions with the actual values here. It is going to be cleaner, and if anyone needs to override it, they can do it in place. Either if there was some logic in the calculation of initial values I think it should be under a config
property i.e. CIRCULATION_EXTENSION_CONDITION
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment: #55 (comment)
"""Validate end dates for a extended loan.""" | ||
get_extension_max_count = current_app.config['CIRCULATION_POLICIES'][ | ||
'extension']['max_count'] | ||
extension_max_count = get_extension_max_count(loan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there is a mix of concerns, extension_max_count
is a policy and get_extention_max_count
takes loan as a parameter. If loan has anything to do with it extention_max_count could be a property of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the same as the checkout policies. It enables the calculation of future complex policies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this policy to be overriden or extendable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zzacharo extendable for sure! For example, extension_max_count
will probably depends on patron type or item type. This mechanism should be also added to the request.
|
||
extension_count = loan.get('extension_count', 0) | ||
extension_count += 1 | ||
if extension_max_count != -1 and extension_count > extension_max_count + 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implied logic of infinity is difficult to follow, and logically incorrect, because the extension_count
here has to be strictly greater than the max_count
increased by one, so its not the max. I would initialise the extension_max_count
with a big number.
'CIRCULATION_POLICIES']['extension']['from_end_date'] | ||
from_end_date = get_extension_from_end_date(loan) | ||
|
||
end_date = parse_date(loan['end_date']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be like
end_date = datetime.now() + timedelta(days=number_of_days)
if from_end_date:
end_date = parse_date(loan['end_date']) + timedelta(days=number_of_days)
@@ -38,6 +38,25 @@ def get_default_loan_duration(loan): | |||
return 30 | |||
|
|||
|
|||
def get_default_extension_duration(loan): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we move the initial values to config.py
these can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spoke to the librarians and they're saying it should be possible to calculate these values similarly as for the checkout
@@ -54,6 +55,40 @@ def test_loan_request(db, params): | |||
assert loan['state'] == 'PENDING' | |||
|
|||
|
|||
def test_loan_extend(loan_created, db, params, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are testing more than aspects in this test, could be split in more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to have one test for the extension even if we test two aspects of it. Otherwise we have to reinit the loan a second time to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be really helpful to put some comments in order to follow the scenario that is tested. Just for the future us to be able to understand really quick the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two cases should be tested from_end_date == True
and from_end_date == False
. It can be in two different test functions.
invenio_circulation/config.py
Outdated
@@ -102,6 +106,11 @@ | |||
duration_validate=is_loan_duration_valid, | |||
item_available=is_item_available | |||
), | |||
extension=dict( | |||
from_end_date=extend_from_end_date, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duration_default
and max_count
can be changed by the ILS, but from_en_date
is just a boolean. Thus we can replace extend_from_end_date
can be removed by a boolean value.
invenio_circulation/config.py
Outdated
@@ -102,6 +106,11 @@ | |||
duration_validate=is_loan_duration_valid, | |||
item_available=is_item_available | |||
), | |||
extension=dict( | |||
from_end_date=extend_from_end_date, | |||
duration_default=get_default_extension_duration, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename duration_default
by duration
. We can do the same for checkout
policy.
|
||
end_date = parse_date(loan['end_date']) | ||
if not get_extension_from_end_date(loan): | ||
end_date = datetime.now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be replaced by transaction_date
.
invenio_circulation/utils.py
Outdated
return float("inf") | ||
|
||
|
||
def extend_from_end_date(loan): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed.
@@ -54,6 +55,40 @@ def test_loan_request(db, params): | |||
assert loan['state'] == 'PENDING' | |||
|
|||
|
|||
def test_loan_extend(loan_created, db, params, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two cases should be tested from_end_date == True
and from_end_date == False
. It can be in two different test functions.
* (closes #49) Signed-off-by: Peter Weber <Peter.Weber@rero.ch> Co-authored-by: Igor Milhit <Igor.Milhit@rero.ch>
Signed-off-by: Peter Weber Peter.Weber@rero.ch
Co-authored-by: Igor Milhit Igor.Milhit@rero.ch