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

circulation: due date hours set to end of day #440

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PyYAML = ">=3.13"
rero-ils = {editable = true, path = "."}
uwsgi = ">=2.0"
invenio-oaiharvester = {ref = "v1.0.0a4", git = "https://github.com/inveniosoftware/invenio-oaiharvester.git"}
invenio-circulation = {ref = "v1.0.0a14", git = "https://github.com/inveniosoftware/invenio-circulation.git"}
invenio-circulation = {ref = "v1.0.0a16", git = "https://github.com/inveniosoftware/invenio-circulation.git"}
pipenv = "*"
requests = ">=2.20.0"
flask-oauthlib = "*"
Expand Down
34 changes: 17 additions & 17 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 22 additions & 23 deletions rero_ils/modules/items/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def wrapper(item, *args, **kwargs):
loan = None
web_request = False
patron_pid = kwargs.get('patron_pid')
loan_pid = kwargs.get('loan_pid')
loan_pid = kwargs.get('pid')
# TODO: include in invenio-circulation
if function.__name__ == 'request' and \
not kwargs.get('pickup_location_pid'):
Expand All @@ -126,7 +126,7 @@ def wrapper(item, *args, **kwargs):
request = get_request_by_item_pid_by_patron_pid(
item_pid=item.pid, patron_pid=patron_pid)
if request:
loan = Loan.get_record_by_pid(request.get('loan_pid'))
loan = Loan.get_record_by_pid(request.get('pid'))

if not loan:
data = {
Expand All @@ -136,12 +136,12 @@ def wrapper(item, *args, **kwargs):
loan = Loan.create(data, dbcommit=True, reindex=True)
else:
raise MissingRequiredParameterError(
description="Parameter 'loan_pid' is required")
description="Parameter 'pid' is required")

# set missing parameters
kwargs['item_pid'] = item.pid
kwargs['patron_pid'] = loan.get('patron_pid')
kwargs['loan_pid'] = loan.get('loan_pid')
kwargs['pid'] = loan.pid
kwargs.setdefault(
'transaction_date', datetime.now(timezone.utc).isoformat())
if not kwargs.get('transaction_user_pid'):
Expand Down Expand Up @@ -226,18 +226,18 @@ def get_items_pid_by_document_pid(cls, document_pid):
def get_loans_by_item_pid(cls, item_pid):
"""Return any loan loans for item."""
results = current_circulation.loan_search.filter(
'term', item_pid=item_pid).source(includes='loan_pid').scan()
'term', item_pid=item_pid).source(includes='pid').scan()
for loan in results:
yield Loan.get_record_by_pid(loan.loan_pid)
yield Loan.get_record_by_pid(loan.pid)

@classmethod
def get_loan_pid_with_item_on_loan(cls, item_pid):
"""Returns loan pid for checked out item."""
search = search_by_pid(
item_pid=item_pid, filter_states=['ITEM_ON_LOAN'])
results = search.source(['loan_pid']).scan()
results = search.source(['pid']).scan()
try:
return next(results).loan_pid
return next(results).pid
except StopIteration:
return None

Expand All @@ -248,9 +248,9 @@ def get_loan_pid_with_item_in_transit(cls, item_pid):
item_pid=item_pid, filter_states=[
"ITEM_IN_TRANSIT_FOR_PICKUP",
"ITEM_IN_TRANSIT_TO_HOUSE"])
results = search.source(['loan_pid']).scan()
results = search.source(['pid']).scan()
try:
return next(results).loan_pid
return next(results).pid
except StopIteration:
return None

Expand All @@ -273,14 +273,14 @@ def get_pendings_loans(cls, library_pid):
raise Exception('Invalid Library PID')

results = current_circulation.loan_search\
.source(['loan_pid'])\
.source(['pid'])\
.params(preserve_order=True)\
.filter('term', state='PENDING')\
.filter('term', library_pid=library_pid)\
.sort({'transaction_date': {'order': 'asc'}})\
.scan()
for loan in results:
yield Loan.get_record_by_pid(loan.loan_pid)
yield Loan.get_record_by_pid(loan.pid)

