Acquisitions¶
Acquisitions
¶
Acquisitions(client: AlmaAPIClient)
Domain class for handling Alma Acquisitions API operations. Currently focused on invoice management - will be expanded later.
This class uses the AlmaAPIClient as its foundation for all HTTP operations.
Initialize the Acquisitions domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
AlmaAPIClient
|
The AlmaAPIClient instance for making HTTP requests |
required |
Source code in src/almaapitk/domains/acquisition.py
create_invoice_simple
¶
create_invoice_simple(
invoice_number: str,
invoice_date: str,
vendor_code: str,
total_amount: float,
currency: str = "ILS",
**optional_fields
) -> Dict[str, Any]
Create an invoice with simplified parameters.
This is a high-level helper that automatically formats the invoice data structure and handles date formatting. It wraps the low-level create_invoice() method with user-friendly parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_number
|
str
|
Vendor invoice number (required) |
required |
invoice_date
|
str
|
Invoice date - accepts "YYYY-MM-DD" or "YYYY-MM-DDZ" or datetime (required) |
required |
vendor_code
|
str
|
Vendor code from Alma (required) |
required |
total_amount
|
float
|
Total invoice amount (required) |
required |
currency
|
str
|
Currency code (default: "ILS") |
'ILS'
|
**optional_fields
|
Additional optional fields: - invoice_due_date: str or datetime - vendor_account: str - reference_number: str - payment_method: str - notes: List[str] - payment: Dict (voucher info, etc.) - invoice_vat: Dict (VAT details) - additional_charges: Dict (shipment, overhead, etc.) |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Created invoice dict with invoice_id and all invoice data |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required fields are missing or invalid |
AlmaAPIError
|
If API request fails |
Example - Simple invoice
invoice = acq.create_invoice_simple( ... invoice_number="INV-2025-001", ... invoice_date="2025-10-21", ... vendor_code="RIALTO", ... total_amount=100.00, ... currency="ILS" ... ) print(f"Created invoice: {invoice['id']}")
Example - Invoice with optional fields
invoice = acq.create_invoice_simple( ... invoice_number="INV-2025-002", ... invoice_date="2025-10-21", ... vendor_code="RIALTO", ... total_amount=250.00, ... currency="ILS", ... reference_number="PO-12345", ... payment={"voucher_number": "V-001"}, ... notes=["Payment for books", "Rush order"] ... )
Example - With datetime object
from datetime import datetime invoice = acq.create_invoice_simple( ... invoice_number="INV-2025-003", ... invoice_date=datetime.now(), ... vendor_code="VENDOR_CODE", ... total_amount=500.00 ... )
Source code in src/almaapitk/domains/acquisition.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
create_invoice_line_simple
¶
create_invoice_line_simple(
invoice_id: str,
pol_id: str,
amount: float,
quantity: int = 1,
fund_code: Optional[str] = None,
currency: str = "ILS",
**optional_fields
) -> Dict[str, Any]
Create an invoice line with simplified parameters.
This is a high-level helper that automatically handles fund distribution structure and other complexities. If fund_code is not provided, it will attempt to extract it from the POL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_id
|
str
|
Invoice ID (required) |
required |
pol_id
|
str
|
POL number e.g., "POL-12349" (required) |
required |
amount
|
float
|
Line amount (required) |
required |
quantity
|
int
|
Line quantity (default: 1) |
1
|
fund_code
|
Optional[str]
|
Fund code for distribution (optional - will try to get from POL if not provided) |
None
|
currency
|
str
|
Currency code (default: "ILS") |
'ILS'
|
**optional_fields
|
Additional optional fields: - invoice_line_type: str (default: "REGULAR") - note: str - subscription_from_date: str or datetime - subscription_to_date: str or datetime - vat: Dict |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Created invoice line dict |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required fields are missing or invalid |
AlmaAPIError
|
If API request fails |
Example - Simple line
line = acq.create_invoice_line_simple( ... invoice_id="123456789", ... pol_id="POL-12349", ... amount=100.00, ... fund_code="LIBRARY_FUND" ... )
Example - Line with multiple quantities
line = acq.create_invoice_line_simple( ... invoice_id="123456789", ... pol_id="POL-12350", ... amount=50.00, ... quantity=2, ... fund_code="BOOK_FUND", ... note="Textbooks for course" ... )
Example - Auto-detect fund from POL
line = acq.create_invoice_line_simple( ... invoice_id="123456789", ... pol_id="POL-12351", ... amount=75.00 ... # fund_code will be extracted from POL ... )
Example - Subscription line
line = acq.create_invoice_line_simple( ... invoice_id="123456789", ... pol_id="POL-12352", ... amount=200.00, ... fund_code="JOURNAL_FUND", ... subscription_from_date="2025-01-01", ... subscription_to_date="2025-12-31" ... )
Source code in src/almaapitk/domains/acquisition.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | |
create_invoice_with_lines
¶
create_invoice_with_lines(
invoice_number: str,
invoice_date: str,
vendor_code: str,
lines: List[Dict[str, Any]],
currency: str = "ILS",
auto_process: bool = True,
auto_pay: bool = False,
check_duplicates: bool = False,
**invoice_kwargs
) -> Dict[str, Any]
Create a complete invoice with lines in a single workflow.
This method automates the entire invoice creation process: 1. Calculates total amount from lines 2. Creates the invoice 3. Adds all invoice lines 4. Optionally processes (approves) the invoice 5. Optionally marks the invoice as paid
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_number
|
str
|
Vendor invoice number (required) |
required |
invoice_date
|
str
|
Invoice date as "YYYY-MM-DD" or datetime object (required) |
required |
vendor_code
|
str
|
Vendor code from Alma (required) |
required |
lines
|
List[Dict[str, Any]]
|
List of line items, each containing: - pol_id: POL ID (required) - amount: Line amount (required) - quantity: Item quantity (default: 1) - fund_code: Fund code (optional, auto-extracted from POL if missing) - Additional optional fields: note, subscription_from_date, etc. |
required |
currency
|
str
|
Currency code (default: "ILS") |
'ILS'
|
auto_process
|
bool
|
Automatically approve/process the invoice (default: True) |
True
|
auto_pay
|
bool
|
Automatically mark invoice as paid (default: False) |
False
|
check_duplicates
|
bool
|
Check if POLs are already invoiced before creating lines (default: False) Warning: This performs additional API calls and may be slow |
False
|
**invoice_kwargs
|
Additional invoice fields (payment, invoice_vat, etc.) |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing: - invoice_id: Created invoice ID - invoice_number: Invoice number - line_ids: List of created line IDs - total_amount: Calculated total - status: Final invoice status - processed: Whether invoice was processed - paid: Whether invoice was paid - errors: List of any errors encountered (empty if all successful) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required parameters are missing or invalid |
AlmaAPIError
|
If any API operation fails |
Example - Simple invoice with lines
lines = [ ... {"pol_id": "POL-12347", "amount": 50.00, "quantity": 1}, ... {"pol_id": "POL-12348", "amount": 75.00, "quantity": 2} ... ] result = acq.create_invoice_with_lines( ... invoice_number="INV-2025-001", ... invoice_date="2025-10-22", ... vendor_code="RIALTO", ... lines=lines ... ) print(f"Invoice ID: {result['invoice_id']}") print(f"Lines created: {len(result['line_ids'])}")
Example - Complete workflow with auto-pay
lines = [{"pol_id": "POL-12349", "amount": 100.00}] result = acq.create_invoice_with_lines( ... invoice_number="INV-2025-002", ... invoice_date="2025-10-22", ... vendor_code="RIALTO", ... lines=lines, ... auto_process=True, ... auto_pay=True ... )
Invoice is now created, processed, and paid¶
Example - With explicit fund codes
lines = [ {"pol_id": "POL-12350", "amount": 45.00, "fund_code": "SCIENCE"}, {"pol_id": "POL-12351", "amount": 55.00, "fund_code": "HISTORY"} ... ] result = acq.create_invoice_with_lines( ... invoice_number="INV-2025-003", ... invoice_date="2025-10-22", ... vendor_code="RIALTO", ... lines=lines, ... currency="USD" ... )
Example - Dry run (process but don't pay): >>> lines = [{"pol_id": "POL-12352", "amount": 200.00}] >>> result = acq.create_invoice_with_lines( ... invoice_number="INV-2025-004", ... invoice_date="2025-10-22", ... vendor_code="RIALTO", ... lines=lines, ... auto_process=True, ... auto_pay=False # Leave for manual payment ... )
Note
- If a line creation fails, subsequent lines will still be attempted
- All errors are captured in the 'errors' list in the result
- The invoice is created even if some lines fail
- Processing and payment only occur if all previous steps succeed
- Once an invoice is created, it cannot be deleted via API (only canceled/rejected in Alma UI if needed)
Source code in src/almaapitk/domains/acquisition.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 | |
get_invoice
¶
Retrieve an invoice by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_id
|
str
|
The invoice ID to retrieve |
required |
view
|
str
|
Level of detail (brief, full) |
'full'
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing the invoice data |
Raises:
| Type | Description |
|---|---|
ValueError
|
If invoice_id is empty or None |
RequestException
|
If the API request fails |
Source code in src/almaapitk/domains/acquisition.py
process_invoice_service
¶
Process an invoice service operation using the Invoice Service API.
According to Alma API documentation, this endpoint expects: - Operation specified in query parameter 'op' - Empty object {} as the request body
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_id
|
str
|
The invoice ID to process |
required |
operation
|
str
|
The operation to perform ('paid', 'process_invoice', 'mark_in_erp', 'rejected') |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing the operation result |
Raises:
| Type | Description |
|---|---|
ValueError
|
If invoice_id or operation is empty/None |
RequestException
|
If the API request fails |
Source code in src/almaapitk/domains/acquisition.py
check_invoice_payment_status
¶
Check if an invoice has already been paid (duplicate payment protection).
This method retrieves the invoice and checks its payment status to prevent accidentally paying the same invoice twice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_id
|
str
|
The invoice ID to check |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict with: - is_paid: bool - Whether invoice is already paid - payment_status: str - Current payment status (PAID, NOT_PAID, etc.) - invoice_status: str - Current invoice status (ACTIVE, CLOSED, etc.) - approval_status: str - Current approval status - can_pay: bool - Whether it's safe to mark as paid - warnings: List[str] - Any warnings about payment |
Example
check = acq.check_invoice_payment_status("123456") if check['is_paid']: ... print(f"⚠️ Invoice already paid! Status: {check['payment_status']}") elif check['can_pay']: ... acq.mark_invoice_paid("123456")
Source code in src/almaapitk/domains/acquisition.py
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 | |
mark_invoice_paid
¶
Mark an invoice as paid using the Invoice Service API.
⚠️ DUPLICATE PAYMENT PROTECTION: This method now includes automatic duplicate payment protection. It will check if the invoice is already paid before proceeding. Use force=True to bypass this check (not recommended).
This uses the 'paid' operation which sends an empty object {} as payload and specifies the operation in the query parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_id
|
str
|
The invoice ID to mark as paid |
required |
force
|
bool
|
If True, bypass duplicate payment protection (dangerous!) |
False
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing the operation result |
Raises:
| Type | Description |
|---|---|
AlmaAPIError
|
If invoice is already paid (unless force=True) |
Example - Safe payment with automatic protection
result = acq.mark_invoice_paid("123456")
Example - Force payment (bypass protection): >>> result = acq.mark_invoice_paid("123456", force=True) # NOT RECOMMENDED
Source code in src/almaapitk/domains/acquisition.py
approve_invoice
¶
Process an invoice (convenience method).
This uses the 'process_invoice' operation as described in the blog post. According to the documentation, this step is mandatory after creating the invoice and its lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_id
|
str
|
The invoice ID to process |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing the operation result |
Source code in src/almaapitk/domains/acquisition.py
reject_invoice
¶
Reject an invoice (convenience method).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_id
|
str
|
The invoice ID to reject |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing the operation result |
Source code in src/almaapitk/domains/acquisition.py
mark_invoice_in_erp
¶
Mark invoice in ERP system (convenience method).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_id
|
str
|
The invoice ID to mark in ERP |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing the operation result |
Source code in src/almaapitk/domains/acquisition.py
get_invoice_summary
¶
Get a summary of key invoice information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_id
|
str
|
The invoice ID |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict containing key invoice information |
Source code in src/almaapitk/domains/acquisition.py
list_invoices
¶
list_invoices(
limit: int = 10,
offset: int = 0,
status: Optional[str] = None,
vendor_code: Optional[str] = None,
) -> Dict[str, Any]
List invoices with optional filtering.
Pre-#11 behaviour is preserved bit-for-bit: the method still
accepts limit / offset and returns a single Alma list
payload ({"invoice": [...], "total_record_count": N}). The
offset kwarg is honoured by passing it as a base param into
client.iter_paged so callers that page manually
(e.g., offset=200 to skip the first two pages) still see
the records they expect.
Pattern source: GitHub issue #11 (API: add iter_paged()
generator at the client level) -- proof-point migration #1.
list_invoices keeps a list-shaped public return for
backwards compatibility; callers that want streaming should
switch to client.iter_paged(...) directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum number of results to return. |
10
|
offset
|
int
|
Starting point for results. |
0
|
status
|
Optional[str]
|
Optional status filter. |
None
|
vendor_code
|
Optional[str]
|
Optional vendor code filter. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing the list of invoices, in the same shape |
Dict[str, Any]
|
the Alma /acq/invoices endpoint returns. |
Source code in src/almaapitk/domains/acquisition.py
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 | |
search_invoices
¶
Search invoices with a custom query.
Pattern source: GitHub issue #11 (API: add iter_paged()
generator at the client level) -- proof-point migration #2.
The method routes through client.iter_paged for the
common offset=0 case so the page-size, max_records cap, and
total_record_count bookkeeping live in one place. The
legacy offset > 0 window falls back to a direct one-page
GET, matching the list_invoices migration for symmetry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query (e.g., |
required |
limit
|
int
|
Maximum number of results to return. Must be in
the |
10
|
offset
|
int
|
Starting point for results. |
0
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict in the legacy Alma list shape: |
Dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
AlmaValidationError
|
If |
Source code in src/almaapitk/domains/acquisition.py
1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 | |
get_invoice_lines
¶
Get invoice lines for a specific invoice using dedicated lines endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_id
|
str
|
The invoice ID |
required |
limit
|
int
|
Maximum number of lines to retrieve (default: 100) |
100
|
offset
|
int
|
Starting offset for pagination (default: 0) |
0
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of invoice line dictionaries |
Source code in src/almaapitk/domains/acquisition.py
get_pol
¶
Retrieve a Purchase Order Line by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pol_id
|
str
|
Purchase Order Line ID |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
POL data dictionary |
Source code in src/almaapitk/domains/acquisition.py
extract_items_from_pol_data
¶
Extract items from POL data structure.
Items in POL data are nested in: location → copy (list of copy objects, each is an item). This method flattens that structure to return a simple list of item objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pol_data
|
Dict[str, Any]
|
POL data dictionary from get_pol() |
required |
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of item dictionaries extracted from all locations |
Example POL structure
{ "location": [ { "copy": [ {"pid": "item1", ...}, {"pid": "item2", ...} ] }, { "copy": [...] } ] }
Source code in src/almaapitk/domains/acquisition.py
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 | |
get_pol_items
¶
Get all items associated with a Purchase Order Line using dedicated items endpoint.
This uses the GET /almaws/v1/acq/po-lines/{pol_id}/items endpoint which returns items directly without nested location structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pol_id
|
str
|
Purchase Order Line ID |
required |
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of item dictionaries with item_id, status, receiving info, barcode, location |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pol_id is empty or None |
AlmaAPIError
|
If the API request fails |
If you already have POL data from get_pol(), you can use
extract_items_from_pol_data() instead to avoid an extra API call.
Source code in src/almaapitk/domains/acquisition.py
receive_item
¶
receive_item(
pol_id: str,
item_id: str,
receive_date: Optional[str] = None,
department: Optional[str] = None,
department_library: Optional[str] = None,
) -> Dict[str, Any]
Receive an existing item in a Purchase Order Line.
This operation marks an item as received in Alma. The item status will change to "received" and the process type will update from "acquisition" to "in transit".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pol_id
|
str
|
Purchase Order Line ID |
required |
item_id
|
str
|
Item ID to receive |
required |
receive_date
|
Optional[str]
|
Date of receipt in format YYYY-MM-DDZ (e.g., "2025-01-15Z") If not provided, current date will be used by Alma |
None
|
department
|
Optional[str]
|
Department code for receiving (optional) |
None
|
department_library
|
Optional[str]
|
Library code of receiving department (optional) |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing updated item data |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pol_id or item_id is empty/None |
AlmaAPIError
|
If the API request fails |
Example
acq.receive_item("POL-12345", "23435899800121", ... receive_date="2025-01-15Z", ... department="DEPT_CODE", ... department_library="LIB_CODE")
Source code in src/almaapitk/domains/acquisition.py
1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 | |
receive_and_keep_in_department
¶
receive_and_keep_in_department(
pol_id: str,
item_id: str,
mms_id: str,
holding_id: str,
library: str,
department: str,
work_order_type: str = "AcqWorkOrder",
work_order_status: str = "CopyCataloging",
receive_date: Optional[str] = None,
) -> Dict[str, Any]
Receive an item and immediately scan it into a department to prevent Transit status.
This method combines the receive_item operation with a scan-in operation to keep the item in the acquisitions department instead of letting it go to "in transit" status.
Workflow: 1. Receive the item via acquisitions API 2. Scan in the item to the specified department with a work order 3. Item stays in department with work order status instead of going to Transit
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pol_id
|
str
|
Purchase Order Line ID |
required |
item_id
|
str
|
Item ID to receive (from POL items) |
required |
mms_id
|
str
|
MMS ID (bibliographic record ID) - needed for scan-in |
required |
holding_id
|
str
|
Holding ID - needed for scan-in |
required |
library
|
str
|
Library code for the department |
required |
department
|
str
|
Department code where item should stay |
required |
work_order_type
|
str
|
Work order type code (default: "AcqWorkOrder") |
'AcqWorkOrder'
|
work_order_status
|
str
|
Work order status (default: "CopyCataloging") |
'CopyCataloging'
|
receive_date
|
Optional[str]
|
Optional receive date in format YYYY-MM-DDZ |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing the final item data after scan-in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required parameters are missing |
AlmaAPIError
|
If either API operation fails |
Example
Receive item and keep in acquisitions department¶
acq.receive_and_keep_in_department( ... pol_id="POL-12345", ... item_id="23123456789", ... mms_id="99123456789", ... holding_id="22123456789", ... library="MAIN", ... department="ACQ_DEPT" ... )
Notes
- Work order type and status must be configured in Alma
- The item will have process_type="Work Order" instead of "in transit"
- To complete the work order later, use bibs.scan_in_item with done=True
Source code in src/almaapitk/domains/acquisition.py
1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 | |
update_pol
¶
Update a Purchase Order Line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pol_id
|
str
|
Purchase Order Line ID |
required |
pol_data
|
Dict[str, Any]
|
Updated POL data |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Updated POL data |
Source code in src/almaapitk/domains/acquisition.py
create_invoice
¶
Create a new invoice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_data
|
Dict[str, Any]
|
Invoice data dictionary |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Created invoice data with ID |
Source code in src/almaapitk/domains/acquisition.py
create_invoice_line
¶
Create an invoice line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invoice_id
|
str
|
Invoice ID |
required |
line_data
|
Dict[str, Any]
|
Invoice line data |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Created invoice line data |
Source code in src/almaapitk/domains/acquisition.py
get_vendor_from_pol
¶
Extract vendor code from a POL.
Retrieves the POL data and extracts the vendor code, which is useful when creating invoices for POLs without knowing the vendor in advance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pol_id
|
str
|
POL number (e.g., "POL-12349") |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Vendor code string if found, None if vendor not found or POL doesn't exist |
Raises:
| Type | Description |
|---|---|
AlmaAPIError
|
If POL retrieval fails |
Example
vendor_code = acq.get_vendor_from_pol("POL-12349") print(f"Vendor: {vendor_code}") Vendor: RIALTO
Example - Handle missing vendor
vendor_code = acq.get_vendor_from_pol("POL-12349") if vendor_code: ... invoice = acq.create_invoice_simple( ... invoice_number="INV-001", ... invoice_date="2025-10-22", ... vendor_code=vendor_code, ... total_amount=100.00 ... ) ... else: ... print("No vendor found on POL")
Source code in src/almaapitk/domains/acquisition.py
get_fund_from_pol
¶
Extract primary fund code from a POL.
Retrieves the POL data and extracts the first fund code from the fund_distribution array. This is useful when creating invoice lines without knowing the fund code in advance.
Note: If POL has multiple funds, only the first (primary) fund is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pol_id
|
str
|
POL number (e.g., "POL-12349") |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Fund code string if found, None if no fund found or POL doesn't exist |
Raises:
| Type | Description |
|---|---|
AlmaAPIError
|
If POL retrieval fails |
Example
fund_code = acq.get_fund_from_pol("POL-12349") print(f"Fund: {fund_code}") Fund: LIBRARY_FUND
Example - Auto-populate invoice line
fund_code = acq.get_fund_from_pol("POL-12349") if fund_code: ... line = acq.create_invoice_line_simple( ... invoice_id="123456789", ... pol_id="POL-12349", ... amount=100.00, ... fund_code=fund_code ... ) ... else: ... print("No fund found on POL - must provide explicitly")
Example - Used automatically by create_invoice_line_simple
Fund code extracted automatically if not provided¶
line = acq.create_invoice_line_simple( ... invoice_id="123456789", ... pol_id="POL-12349", ... amount=100.00 ... # fund_code omitted - will call get_fund_from_pol() ... )
Source code in src/almaapitk/domains/acquisition.py
2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 | |
get_price_from_pol
¶
Extract price (list price) from a POL.
Retrieves the POL data and extracts the list price. This is useful when creating invoice lines to ensure the correct amount is invoiced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pol_id
|
str
|
POL number (e.g., "POL-12349") |
required |
Returns:
| Type | Description |
|---|---|
Optional[float]
|
Price as float if found, None if no price found or POL doesn't exist |
Raises:
| Type | Description |
|---|---|
AlmaAPIError
|
If POL retrieval fails |
Example
price = acq.get_price_from_pol("POL-12349") print(f"POL Price: {price}") POL Price: 180.0
Example - Create invoice line with POL's actual price: >>> price = acq.get_price_from_pol("POL-12349") >>> if price: ... line = acq.create_invoice_line_simple( ... invoice_id="123456789", ... pol_id="POL-12349", ... amount=price, # Use POL's actual price ... quantity=1 ... )
Example - Complete workflow with POL prices
pol_ids = ["POL-12349", "POL-12350"] lines = [] for pol_id in pol_ids: ... price = acq.get_price_from_pol(pol_id) ... if price: ... lines.append({"pol_id": pol_id, "amount": price})
result = acq.create_invoice_with_lines( ... invoice_number="INV-2025-001", ... invoice_date="2025-10-22", ... vendor_code="RIALTO", ... lines=lines ... )
Source code in src/almaapitk/domains/acquisition.py
2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 | |
check_pol_invoiced
¶
Check if a POL is already linked to any invoice lines.
This is a critical validation to prevent double-invoicing. Searches through active and waiting invoices to find any existing invoice lines for the POL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pol_id
|
str
|
POL number (e.g., "POL-12349") |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict with: - is_invoiced: bool - Whether POL has any invoice lines - invoice_count: int - Number of invoices with this POL - invoices: List[Dict] - List of invoices containing this POL Each invoice dict contains: - invoice_id: str - invoice_number: str - line_id: str - amount: float - status: str |
Raises:
| Type | Description |
|---|---|
AlmaAPIError
|
If invoice search fails |
Example - Check before creating invoice line
check = acq.check_pol_invoiced("POL-12349") if check['is_invoiced']: ... print(f"⚠️ POL already has {check['invoice_count']} invoice(s)") ... for inv in check['invoices']: ... print(f" - Invoice {inv['invoice_number']}: {inv['amount']}") ... else: ... # Safe to create invoice line ... line = acq.create_invoice_line_simple(...)
Example - Prevent double invoicing in workflow
def safe_create_invoice_line(pol_id, amount): ... check = acq.check_pol_invoiced(pol_id) ... if check['is_invoiced']: ... raise ValueError(f"POL {pol_id} already invoiced") ... return acq.create_invoice_line_simple(...)
Note
- This performs API searches which may be slow for large datasets
- Searches invoices with statuses: ACTIVE, WAITING_TO_BE_SENT, WAITING_FOR_INVOICE, IN_REVIEW
- Closed/cancelled invoices are not checked
- May not find invoices if Alma API search has limitations
- Best used as a safety check, not guaranteed to be exhaustive
Source code in src/almaapitk/domains/acquisition.py
2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 | |
get_environment
¶
test_connection
¶
Test if the acquisitions endpoints are accessible.
Returns:
| Type | Description |
|---|---|
bool
|
True if connection successful, False otherwise |