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

transition: implement extension of a loan #55

Merged
merged 1 commit into from
Aug 17, 2018
Merged

transition: implement extension of a loan #55

merged 1 commit into from
Aug 17, 2018

Conversation

rerowep
Copy link
Contributor

@rerowep rerowep commented Aug 2, 2018

* (closes #49)

Signed-off-by: Peter Weber Peter.Weber@rero.ch
Co-authored-by: Igor Milhit Igor.Milhit@rero.ch

Copy link
Member

@topless topless left a 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):
Copy link
Member

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(
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor

@jma jma Aug 7, 2018

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:
Copy link
Member

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'])
Copy link
Member

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):
Copy link
Member

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.

Copy link
Contributor Author

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,
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

@rerowep rerowep Aug 7, 2018

Choose a reason for hiding this comment

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

@zzacharo Yes this will be very helpful and I think this will be added with the task Write docstrings and documentation #30

Copy link
Contributor

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.

@@ -102,6 +106,11 @@
duration_validate=is_loan_duration_valid,
item_available=is_item_available
),
extension=dict(
from_end_date=extend_from_end_date,
Copy link
Contributor

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.

@@ -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,
Copy link
Contributor

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()
Copy link
Contributor

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.

return float("inf")


def extend_from_end_date(loan):
Copy link
Contributor

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,
Copy link
Contributor

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>
@ntarocco ntarocco merged commit 21a702c into inveniosoftware:master Aug 17, 2018
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.

5 participants