Skip to content

Commit

Permalink
transaction: add library for patron transactions
Browse files Browse the repository at this point in the history
* Adds the library pid in the patron transaction index if the
  transaction is related to a loan.
* Closes #1533.

Co-Authored-by: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
  • Loading branch information
jma committed Mar 30, 2021
1 parent 0b343bc commit 0a67262
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
9 changes: 6 additions & 3 deletions rero_ils/modules/patron_transactions/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,12 @@ def get_last_transaction_by_loan_pid(cls, loan_pid, status=None):
@property
def document_pid(self):
"""Return the document pid of the the patron transaction."""
loan = self.loan
if loan:
return loan.document_pid
return self.loan.document_pid if self.loan else None

@property
def library_pid(self):
"""Return the library pid of the the patron transaction."""
return self.loan.library_pid if self.loan else None

@property
def patron_pid(self):
Expand Down
4 changes: 4 additions & 0 deletions rero_ils/modules/patron_transactions/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ def enrich_patron_transaction_data(sender, json=None, record=None, index=None,
'pid': record.document_pid,
'type': 'documents'
}
json['library'] = {
'pid': record.library_pid,
'type': 'libraries'
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
}
}
},
"library": {
"properties": {
"type": {
"type": "keyword"
},
"pid": {
"type": "keyword"
}
}
},
"loan": {
"properties": {
"type": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def test_patron_transactions_get(client, patron_transaction_overdue_martigny):
data = get_json(res)
result = data['hits']['hits'][0]['metadata']
del(result['document'])
del(result['library'])
assert result == transaction.replace_refs()


Expand Down

0 comments on commit 0a67262

Please sign in to comment.