Skip to content

Commit

Permalink
primeng: acquistion (in progress)
Browse files Browse the repository at this point in the history
Co-Authored-by: Johnny Mariéthoz <[email protected]>
Co-Authored-by: Pascal Repond <[email protected]>
  • Loading branch information
jma and PascalRepond committed Feb 4, 2025
1 parent 2f09105 commit de894fd
Show file tree
Hide file tree
Showing 41 changed files with 132 additions and 378 deletions.
37 changes: 9 additions & 28 deletions data/acq_order_lines.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"priority": 0,
"quantity": 3,
"amount": 25,
"exchange_rate": 1,
"notes": [
{
"type": "staff_note",
Expand All @@ -23,15 +22,13 @@
"library": {
"$ref": "https://bib.rero.ch/api/libraries/1"
},
"is_cancelled": false,
"send_now": true
"is_cancelled": false
},
{
"pid": "2",
"priority": 0,
"quantity": 15,
"amount": 5,
"exchange_rate": 1,
"notes": [
{
"type": "staff_note",
Expand All @@ -50,15 +47,13 @@
"library": {
"$ref": "https://bib.rero.ch/api/libraries/1"
},
"is_cancelled": false,
"send_now": true
"is_cancelled": false
},
{
"pid": "3",
"priority": 0,
"quantity": 2,
"amount": 100,
"exchange_rate": 1,
"notes": [
{
"type": "staff_note",
Expand All @@ -77,15 +72,13 @@
"library": {
"$ref": "https://bib.rero.ch/api/libraries/1"
},
"is_cancelled": false,
"send_now": true
"is_cancelled": false
},
{
"pid": "4",
"priority": 0,
"quantity": 5,
"amount": 10,
"exchange_rate": 1,
"acq_account": {
"$ref": "https://bib.rero.ch/api/acq_accounts/7"
},
Expand All @@ -98,15 +91,13 @@
"library": {
"$ref": "https://bib.rero.ch/api/libraries/2"
},
"is_cancelled": false,
"send_now": true
"is_cancelled": false
},
{
"pid": "5",
"priority": 5,
"quantity": 1,
"amount": 100,
"exchange_rate": 1,
"notes": [
{
"type": "staff_note",
Expand All @@ -125,15 +116,13 @@
"library": {
"$ref": "https://bib.rero.ch/api/libraries/2"
},
"is_cancelled": false,
"send_now": true
"is_cancelled": false
},
{
"pid": "6",
"priority": 1,
"quantity": 5,
"amount": 7,
"exchange_rate": 1,
"acq_account": {
"$ref": "https://bib.rero.ch/api/acq_accounts/14"
},
Expand All @@ -146,15 +135,13 @@
"library": {
"$ref": "https://bib.rero.ch/api/libraries/3"
},
"is_cancelled": false,
"send_now": true
"is_cancelled": false
},
{
"pid": "7",
"priority": 1,
"quantity": 15,
"amount": 12,
"exchange_rate": 1,
"acq_account": {
"$ref": "https://bib.rero.ch/api/acq_accounts/20"
},
Expand All @@ -167,15 +154,13 @@
"library": {
"$ref": "https://bib.rero.ch/api/libraries/4"
},
"is_cancelled": false,
"send_now": true
"is_cancelled": false
},
{
"pid": "8",
"priority": 1,
"quantity": 10,
"amount": 20,
"exchange_rate": 1,
"acq_account": {
"$ref": "https://bib.rero.ch/api/acq_accounts/4"
},
Expand All @@ -188,15 +173,13 @@
"library": {
"$ref": "https://bib.rero.ch/api/libraries/1"
},
"is_cancelled": false,
"send_now": true
"is_cancelled": false
},
{
"pid": "9",
"priority": 0,
"quantity": 3,
"amount": 22,
"exchange_rate": 1,
"acq_account": {
"$ref": "https://bib.rero.ch/api/acq_accounts/2"
},
Expand All @@ -216,7 +199,6 @@
"priority": 0,
"quantity": 3,
"amount": 25,
"exchange_rate": 1,
"notes": [
{
"type": "staff_note",
Expand All @@ -235,7 +217,6 @@
"library": {
"$ref": "https://bib.rero.ch/api/libraries/1"
},
"is_cancelled": false,
"order_date": "2021-07-20"
"is_cancelled": false
}
]
16 changes: 6 additions & 10 deletions data/acq_orders.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
"pid": "1",
"reference": "AOSTE-CANT1-POL-1",
"type": "monograph",
"currency": "EUR",
"notes": [
{
Expand All @@ -18,12 +17,12 @@
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/1"
}
},
"send_now": true
},
{
"pid": "2",
"reference": "AOSTE-CANT1-POL-2",
"type": "monograph",
"currency": "EUR",
"notes": [
{
Expand All @@ -39,12 +38,12 @@
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/1"
}
},
"send_now": true
},
{
"pid": "3",
"reference": "AOSTE-CANT2-POL-1",
"type": "monograph",
"currency": "EUR",
"notes": [
{
Expand All @@ -65,7 +64,6 @@
{
"pid": "4",
"reference": "AOSTE-AVISE-POL-1",
"type": "monograph",
"currency": "EUR",
"notes": [
{
Expand All @@ -86,7 +84,6 @@
{
"pid": "5",
"reference": "AOSTE-LYCEE-POL-1",
"type": "monograph",
"currency": "EUR",
"notes": [
{
Expand All @@ -107,7 +104,6 @@
{
"pid": "6",
"reference": "AOSTE-CANT1-POL-6",
"type": "monograph",
"currency": "EUR",
"library": {
"$ref": "https://bib.rero.ch/api/libraries/1"
Expand All @@ -122,7 +118,6 @@
{
"pid": "7",
"reference": "AOSTE-CANT1-POL-2021-1",
"type": "monograph",
"currency": "EUR",
"notes": [
{
Expand All @@ -138,6 +133,7 @@
},
"organisation": {
"$ref": "https://bib.rero.ch/api/organisations/1"
}
},
"send_now": true
}
]
2 changes: 0 additions & 2 deletions data/acq_receipts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"$ref": "https://bib.rero.ch/api/acq_orders/1"
},
"reference": "AOSTE-CANT1-POL-1",
"exchange_rate": 1,
"notes": [
{
"type": "staff_note",
Expand All @@ -25,7 +24,6 @@
"$ref": "https://bib.rero.ch/api/acq_orders/7"
},
"reference": "AOSTE-CANT1-POL-2021-1",
"exchange_rate": 1,
"notes": [
{
"type": "staff_note",
Expand Down
17 changes: 10 additions & 7 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2778,23 +2778,26 @@ def _(x):
),
),
filters={
"item": and_term_filter("item.pid"),
"patron_type": and_term_filter("patron_type.pid"),
"transaction_library": and_term_filter("library.pid"),
"transaction_date": range_filter(
_("item"): and_term_filter("item.pid"),
_("patron_type"): and_term_filter("patron_type.pid"),
_("transaction_library"): and_term_filter("library.pid"),
_("transaction_date"): range_filter(
"creation_date",
format="epoch_millis",
start_date_math="/d",
end_date_math="/d",
),
},
post_filters={
"owning_library": {
_("owning_library"): {
"owning_library": terms_filter("owning_library.pid"),
"owning_location": terms_filter("owning_location.pid"),
},
"category": terms_filter("category"),
"type": {"type": terms_filter("type"), "subtype": terms_filter("subtype")},
_("category"): terms_filter("category"),
_("type"): {
"type": terms_filter("type"),
"subtype": terms_filter("subtype"),
},
},
),
stats_cfg=dict(
Expand Down
9 changes: 9 additions & 0 deletions rero_ils/modules/acquisition/acq_accounts/serializers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
class AcqAccountJSONSerializer(ACQJSONSerializer):
"""Serializer for RERO-ILS `AcqAccount` records as JSON."""

def _postprocess_search_hit(self, hit: dict) -> None:
"""Post-process each hit of a search result."""
hit["metadata"]["number_of_children"] = (
AcqAccountsSearch()
.filter("term", parent__pid=hit["metadata"]["pid"])
.count()
)
super()._postprocess_search_hit(hit)

def preprocess_record(self, pid, record, links_factory=None, **kwargs):
"""Prepare a record and persistent identifier for serialization."""
# Add some ES stored keys into response
Expand Down
22 changes: 1 addition & 21 deletions rero_ils/modules/acquisition/acq_order_lines/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
"""API for manipulating Acquisition Order Line."""

from copy import deepcopy
from datetime import datetime
from functools import partial

from flask_babel import gettext as _
from werkzeug.utils import cached_property

from rero_ils.modules.acquisition.api import AcquisitionIlsRecord
from rero_ils.modules.api import IlsRecordsIndexer, IlsRecordsSearch
Expand Down Expand Up @@ -149,11 +147,6 @@ def order(self):
"""Shortcut to the order of the order line."""
return extracted_data_from_ref(self.get("acq_order"), data="record")

@property
def order_date(self):
"""Shortcut for acquisition order send date."""
return self.get("order_date")

@property
def is_cancelled(self):
"""Shortcut for acquisition order is_cancelled falg."""
Expand Down Expand Up @@ -223,19 +216,6 @@ def unreceived_quantity(self):
"""Get quantity of unreceived ordered_items for a line order."""
return self.quantity - self.received_quantity

@cached_property
def receipt_date(self):
"""Get the first reception date for one item of this order line."""
from rero_ils.modules.acquisition.acq_receipt_lines.api import (
AcqReceiptLinesSearch,
)

search = AcqReceiptLinesSearch().filter("term", acq_order_line__pid=self.pid)
search.aggs.metric("min_receipt_date", "min", field="receipt_date")
results = search.execute()
epoch = results.aggregations.min_receipt_date.value / 1000
return datetime.fromtimestamp(epoch)

@property
def status(self):
"""Calculate the order line status.
Expand All @@ -252,7 +232,7 @@ def status(self):
return AcqOrderLineStatus.CANCELLED
status = (
AcqOrderLineStatus.ORDERED
if self.order_date
if self.order.get("order_date")
else AcqOrderLineStatus.APPROVED
)

Expand Down
2 changes: 1 addition & 1 deletion rero_ils/modules/acquisition/acq_order_lines/dumpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def dump(self, record, data):
:param data: The initial dump data passed in by ``record.dumps()``.
"""
# Keep only some attributes from AcqOrderLine object initial dump.
for attr in ["pid", "status", "order_date", "quantity"]:
for attr in ["pid", "status", "quantity"]:
if value := record.get(attr):
data.update({attr: value})

Expand Down
Loading

0 comments on commit de894fd

Please sign in to comment.