Skip to content

Commit

Permalink
Merge ae4bb57 into 62c8ee5
Browse files Browse the repository at this point in the history
  • Loading branch information
Aly Badr committed Sep 27, 2019
2 parents 62c8ee5 + ae4bb57 commit af6a959
Show file tree
Hide file tree
Showing 33 changed files with 1,236 additions and 238 deletions.
7 changes: 7 additions & 0 deletions data/circulation_policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"allow_requests": true,
"number_of_days_before_due_date": 5,
"number_of_days_after_due_date": 5,
"overdue_amount": 2.0,
"number_renewals": 3,
"renewal_duration": 30,
"policy_library_level": false,
Expand All @@ -29,6 +30,7 @@
"number_renewals": 3,
"number_of_days_before_due_date": 5,
"number_of_days_after_due_date": 5,
"overdue_amount": 2.0,
"renewal_duration": 30,
"policy_library_level": false,
"is_default": true
Expand All @@ -46,6 +48,7 @@
"number_renewals": 1,
"number_of_days_before_due_date": 5,
"number_of_days_after_due_date": 5,
"overdue_amount": 2.0,
"renewal_duration": 7,
"policy_library_level": true,
"is_default": false,
Expand Down Expand Up @@ -78,6 +81,7 @@
"number_renewals": 1,
"number_of_days_before_due_date": 5,
"number_of_days_after_due_date": 5,
"overdue_amount": 2.0,
"renewal_duration": 14,
"policy_library_level": false,
"is_default": false,
Expand Down Expand Up @@ -113,6 +117,7 @@
"number_renewals": 1,
"number_of_days_before_due_date": 5,
"number_of_days_after_due_date": 5,
"overdue_amount": 2.0,
"renewal_duration": 14,
"policy_library_level": false,
"is_default": false,
Expand Down Expand Up @@ -140,6 +145,7 @@
"number_renewals": 3,
"number_of_days_before_due_date": 5,
"number_of_days_after_due_date": 5,
"overdue_amount": 2.0,
"renewal_duration": 28,
"policy_library_level": false,
"is_default": false,
Expand Down Expand Up @@ -167,6 +173,7 @@
"number_renewals": 3,
"number_of_days_before_due_date": 5,
"number_of_days_after_due_date": 5,
"overdue_amount": 2.0,
"renewal_duration": 84,
"policy_library_level": false,
"is_default": false,
Expand Down
6 changes: 4 additions & 2 deletions data/organisations.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"$schema": "https://ils.rero.ch/schema/organisations/organisation-v0.0.1.json",
"address": "Via Challand 132, 11100 Aosta",
"name": "R\u00e9seau des biblioth\u00e8ques du Canton d'Aoste",
"code": "aoste"
"code": "aoste",
"default_currency": "EUR"
},
{
"$schema": "https://ils.rero.ch/schema/organisations/organisation-v0.0.1.json",
"address": "Highlands, Scotland, Great Britain",
"name": "Libraries of the British Ministry of Magic",
"code": "highlands"
"code": "highlands",
"default_currency": "GBP"
}
]
37 changes: 37 additions & 0 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,38 @@ def _(x):
update_permission_factory_imp=can_update_organisation_records_factory,
delete_permission_factory_imp=can_delete_organisation_records_factory,
),
fee=dict(
pid_type='fee',
pid_minter='fee_id',
pid_fetcher='fee_id',
search_class=RecordsSearch,
search_index='fees',
indexer_class=IlsRecordIndexer,
search_type=None,
record_serializers={
'application/json': (
'rero_ils.modules.serializers:json_v1_response'
)
},
search_serializers={
'application/json': (
'rero_ils.modules.serializers:json_v1_search'
)
},
record_loaders={
'application/json': lambda: Fee(request.get_json()),
},
list_route='/fees/',
record_class='rero_ils.modules.fees.api:Fee',
item_route='/fees/<pid(fee, record_class="rero_ils.modules.fees.api:Fee"):pid_value>',
default_media_type='application/json',
max_result_window=10000,
search_factory_imp='rero_ils.query:organisation_search_factory',
read_permission_factory_imp=can_access_organisation_records_factory,
create_permission_factory_imp=can_create_organisation_records_factory,
update_permission_factory_imp=can_update_organisation_records_factory,
delete_permission_factory_imp=can_delete_organisation_records_factory,
),
)

SEARCH_UI_SEARCH_INDEX = 'documents'
Expand Down Expand Up @@ -937,6 +969,7 @@ def _(x):
'ptty': '/patron_types/patron_type-v0.0.1.json',
'notif': '/notifications/notification-v0.0.1.json',
'hold': '/holdings/holding-v0.0.1.json',
'fee': '/fees/fee-v0.0.1.json',
}

# Login Configuration
Expand Down Expand Up @@ -1136,3 +1169,7 @@ def _(x):
can_be_requested=can_be_requested
)
)

