Skip to content

Commit

Permalink
fix(items): remove legacy fields
Browse files Browse the repository at this point in the history
* Closes #3667.
* ⚠️ Requires update mapping and deleting fields
`legacy_checkout_count` and `legacy_circulation_rules` in existing
items' data.

Co-Authored-by: Pascal Repond <pascal.repond@rero.ch>
  • Loading branch information
PascalRepond committed May 14, 2024
1 parent 4dd1dd5 commit 9c94dd0
Show file tree
Hide file tree
Showing 12 changed files with 537 additions and 24,373 deletions.
19,954 changes: 436 additions & 19,518 deletions data/items_big.json

Large diffs are not rendered by default.

4,841 changes: 93 additions & 4,748 deletions data/items_small.json

Large diffs are not rendered by default.

18 changes: 3 additions & 15 deletions rero_ils/modules/items/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,6 @@ def generate(count, itemscount, missing):
barcode = str(10000000000 + item_pid)

price = random.randint(1, 100)
legacy_checkout_count = random.randint(1, 15)
legacy_circulation_rules = {
'use_item_specific_rules': False,
'loan_duration': 15,
'allow_request': False,
'floats': False
}

missing, item = create_random_item(
item_pid=item_pid,
Expand All @@ -167,9 +160,7 @@ def generate(count, itemscount, missing):
barcode=barcode,
status=status,
new_acquisition=new_acquisition,
price=price,
legacy_checkout_count=legacy_checkout_count,
legacy_circulation_rules=legacy_circulation_rules
price=price
)
item_pid += 1
yield item, new_holding
Expand Down Expand Up @@ -245,8 +236,7 @@ def get_item_types():

