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

serials: fix issue.status_date field update #1911

Merged
merged 1 commit into from
Jun 7, 2021
Merged
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
7 changes: 6 additions & 1 deletion rero_ils/modules/items/api/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
from flask import current_app

from .record import ItemRecord
from ..models import ItemIssueStatus
from ..models import ItemIssueStatus, TypeOfItem


class ItemIssue(ItemRecord):
"""Item issue class."""

@property
def is_issue(self):
"""Is this item is an issue or not."""
return self.get('type') == TypeOfItem.ISSUE

@property
def expected_date(self):
"""Shortcut for issue expected date."""
Expand Down
18 changes: 14 additions & 4 deletions rero_ils/modules/items/api/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from elasticsearch_dsl.query import Q
from flask_babelex import gettext as _

from ..models import TypeOfItem
from ..utils import item_pid_to_object
from ...api import IlsRecord
from ...item_types.api import ItemType
Expand Down Expand Up @@ -97,6 +98,7 @@ def create(cls, data, id_=None, delete_pid=False,
"""Create item record."""
cls._item_build_org_ref(data)
data = cls._prepare_item_record(data=data, mode='create')
data = cls._set_issue_status_date(data=data)
record = super().create(
data, id_, delete_pid, dbcommit, reindex, **kwargs)
holding = cls._increment_next_prediction_for_holding(
Expand All @@ -109,7 +111,7 @@ def create(cls, data, id_=None, delete_pid=False,
# If `dbcommit` is already set to True, this commit is already done by
# the `IlsRecord.update()` function.
#
# /!\ if we write some other operation after _increement_next_predition
# /!\ if we write some other operation after _increment_next_predition
# we need to manage ourself the `rollback()`.
#
# TODO :: best solution will be to create an invenio `post_create`
Expand Down Expand Up @@ -153,11 +155,19 @@ def _set_issue_status_date(cls, data):
:param data: The record to update.
:return: The updated record.
"""
if data.get('type') != TypeOfItem.ISSUE:
return data

status = data.get('issue', {}).get('status')
item = cls.get_record_by_pid(data.get('pid'))
if status and item and status != item.issue_status:
data['issue']['status_date'] = \
datetime.now(timezone.utc).isoformat()
now = datetime.now(timezone.utc).isoformat()

if item: # item already exists
if status and status != item.issue_status:
data['issue']['status_date'] = now
else: # item creation
if status:
data['issue']['status_date'] = now
return data

@classmethod
Expand Down
9 changes: 8 additions & 1 deletion rero_ils/modules/items/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ class ItemMetadata(db.Model, RecordMetadataBase):
__tablename__ = 'item_metadata'


class TypeOfItem:
"""Enum class to list all possible item type."""

STANDARD = 'standard'
ISSUE = 'issue'


class ItemStatus:
"""Class holding all availabe circulation item statuses."""
"""Class holding all available circulation item statuses."""

ON_SHELF = 'on_shelf'
AT_DESK = 'at_desk'
Expand Down