# Define the default system currency in used. Each organisation can override
# this parameter using the 'default_currency' field
RERO_ILS_DEFAULT_CURRENCY = 'CHF'
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
"default": 5,
"minimum": 1
},
"overdue_amount": {
"title": "Overdue amount",
"description": "Overdue amount.",
"type": "number",
"default": 2.0
},
"number_renewals": {
"title": "Maximum number of renewals",
"description": "Maximum number of renewals allowed.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"number_of_days_before_due_date": {
"type": "integer"
},
"overdue_amount": {
"type": "float"
},
"renewal_duration": {
"type": "integer"
},
Expand Down
21 changes: 21 additions & 0 deletions rero_ils/modules/fees/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- 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 <http://www.gnu.org/licenses/>.


"""Fee Records."""

from __future__ import absolute_import, print_function
132 changes: 132 additions & 0 deletions rero_ils/modules/fees/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# -*- 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 <http://www.gnu.org/licenses/>.

"""API for manipulating Fees."""

from __future__ import absolute_import, print_function

from datetime import datetime, timezone
from functools import partial

from flask import current_app
from invenio_search.api import RecordsSearch

from .models import FeeIdentifier, FeeMetadata
from ..api import IlsRecord
from ..circ_policies.api import CircPolicy
from ..fetchers import id_fetcher
from ..locations.api import Location
from ..minters import id_minter
from ..providers import Provider

# fee provider
feeProvider = type(
'FeeProvider',
(Provider,),
dict(identifier=FeeIdentifier, pid_type='fee')
)
# fee minter
fee_id_minter = partial(id_minter, provider=feeProvider)
# fee fetcher
fee_id_fetcher = partial(id_fetcher, provider=feeProvider)


class FeesSearch(RecordsSearch):
"""RecordsSearch for Fees."""

class Meta:
"""Search only on Fees index."""

index = 'fees'


class Fee(IlsRecord):
"""Fees class."""

minter = fee_id_minter
fetcher = fee_id_fetcher
provider = feeProvider
model_cls = FeeMetadata

@property
def organisation_pid(self):
"""Return organisation pid."""
location = Location.get_record_by_pid(self.transaction_location_pid)
return location.organisation_pid

@property
def transaction_location_pid(self):
"""Return transaction location pid."""
return self.replace_refs().get('location').get('pid')

@classmethod
def create_fee_from_notification(cls, notification):
"""Create a new fee."""
record = {}
if notification.get('notification_type') == 'overdue':
data = {}
schemas = current_app.config.get('RECORDS_JSON_SCHEMA')
data_schema = {
'base_url': current_app.config.get(
'RERO_ILS_APP_BASE_URL'
),
'schema_endpoint': current_app.config.get(
'JSONSCHEMAS_ENDPOINT'
),
'schema': schemas['fee']
}
data['$schema'] = '{base_url}{schema_endpoint}{schema}'\
.format(**data_schema)
base_url = current_app.config.get('RERO_ILS_APP_BASE_URL')
url_api = '{base_url}/api/{doc_type}/{pid}'
data['creation_date'] = datetime.now(timezone.utc).isoformat()
data['fee_type'] = 'overdue'
data['notification'] = {
'$ref': url_api.format(
base_url=base_url,
doc_type='notifications',
pid=notification.pid)
}
location_pid = notification.transaction_location_pid
data['location'] = {
'$ref': url_api.format(
base_url=base_url,
doc_type='locations',
pid=location_pid)
}
library_pid = Location.get_record_by_pid(location_pid).library_pid
patron_type_pid = notification.patron.patron_type_pid
holding_circulation_category_pid = notification\
.item.holding_circulation_category_pid
cipo = CircPolicy.provide_circ_policy(
library_pid,
patron_type_pid,
holding_circulation_category_pid
)
data['amount'] = cipo.get('overdue_amount')
currency = current_app.config.get('RERO_ILS_DEFAULT_CURRENCY')
if notification.organisation:
currency = notification.organisation.get('default_currency')
data['currency'] = currency
data['status'] = 'open'
record = cls.create(
data,
dbcommit=True,
reindex=True,
delete_pid=True
)
return record
28 changes: 28 additions & 0 deletions rero_ils/modules/fees/api_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- 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 <http://www.gnu.org/licenses/>.

"""Blueprint used for loading templates."""

from __future__ import absolute_import, print_function

from flask import Blueprint

api_blueprint = Blueprint(
'api_fee',
__name__,
url_prefix='/fee'
)
21 changes: 21 additions & 0 deletions rero_ils/modules/fees/jsonschemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- 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 <http://www.gnu.org/licenses/>.


"""JSON schemas."""

from __future__ import absolute_import, print_function

0 comments on commit af6a959

Please sign in to comment.