Skip to content

Commit

Permalink
item: make barcode uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
ntarocco committed Oct 16, 2024
1 parent 8221ccc commit 4a050bf
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 29 deletions.
4 changes: 2 additions & 2 deletions invenio_app_ils/circulation/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ def checkout_loan(
)

# check if there is an existing request
loan = patron_has_request_on_document(patron_pid, kwargs.get("document_pid"))
loan = patron_has_request_on_document(patron_pid, kwargs["document_pid"])
if loan:
loan = loan_cls.get_record_by_pid(loan.pid)
pid = IlsCirculationLoanIdProvider.get(loan["pid"]).pid
pid = IlsCirculationLoanIdProvider[loan["pid"]].pid
loan.update(new_loan)
else:
pid = ils_circulation_loan_pid_minter(record_uuid, data=new_loan)
Expand Down
2 changes: 2 additions & 0 deletions invenio_app_ils/items/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ def build_resolver_fields(cls, data):
def create(cls, data, id_=None, **kwargs):
"""Create Item record."""
cls.build_resolver_fields(data)
data["barcode"] = data["barcode"].upper()
return super().create(data, id_=id_, **kwargs)

def update(self, *args, **kwargs):
"""Update Item record."""
super().update(*args, **kwargs)
self["barcode"] = self["barcode"].upper()
self.build_resolver_fields(self)

def delete(self, **kwargs):
Expand Down
53 changes: 27 additions & 26 deletions invenio_app_ils/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,36 +168,37 @@ def __init__(self, record):
super().__init__(UserNeed(int(record["patron_pid"])), backoffice_access_action)


_is_authenticated_user = [
"circulation-loan-request",
"patron-loans",
"bulk-loan-extension",
]
_is_backoffice_permission = [
"circulation-loan-force-checkout",
"circulation-overdue-loan-notification",
"circulation-loan-update-dates",
"relations-create",
"relations-delete",
"stats-most-loaned",
"document-request-actions",
"bucket-create",
"ill-brwreq-patron-loan-create",
"ill-brwreq-patron-loan-extension-accept",
"ill-brwreq-patron-loan-extension-decline",
"send-notification-to-patron",
]
_is_patron_owner_permission = [
"document-request-decline",
"ill-brwreq-patron-loan-extension-request",
]

def views_permissions_factory(action):
"""Return ILS views permissions factory."""
is_authenticated_user = [
"circulation-loan-request",
"patron-loans",
"bulk-loan-extension",
]
is_backoffice_permission = [
"circulation-loan-force-checkout",
"circulation-overdue-loan-notification",
"circulation-loan-update-dates",
"relations-create",
"relations-delete",
"stats-most-loaned",
"document-request-actions",
"bucket-create",
"ill-brwreq-patron-loan-create",
"ill-brwreq-patron-loan-extension-accept",
"ill-brwreq-patron-loan-extension-decline",
"send-notification-to-patron",
]
is_patron_owner_permission = [
"document-request-decline",
"ill-brwreq-patron-loan-extension-request",
]
if action in is_authenticated_user:
if action in _is_authenticated_user:
return authenticated_user_permission()
elif action in is_backoffice_permission:
elif action in _is_backoffice_permission:
return backoffice_permission()
elif action in is_patron_owner_permission:
elif action in _is_patron_owner_permission:
return PatronOwnerPermission
elif action == "circulation-loan-checkout":
if current_app.config["ILS_SELF_CHECKOUT_ENABLED"]:
Expand Down
3 changes: 2 additions & 1 deletion tests/api/ils/items/test_items_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ def test_item_refs(app, testdata):
document_pid="docid-1",
internal_location_pid="ilocid-4",
created_by=dict(type="script", value="demo"),
barcode="348048",
barcode="cm-348048",
status="CAN_CIRCULATE",
circulation_restriction="NO_RESTRICTION",
medium="PAPER",
)
)
assert "$schema" in item
assert "document" in item and "$ref" in item["document"]
assert item["barcode"] == "CM-348048"
assert "internal_location" in item and "$ref" in item["internal_location"]

item = Item.get_record_by_pid("itemid-1")
Expand Down
5 changes: 5 additions & 0 deletions tests/api/ils/items/test_items_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def get_active_loan_pid_and_item_pid():
if total > 0:
return t["pid"], active_loan[0]["pid"]

item = Item.get_record_by_pid("itmeid-1")

Check failure on line 29 in tests/api/ils/items/test_items_update.py

View workflow job for this annotation

GitHub Actions / Tests (ils, 3.9, pypi, postgresql14, opensearch2)

test_update_item invenio_pidstore.errors.PIDDoesNotExistError
item["barcode"] = "aaabbbccc"
item.commit()
assert Item.get_record_by_pid("itmeid-1")["barcode"] == "AAABBBCCC"

# change document pid while is on loan
item_pid, loan_pid = get_active_loan_pid_and_item_pid()
item = Item.get_record_by_pid(item_pid)
Expand Down

0 comments on commit 4a050bf

Please sign in to comment.