From 95babd95f4858edd019c14443b9d99c39801c44f Mon Sep 17 00:00:00 2001 From: Peter Weber Date: Wed, 27 Nov 2024 14:18:17 +0100 Subject: [PATCH] loan: fix organisation_pid function * Closes #3710 * Cleans code for `organisation_pid` function. Co-Authored-by: Peter Weber --- rero_ils/modules/acquisition/acq_invoices/api.py | 5 ----- rero_ils/modules/acquisition/acq_orders/api.py | 3 +-- rero_ils/modules/acquisition/acq_receipts/api.py | 5 ----- rero_ils/modules/holdings/api.py | 2 +- rero_ils/modules/loans/api.py | 11 +---------- rero_ils/modules/locations/api.py | 5 +---- scripts/test | 4 +++- tests/api/circulation/test_locations_restrictions.py | 12 +++++++----- tests/ui/circulation/test_loan_utils.py | 6 ++---- 9 files changed, 16 insertions(+), 37 deletions(-) diff --git a/rero_ils/modules/acquisition/acq_invoices/api.py b/rero_ils/modules/acquisition/acq_invoices/api.py index 3fe8c661ad..abd1878841 100644 --- a/rero_ils/modules/acquisition/acq_invoices/api.py +++ b/rero_ils/modules/acquisition/acq_invoices/api.py @@ -122,11 +122,6 @@ def _acquisition_invoice_build_org_ref(cls, data): ) data["organisation"] = {"$ref": f"{get_base_url()}/api/organisations/{org_pid}"} - @property - def organisation_pid(self): - """Shortcut for acquisition invoice organisation pid.""" - return extracted_data_from_ref(self.get("organisation")) - @property def library_pid(self): """Shortcut for acquisition order library pid.""" diff --git a/rero_ils/modules/acquisition/acq_orders/api.py b/rero_ils/modules/acquisition/acq_orders/api.py index 0e88776c72..1dd3192115 100644 --- a/rero_ils/modules/acquisition/acq_orders/api.py +++ b/rero_ils/modules/acquisition/acq_orders/api.py @@ -120,8 +120,7 @@ def vendor(self): @property def organisation_pid(self): """Shortcut for acquisition order organisation pid.""" - library = extracted_data_from_ref(self.get("library"), data="record") - return library.organisation_pid + return self.library.organisation_pid @property def library_pid(self): diff --git a/rero_ils/modules/acquisition/acq_receipts/api.py b/rero_ils/modules/acquisition/acq_receipts/api.py index d53344ef19..08db28b7eb 100644 --- a/rero_ils/modules/acquisition/acq_receipts/api.py +++ b/rero_ils/modules/acquisition/acq_receipts/api.py @@ -284,11 +284,6 @@ def library_pid(self): """Shortcut for acquisition receipt library pid.""" return extracted_data_from_ref(self.get("library")) - @property - def organisation_pid(self): - """Shortcut for acquisition receipt organisation pid.""" - return extracted_data_from_ref(self.get("organisation")) - def get_receipt_lines(self, output=None): """Get all receipt lines related to this receipt. diff --git a/rero_ils/modules/holdings/api.py b/rero_ils/modules/holdings/api.py index f7966c8e22..d10b549fb8 100644 --- a/rero_ils/modules/holdings/api.py +++ b/rero_ils/modules/holdings/api.py @@ -264,7 +264,7 @@ def library(self): @property def organisation_pid(self): """Get organisation pid for holding.""" - return Location.get_record_by_pid(self.location_pid).organisation_pid + return self.location.organisation_pid @property def vendor_pid(self): diff --git a/rero_ils/modules/loans/api.py b/rero_ils/modules/loans/api.py index 5620aa1a9a..4c495913e9 100644 --- a/rero_ils/modules/loans/api.py +++ b/rero_ils/modules/loans/api.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # RERO ILS -# Copyright (C) 2019-2022 RERO +# Copyright (C) 2019-2024 RERO # Copyright (C) 2019-2022 UCLouvain # # This program is free software: you can redistribute it and/or modify @@ -640,15 +640,6 @@ def is_active(self): states = current_app.config["CIRCULATION_STATES_LOAN_ACTIVE"] return self.get("state") in states - @property - def organisation_pid(self): - """Get organisation pid for loan.""" - if item := self.item: - return item.organisation_pid - raise IlsRecordError.PidDoesNotExist( - self.provider.pid_type, "organisation_pid:item_pid" - ) - @property def library_pid(self): """Get library PID regarding loan location.""" diff --git a/rero_ils/modules/locations/api.py b/rero_ils/modules/locations/api.py index b819665d26..5e8e9c2713 100644 --- a/rero_ils/modules/locations/api.py +++ b/rero_ils/modules/locations/api.py @@ -213,10 +213,7 @@ def library(self): @property def organisation_pid(self): """Get organisation pid for location.""" - from ..libraries.api import Library - - library = Library.get_record_by_pid(self.library_pid) - return library.organisation_pid + return self.library.organisation_pid @property def restrict_pickup_to(self): diff --git a/scripts/test b/scripts/test index 42b938c73c..a6f8f96c69 100755 --- a/scripts/test +++ b/scripts/test @@ -84,6 +84,8 @@ function pretests () { # -> Vulnerability found in werkzeug version 2.2.3 # Vulnerability ID: 71595 # -> Vulnerability found in werkzeug version 2.2.3 +# Vulnerability ID: 73969 +# -> Vulnerability found in werkzeug version 2.2.3 # Vulnerability ID: 71594 # -> Vulnerability found in werkzeug version 2.2.3 # Vulnerability ID: 73969 @@ -98,7 +100,7 @@ function pretests () { # -> Vulnerability found in werkzeug version 2.2.3 # Vulnerability ID: 73889 info_msg "Check vulnerabilities:" - safety_exceptions="-i 40459 -i 72731 -i 70624 -i 51668 -i 42194 -i 42852 -i 62019 -i 71595 -i 71594 -i 73969 -i 70612 -i 72982 -i 51457 -i 72260 -i 73889" + safety_exceptions="-i 40459 -i 72731 -i 70624 -i 51668 -i 42194 -i 42852 -i 62019 -i 71595 -i 73969 -i 71594 -i 70612 -i 72982 -i 51457 -i 72260 -i 73889" msg=$(safety check -o text ${safety_exceptions}) || { echo "Safety vulnerabilites found for packages:" $(safety check -o bare ${safety_exceptions}) echo "Run: \"safety check -o screen ${safety_exceptions} | grep -i vulnerability\" for more details" diff --git a/tests/api/circulation/test_locations_restrictions.py b/tests/api/circulation/test_locations_restrictions.py index d9c3911321..e47bf3d1f8 100644 --- a/tests/api/circulation/test_locations_restrictions.py +++ b/tests/api/circulation/test_locations_restrictions.py @@ -63,11 +63,13 @@ def test_location_disallow_request( # Create "virtual" Loan (not registered) loan = Loan( - { - "item_pid": item_pid_to_object(item_lib_martigny.pid), - "library_pid": lib_martigny.pid, - "patron_pid": patron_martigny.pid, - } + Loan._loan_build_org_ref( + { + "item_pid": item_pid_to_object(item_lib_martigny.pid), + "library_pid": lib_martigny.pid, + "patron_pid": patron_martigny.pid, + } + ) ) assert not can_be_requested(loan) diff --git a/tests/ui/circulation/test_loan_utils.py b/tests/ui/circulation/test_loan_utils.py index c4ec161c78..4b9805ad26 100644 --- a/tests/ui/circulation/test_loan_utils.py +++ b/tests/ui/circulation/test_loan_utils.py @@ -23,7 +23,6 @@ from invenio_circulation.errors import CirculationException from utils import item_record_to_a_specific_loan_state -from rero_ils.modules.api import IlsRecordError from rero_ils.modules.items.utils import item_pid_to_object from rero_ils.modules.loans.api import ( Loan, @@ -89,10 +88,9 @@ def test_loan_utils( # test the organisation of the loan is based on the item new_loan = deepcopy(loan_pending_martigny) - assert new_loan.organisation_pid + assert new_loan.organisation_pid == "org1" del new_loan["item_pid"] - with pytest.raises(IlsRecordError.PidDoesNotExist): - new_loan.organisation_pid + assert new_loan.organisation_pid == "org1" assert not can_be_requested(loan_pending_martigny) # test the allow request at the location level