@classmethod
def get_checked_out_loans(cls, patron_pid):
Expand All @@ -290,14 +290,14 @@ def get_checked_out_loans(cls, patron_pid):
if not patron:
raise InvalidRecordID('Invalid Patron PID')
results = current_circulation.loan_search\
.source(['loan_pid'])\
.source(['pid'])\
.params(preserve_order=True)\
.filter('term', state='ITEM_ON_LOAN')\
.filter('term', patron_pid=patron_pid)\
.sort({'transaction_date': {'order': 'asc'}})\
.scan()
for loan in results:
yield Loan.get_record_by_pid(loan.loan_pid)
yield Loan.get_record_by_pid(loan.pid)

@classmethod
def get_checked_out_items(cls, patron_pid):
Expand All @@ -320,10 +320,10 @@ def get_requests(self):
'ITEM_AT_DESK',
'ITEM_IN_TRANSIT_FOR_PICKUP'
]).params(preserve_order=True)\
.source(['loan_pid'])\
.source(['pid'])\
.sort({'transaction_date': {'order': 'asc'}})
for result in search.scan():
yield Loan.get_record_by_pid(result.loan_pid)
yield Loan.get_record_by_pid(result.pid)

@classmethod
def get_requests_to_validate(cls, library_pid):
Expand Down Expand Up @@ -622,12 +622,11 @@ def checkin(self, current_loan, **kwargs):
requests = self.number_of_requests()
if requests:
request = next(self.get_requests())
requested_loan = Loan.get_record_by_pid(request.get('loan_pid'))
requested_loan = Loan.get_record_by_pid(request.get('pid'))
pickup_location_pid = requested_loan.get('pickup_location_pid')
if self.last_location_pid == pickup_location_pid:
if loan.is_active:
item, cancel_action = self.cancel_loan(
loan_pid=loan.get('loan_pid'))
item, cancel_action = self.cancel_loan(pid=loan.pid)
item, validate_action = self.validate_request(**request)
return self, actions

Expand Down Expand Up @@ -660,7 +659,7 @@ def automatic_checkin(self):
"""Apply circ transactions for item."""
if self.status == ItemStatus.ON_LOAN:
loan_pid = self.get_loan_pid_with_item_on_loan(self.pid)
return self.checkin(loan_pid=loan_pid)
return self.checkin(pid=loan_pid)

elif self.status == ItemStatus.IN_TRANSIT:
do_receive = False
Expand All @@ -676,7 +675,7 @@ def automatic_checkin(self):
== transaction_location_pid:
do_receive = True
if do_receive:
return self.receive(loan_pid=loan_pid)
return self.receive(pid=loan_pid)
return self, {
LoanAction.NO: None
}
Expand All @@ -695,9 +694,9 @@ def lose(self):
"""
# cancel all actions if it is possible
for loan in self.get_loans_by_item_pid(self.pid):
loan_pid = loan['loan_pid']
loan_pid = loan['pid']
try:
self.cancel_loan(loan_pid=loan_pid)
self.cancel_loan(pid=loan_pid)
except NoValidTransitionAvailableError:
pass
self['status'] = ItemStatus.MISSING
Expand Down
12 changes: 6 additions & 6 deletions rero_ils/modules/items/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,20 @@ def librarian_request(item, data):

def prior_checkout_actions(item, data):
"""Actions executed prior to a checkout."""
if data.get('loan_pid'):
loan = Loan.get_record_by_pid(data.get('loan_pid'))
if data.get('pid'):
loan = Loan.get_record_by_pid(data.get('pid'))
if (
loan.get('state') == 'ITEM_IN_TRANSIT_FOR_PICKUP' and
loan.get('patron_pid') == data.get('patron_pid')
):
item.receive(**data)
if loan.get('state') == 'ITEM_IN_TRANSIT_TO_HOUSE':
item.cancel_loan(loan_pid=loan.get('loan_pid'))
del data['loan_pid']
item.cancel_loan(pid=loan.get('pid'))
del data['pid']
else:
loan = get_loan_for_item(item.pid)
if loan:
item.cancel_loan(loan_pid=loan.get('loan_pid'))
item.cancel_loan(pid=loan.get('pid'))
return data


Expand Down Expand Up @@ -282,7 +282,7 @@ def item(item_barcode):
abort(404)
loan = get_loan_for_item(item.pid)
if loan:
loan = Loan.get_record_by_pid(loan['loan_pid']).dumps_for_circulation()
loan = Loan.get_record_by_pid(loan.get('pid')).dumps_for_circulation()
item_dumps = item.dumps_for_circulation()
patron_pid = flask_request.args.get('patron_pid')

Expand Down
Loading