def create_random_item(item_pid, location_pid, missing, item_type_pid,
document_pid, holding_pid, barcode, status,
new_acquisition, price, legacy_checkout_count,
legacy_circulation_rules):
new_acquisition, price):
"""Create items with randomised values."""
if not status:
status = ItemStatus.ON_SHELF
Expand All @@ -272,9 +262,7 @@ def create_random_item(item_pid, location_pid, missing, item_type_pid,
},
'type': 'standard',
'pac_code': '2_controlled_consumption',
'price': price,
'legacy_checkout_count': legacy_checkout_count,
'legacy_circulation_rules': legacy_circulation_rules
'price': price
}
# ACQUISITION DATE
# add acquisition date if item is a new acquisition
Expand Down
34 changes: 0 additions & 34 deletions rero_ils/modules/items/jsonschemas/items/item-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -786,40 +786,6 @@
}
}
},
"legacy_checkout_count": {
"title": "Virtua checkout count for item",
"type": "integer",
"minimum": 0,
"default": 0
},
"legacy_circulation_rules": {
"title": "Virtua item circulation rules",
"type": "object",
"additionalProperties": false,
"properties": {
"use_item_specific_rules": {
"title": "To use item specific rules or CIPO rules",
"type": "boolean",
"default": false
},
"loan_duration": {
"title": "Loan duration in days",
"type": "integer",
"minimum": 0,
"default": 0
},
"allow_request": {
"title": "Allow requests",
"type": "boolean",
"default": true
},
"floats": {
"title": "Item floats",
"type": "boolean",
"default": false
}
}
},
"_masked": {
"title": "Masked",
"type": "boolean",
Expand Down
35 changes: 0 additions & 35 deletions rero_ils/modules/items/mappings/v7/items/item-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,41 +309,6 @@
"_masked": {
"type": "boolean"
},
"legacy_checkout_count": {
"type": "integer"
},
"legacy_circulation_rules": {
"properties": {
"allow_request": {
"type": "boolean"
},
"floats": {
"type": "boolean"
},
"loan_duration": {
"type": "integer"
},
"use_item_specific_rules": {
"type": "boolean"
}
}
},
"circulation_rules": {
"properties": {
"use_item_specific_rules": {
"type": "boolean"
},
"loan_duration": {
"type": "integer"
},
"allow_request": {
"type": "boolean"
},
"floats": {
"type": "boolean"
}
}
},
"_created": {
"type": "date"
},
Expand Down
1 change: 0 additions & 1 deletion rero_ils/modules/items/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
'item_barcode',
'item_call_number',
'item_second_call_number',
'item_legacy_checkout_count',
'item_type',
'item_library_name',
'item_location_name',
Expand Down
1 change: 0 additions & 1 deletion rero_ils/modules/items/serializers/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def get_item_data(hit):
('barcode', 'item_barcode'),
('call_number', 'item_call_number'),
('second_call_number', 'item_second_call_number'),
('legacy_checkout_count', 'item_legacy_checkout_count'),
('pac_code', 'item_pac_code'),
('price', 'item_price'),
('type', 'item_item_type'),
Expand Down
5 changes: 0 additions & 5 deletions rero_ils/modules/items/views/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,6 @@ def stats(item_pid):
for result in results.aggregations.trigger.buckets:
output['total'][result.key] = result.doc_count
output['total_year'][result.key] = result.year.doc_count
# Add legacy count on checkout
if item := Item.get_record_by_pid(item_pid):
legacy_count = item.get('legacy_checkout_count', 0)
output['total'].setdefault('checkout', 0)
output['total']['checkout'] += legacy_count
return jsonify(output)


Expand Down
6 changes: 2 additions & 4 deletions tests/api/items/test_items_rest_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,10 @@ def test_item_stats(
'execute',
mock.MagicMock(return_value=es_response)
):
# We sum the Legacy_count field in the checkout field
res = client.get(url_for('api_item.stats', item_pid='item1'))
assert res.json == \
{
'total': {'checkout': 5, 'extend': 2, 'checkin': 2},
'total': {'checkout': 1, 'extend': 2, 'checkin': 2},
'total_year': {'checkout': 1, 'extend': 1, 'checkin': 1}}

with mock.patch.object(
Expand All @@ -196,11 +195,10 @@ def test_item_stats(
mock.MagicMock(return_value=es_response_checkin)
):
# item found
# We add the legacy_checkout_count field to the checkout field
res = client.get(url_for('api_item.stats', item_pid='item1'))
assert res.json == \
{
'total': {'checkout': 4, 'checkin': 2},
'total': {'checkin': 2},
'total_year': {'checkin': 1}}
# No item found
res = client.get(url_for('api_item.stats', item_pid='foot'))
Expand Down
2 changes: 1 addition & 1 deletion tests/api/items/test_items_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_serializers(
'document_local_field_7', 'document_local_field_8',
'document_local_field_9', 'document_local_field_10',
'item_acquisition_date', 'item_barcode', 'item_call_number',
'item_second_call_number', 'item_legacy_checkout_count',
'item_second_call_number',
'item_type', 'item_library_name', 'item_location_name',
'item_pac_code', 'item_holding_pid', 'item_price', 'item_status',
'item_item_type', 'item_general_note', 'item_staff_note',
Expand Down
9 changes: 1 addition & 8 deletions tests/data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -4084,14 +4084,7 @@
"status": "on_shelf",
"url": "https://lipda.mediatheque.ch/CH-000019-X:223156.file",
"pac_code": "0_frozen_collection",
"price": 23.2,
"legacy_checkout_count": 4,
"legacy_circulation_rules": {
"use_item_specific_rules": false,
"loan_duration": 15,
"allow_request": false,
"floats": false
}
"price": 23.2
},
"item2": {
"$schema": "https://bib.rero.ch/schemas/items/item-v0.0.1.json",
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/test_items_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def test_item_all_jsonschema_keys_values(
{'key': 'ur', 'value': 25},
{'key': 'pac_code', 'value': 25},
{'key': 'price', 'value': '25'},
{'key': '_masked', 'value': 25},
{'key': 'legacy_checkout_count', 'value': '25'},
{'key': 'legacy_circulation_rules', 'value': 25}
{'key': '_masked', 'value': 25}
]
for element in validator:
with pytest.raises(ValidationError):
Expand Down

0 comments on commit 9c94dd0

Please sign in to comment.