Skip to content

Commit b7cd5e0

Browse files
rerowepPascalRepond
authored andcommitted
documents: allow delete of documents with orderln.
* Closes rero#3225. * Allows deletion of documents with acquisition order lines with status recieved or cancelled. Co-Authored-by: Peter Weber <peter.weber@rero.ch>
1 parent d29392b commit b7cd5e0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

rero_ils/modules/documents/api.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from jsonschema.exceptions import ValidationError
3030

3131
from rero_ils.modules.acquisition.acq_order_lines.api import AcqOrderLinesSearch
32+
from rero_ils.modules.acquisition.acq_order_lines.models import AcqOrderLineStatus
3233
from rero_ils.modules.api import IlsRecord, IlsRecordsIndexer, IlsRecordsSearch
3334
from rero_ils.modules.commons.identifiers import IdentifierFactory, IdentifierType
3435
from rero_ils.modules.documents.tasks import reindex_document_items
@@ -313,8 +314,17 @@ def get_links_to_me(self, get_pids=False):
313314
exclude_states=[LoanState.CANCELLED, LoanState.ITEM_RETURNED],
314315
)
315316
file_query = self.get_records_files_query().source()
316-
acq_order_lines_query = AcqOrderLinesSearch().filter("term", document__pid=self.pid)
317+
318+
status_list = [
319+
AcqOrderLineStatus.APPROVED,
320+
AcqOrderLineStatus.ORDERED,
321+
AcqOrderLineStatus.PARTIALLY_RECEIVED,
322+
]
323+
acq_order_lines_query = (
324+
AcqOrderLinesSearch().filter("term", document__pid=self.pid).filter("terms", status=status_list)
325+
)
317326
local_fields_query = LocalFieldsSearch().get_local_fields(self.provider.pid_type, self.pid)
327+
318328
relation_types = {
319329
"partOf": "partOf.document.pid",
320330
"supplement": "supplement.pid",

tests/api/acquisition/test_acquisition_reception_workflow.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def test_acquisition_reception_workflow(
6464
document,
6565
):
6666
"""Test complete acquisition workflow."""
67+
assert document.get_links_to_me() == {}
6768

6869
def assert_account_data(accounts):
6970
"""Assert account informations."""
@@ -286,6 +287,8 @@ def assert_account_data(accounts):
286287
}
287288
assert_account_data(manual_controls)
288289

290+
assert document.get_links_to_me() == {"acq_order_lines": 6}
291+
289292
# STEP 3 :: UPDATE ORDER LINES
290293
# * Cancel some order lines and change some quantities --> make sure
291294
# calculations still good
@@ -363,6 +366,8 @@ def assert_account_data(accounts):
363366
assert order_line_1.unreceived_quantity == 5
364367
assert order_line_1.status == AcqOrderLineStatus.APPROVED
365368

369+
assert document.get_links_to_me() == {"acq_order_lines": 4}
370+
366371
# STEP 4 :: SEND THE ORDER
367372
# * Test send order and make sure statuses are up to date.
368373
# - check order lines (status, order-date)

0 commit comments

Comments
 (0)