Skip to content

Commit

Permalink
loan: fix organisation_pid function
Browse files Browse the repository at this point in the history
* Closes #3710
* Cleans code for `organisation_pid` function.

Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep committed Nov 29, 2024
1 parent d43b18e commit 915427b
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 36 deletions.
5 changes: 0 additions & 5 deletions rero_ils/modules/acquisition/acq_invoices/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
3 changes: 1 addition & 2 deletions rero_ils/modules/acquisition/acq_orders/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 0 additions & 5 deletions rero_ils/modules/acquisition/acq_receipts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/holdings/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 1 addition & 10 deletions rero_ils/modules/loans/api.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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."""
Expand Down
5 changes: 1 addition & 4 deletions rero_ils/modules/locations/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 10 additions & 5 deletions tests/api/circulation/test_locations_restrictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -78,6 +80,9 @@ def test_location_disallow_request(
item["temporary_location"] = {"$ref": get_ref_for_pid("loc", loc_public_saxon.pid)}
item.update(item, dbcommit=True, reindex=True)
assert loc_public_saxon["allow_request"]
from pprint import pprint

pprint(loan)
assert can_be_requested(loan)

# reset fixtures
Expand Down
6 changes: 2 additions & 4 deletions tests/ui/circulation/test_loan_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 915427b

Please sign in to comment.