diff --git a/Pipfile b/Pipfile index 08c5882eff..4736c189b5 100644 --- a/Pipfile +++ b/Pipfile @@ -39,7 +39,7 @@ Flask-BabelEx = ">=0.9.3" ## Third party invenio modules used by RERO ILS invenio-oaiharvester = {editable = true, ref = "v1.0.0a4", git = "https://github.com/inveniosoftware/invenio-oaiharvester.git"} # invenio-circulation = {editable = true, ref = "v1.0.0a21", git = "https://github.com/inveniosoftware/invenio-circulation.git"} -invenio-circulation = {editable = true, ref = "item_at_desk_temp", git = "https://github.com/rero/invenio-circulation.git"} +invenio-circulation = {editable = true, ref = "baa-1410-assign-item", git = "https://github.com/rero/invenio-circulation.git"} ## Invenio 3.2.1 base modules used by RERO ILS # same as invenio metadata extras without invenio-search-ui invenio-indexer = ">=1.1.1,<1.2.0" diff --git a/Pipfile.lock b/Pipfile.lock index 565a9284fa..c7755314c3 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "18530411c4419c828c3480ddfe80f58c19deaa4f23f2d268f27e0dc5e2d1b409" + "sha256": "bd63f3b315f06f4d45df3450b9014d6b81bab1f0195f3b7dcc41630506cafd41" }, "pipfile-spec": 6, "requires": { @@ -510,7 +510,7 @@ "invenio-circulation": { "editable": true, "git": "https://github.com/rero/invenio-circulation.git", - "ref": "f250b11766c5c98503271cd8e51312d1e95cfb38" + "ref": "5b586d2ca67c1aca15a793c5463a5281cda02396" }, "invenio-config": { "hashes": [ diff --git a/rero_ils/config.py b/rero_ils/config.py index bbf27930fd..0e794f2b84 100644 --- a/rero_ils/config.py +++ b/rero_ils/config.py @@ -35,8 +35,9 @@ CIRCULATION_LOAN_MINTER, CIRCULATION_LOAN_PID_TYPE from invenio_circulation.search.api import LoansSearch from invenio_circulation.transitions.transitions import CreatedToPending, \ - ItemAtDeskToItemOnLoan, ItemOnLoanToItemInTransitHouse, \ - ItemOnLoanToItemOnLoan, PendingToItemAtDesk, \ + ItemAtDeskToItemOnLoan, ItemInTransitHouseToItemReturned, \ + ItemOnLoanToItemInTransitHouse, ItemOnLoanToItemOnLoan, \ + ItemOnLoanToItemReturned, PendingToItemAtDesk, \ PendingToItemInTransitPickup, ToCancelled, ToItemOnLoan from invenio_records_rest.facets import terms_filter from invenio_records_rest.utils import allow_all, deny_all @@ -63,8 +64,6 @@ from .modules.loans.api import Loan from .modules.loans.permissions import can_list_loan_factory, \ can_read_loan_factory -from .modules.loans.transitions import ItemInTransitHouseToItemReturned, \ - ItemOnLoanToItemReturned from .modules.loans.utils import can_be_requested, get_default_loan_duration, \ get_extension_params, is_item_available_for_checkout, \ loan_build_document_ref, loan_build_item_ref, loan_build_patron_ref, \ diff --git a/rero_ils/modules/loans/transitions.py b/rero_ils/modules/loans/transitions.py deleted file mode 100644 index 55a2c9bafa..0000000000 --- a/rero_ils/modules/loans/transitions.py +++ /dev/null @@ -1,119 +0,0 @@ -# -*- coding: utf-8 -*- -# -# RERO ILS -# Copyright (C) 2019 RERO -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, version 3 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -"""REROILS Circulation custom transitions.""" - - -from invenio_circulation.api import get_document_pid_by_item_pid, \ - get_pending_loans_by_doc_pid -from invenio_circulation.proxies import current_circulation -from invenio_circulation.transitions.base import Transition -from invenio_circulation.transitions.transitions import \ - _ensure_same_location as _ensure_same_location -from invenio_circulation.transitions.transitions import ensure_same_item -from invenio_db import db - -from ..documents.api import Document - - -def _update_document_pending_request_for_item(item_pid, **kwargs): - """Update pending loans on a Document with no Item attached yet. - - :param item_pid: a dict containing `value` and `type` fields to - uniquely identify the item. - """ - document_pid = get_document_pid_by_item_pid(item_pid) - document = Document.get_record_by_pid(document_pid) - if document.get_number_of_items() == 1: - for pending_loan in get_pending_loans_by_doc_pid(document_pid): - pending_loan['item_pid'] = item_pid - pending_loan.commit() - db.session.commit() - current_circulation.loan_indexer().index(pending_loan) - - -class ItemInTransitHouseToItemReturned(Transition): - """Check-in action when returning an item to its belonging location.""" - - def __init__( - self, src, dest, trigger="next", permission_factory=None, **kwargs - ): - """Constructor.""" - super().__init__( - src, - dest, - trigger=trigger, - permission_factory=permission_factory, - **kwargs - ) - self.assign_item = kwargs.get("assign_item", True) - - @ensure_same_item - def before(self, loan, **kwargs): - """Validate check-in action.""" - super().before(loan, **kwargs) - - _ensure_same_location( - loan['item_pid'], - loan['transaction_location_pid'], - self.dest, - error_msg="Item should be in transit to house.", - ) - - def after(self, loan): - """Check for pending requests on this item after check-in.""" - super().after(loan) - if self.assign_item: - _update_document_pending_request_for_item(loan['item_pid']) - - -class ItemOnLoanToItemReturned(Transition): - """Check-in action when returning an item to its belonging location.""" - - def __init__( - self, src, dest, trigger="next", permission_factory=None, **kwargs - ): - """Constructor.""" - super().__init__( - src, - dest, - trigger=trigger, - permission_factory=permission_factory, - **kwargs - ) - self.assign_item = kwargs.get("assign_item", True) - - @ensure_same_item - def before(self, loan, **kwargs): - """Validate check-in action.""" - super().before(loan, **kwargs) - - _ensure_same_location( - loan['item_pid'], - loan['transaction_location_pid'], - self.dest, - error_msg="Item should be in transit to house.", - ) - - # set end loan date as transaction date when completing loan - loan['end_date'] = loan['transaction_date'] - - def after(self, loan): - """Check for pending requests on this item after check-in.""" - super().after(loan) - if self.assign_item: - _update_document_pending_request_for_item(loan['item_pid'])