spyreapi 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
spyre/utils.py ADDED
@@ -0,0 +1,130 @@
1
+ from Models.sales_models import *
2
+ from typing import TypeVar, Optional, Type, List, Set
3
+ from copy import deepcopy
4
+ from pydantic import BaseModel
5
+
6
+ T = TypeVar('T', bound=BaseModel)
7
+
8
+ # These will always be excluded unless explicitly overridden
9
+ DEFAULT_EXCLUDE_FIELDS = {'id', 'linkTable', 'linkType', 'linkNo', 'contact_type'}
10
+
11
+ # Normalize paths by replacing numeric list indices with '*'
12
+ def normalize_path(path: str) -> str:
13
+ return '.'.join('*' if part.isdigit() else part for part in path.split('.'))
14
+
15
+ # Should exclude based on normalized paths
16
+ def should_exclude(field_path: str, exclude_paths: Set[str]) -> bool:
17
+ return field_path in exclude_paths or field_path.split('.')[-1] in exclude_paths
18
+
19
+ def create_duplicate_record(
20
+ instance: T,
21
+ exclude_fields: Optional[List[str]] = None,
22
+ _prefix: str = ""
23
+ ) -> T:
24
+ if exclude_fields is None:
25
+ exclude_fields = []
26
+
27
+ # Normalize exclude paths so comparisons are wildcard-friendly
28
+ full_exclude_paths = {normalize_path(f) for f in DEFAULT_EXCLUDE_FIELDS.union(set(exclude_fields))}
29
+ cleaned_data = {}
30
+
31
+ for field_name, value in instance.model_dump().items():
32
+ full_path = f"{_prefix}.{field_name}" if _prefix else field_name
33
+
34
+ if should_exclude(full_path, full_exclude_paths):
35
+ continue
36
+
37
+ if isinstance(value, BaseModel):
38
+ cleaned_data[field_name] = create_duplicate_record(value, exclude_fields, _prefix=full_path)
39
+
40
+ elif isinstance(value, list):
41
+ cleaned_items = []
42
+ for i, item in enumerate(value):
43
+ if isinstance(item, BaseModel):
44
+ cleaned_items.append(create_duplicate_record(item, exclude_fields, _prefix=full_path))
45
+ elif isinstance(item, dict):
46
+ cleaned_dict = {}
47
+ for k, v in item.items():
48
+ field_k_path = f"{full_path}.{k}"
49
+ if isinstance(v, BaseModel):
50
+ cleaned_dict[k] = create_duplicate_record(v, exclude_fields, _prefix=field_k_path)
51
+ elif should_exclude(field_k_path, full_exclude_paths):
52
+ continue
53
+ else:
54
+ cleaned_dict[k] = deepcopy(v)
55
+ cleaned_items.append(cleaned_dict)
56
+ else:
57
+ cleaned_items.append(deepcopy(item))
58
+ cleaned_data[field_name] = cleaned_items
59
+
60
+ elif isinstance(value, dict):
61
+ cleaned_dict = {}
62
+ for k, v in value.items():
63
+ dict_path = f"{full_path}.{k}"
64
+ if isinstance(v, BaseModel):
65
+ cleaned_dict[k] = create_duplicate_record(v, exclude_fields, _prefix=dict_path)
66
+ elif should_exclude(dict_path, full_exclude_paths):
67
+ continue
68
+ else:
69
+ cleaned_dict[k] = deepcopy(v)
70
+ cleaned_data[field_name] = cleaned_dict
71
+
72
+ else:
73
+ cleaned_data[field_name] = deepcopy(value)
74
+
75
+ return instance.__class__(**cleaned_data)
76
+
77
+ def create_sales_order_from_invoice(invoice: Invoice) -> SalesOrder:
78
+ """Creates a Sales Order from an Invoice
79
+
80
+
81
+ Changes when converting
82
+ freight negative
83
+ backorders
84
+ extendedpriceorderd
85
+ orderqty
86
+ shippingCarrier
87
+ subtotalordered
88
+ taxes : {total}
89
+ total
90
+ totalOrdered
91
+ trackingNo
92
+
93
+ """
94
+
95
+
96
+ return SalesOrder(
97
+ orderNo=invoice.orderNo,
98
+ division=invoice.division,
99
+ location=invoice.location,
100
+ profitCenter=invoice.profitCenter,
101
+ customer=deepcopy(invoice.customer),
102
+ currency=deepcopy(invoice.currency),
103
+ status="O",
104
+ type="O",
105
+ hold=False,
106
+ orderDate=invoice.orderDate,
107
+ address=create_duplicate_record(invoice.address, exclude_fields=["contacts.contact_type"]),
108
+ shippingAddress=create_duplicate_record(invoice.shippingAddress),
109
+ customerPO=invoice.customerPO,
110
+ fob=invoice.fob,
111
+ incoterms=invoice.incoterms,
112
+ incotermsPlace=invoice.incotermsPlace,
113
+ referenceNo=None,
114
+ shippingCarrier=None,
115
+ shipDate=invoice.shipDate,
116
+ trackingNo=None,
117
+ termsCode=invoice.termsCode,
118
+ termsText=invoice.termsText,
119
+ freight=f"-{invoice.freight}",
120
+ subtotal=invoice.subtotal,
121
+ total=invoice.total,
122
+ items = [
123
+ create_duplicate_record(item).model_copy(update={
124
+ "orderQty": f"-{item.orderQty}" if item.orderQty != "0" else item.orderQty ,
125
+ "committedQty": f"-{item.committedQty}" if item.committedQty != "0" else item.committedQty
126
+ })
127
+ for item in invoice.items or []
128
+ ],
129
+ udf=deepcopy(invoice.udf),
130
+ )
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: spyreapi
3
+ Version: 0.0.1
4
+ Summary: A robust and extensible Python client for interacting with the [Spire Business Software API](https://developer.spiresystems.com/reference). This client provides an object-oriented interface to get, create, update, delete, query, filter, sort, and manage various Spire modules such as Sales Orders, Invoices, Inventory Items, and more.
5
+ Author-email: Sanjid Sharaf <sanjidsharaf1@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/sanjid-sharaf/spyre/
8
+ Project-URL: Issues, https://github.com/sanjid-sharaf/spyre/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ # Spire API Python Client
17
+
18
+ A robust and extensible Python client for interacting with the [Spire Business Software API](https://developer.spiresystems.com/reference). This client provides an object-oriented interface to get, create, update, delete, query, filter, sort, and manage various Spire modules such as Sales Orders, Invoices, Inventory Items, and more.
19
+
20
+ ---
21
+
22
+ ## โœจ Features
23
+
24
+ - โœ… Object-oriented resource wrappers for each module (e.g., `salesOrder`, `invoice`, `item`)
25
+ - ๐Ÿ” Full-text search via `q` parameter
26
+ - ๐Ÿ” Pagination with `start` and `limit` support
27
+ - ๐Ÿงพ JSON-based advanced filtering (supports `$gt`, `$lt`, `$in`, `$or`, etc.)
28
+ - โ†•๏ธ Multi-field sorting with ascending/descending control
29
+ - ๐Ÿ”ง Clean abstraction layer for API endpoints
30
+ - ๐Ÿ“ฆ Powered by `pydantic` models for validation
31
+
32
+ ---
33
+
34
+ ## ๐Ÿ“ฆ Installation
35
+
36
+ ```bash
37
+ pip install -r requirements.txt
@@ -0,0 +1,19 @@
1
+ spyre/Exceptions.py,sha256=Ikl-eEG_z2YsGbNZt04fw3i1dY_sAMg2VK7cReMEYo4,1511
2
+ spyre/__init__.py,sha256=XmA9jt7wrNJaTNHNHBGg9wM7JL3mO0nYYPYzCHCZOEw,583
3
+ spyre/client.py,sha256=EX-WVJJ60mgo6SzT5HZ9b73kG2hNP3lMYuJoEx7kmac,7485
4
+ spyre/config.py,sha256=rQZza2Rg09cnwIDbdSKkbuCiZkh-vjiy4XHho2QDJ-k,96
5
+ spyre/customers.py,sha256=CafIyuCszTDF4bybLyR4NC6o5AUbvabFZBhwxX8CNg0,5899
6
+ spyre/inventory.py,sha256=QC7C6OGrxejfzm0vOhm1flj3go8DJrkny1lBM_UjbaA,12477
7
+ spyre/sales.py,sha256=NbCh-yQn720PI6QKW6kS60UnCgcpxJ3YA2bZEpTb-fY,12079
8
+ spyre/spire.py,sha256=o7tBVdFVmitCVAQdZypAIvvVnn0Q2Sy9vjvCXcEnsms,483
9
+ spyre/utils.py,sha256=R3JDlDtP_8u6nxtueEp8csTeRxT_2O-rLOPQvW3qgbE,4921
10
+ spyre/Models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ spyre/Models/customers_models.py,sha256=GC-LRBjUGlixpl3tLzWf5_xEaoF95g6NT_tD6Kv4X08,1552
12
+ spyre/Models/inventory_models.py,sha256=U6MDWRl9rSBZNTkcedgdaz7aYsdV5Nlx2155r012_CE,5685
13
+ spyre/Models/sales_models.py,sha256=4CKcB3bZvTLpKJ48LjevnlYCWPzLyhD6_NR2c4WZeHc,6284
14
+ spyre/Models/shared_models.py,sha256=okQbbq6ReFQDDU1OyEeJ4B-gu423bVtmN6ZxhA58cVc,3146
15
+ spyreapi-0.0.1.dist-info/licenses/LICENSE,sha256=9yQHgnVrnoOl6Dnszcua8RuDohRsP9iyNJRVHISK6n0,1084
16
+ spyreapi-0.0.1.dist-info/METADATA,sha256=09JSnxSASzT5Vj6zAmU3jmbqQutT_09bWC4geQ5rJzY,1730
17
+ spyreapi-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
18
+ spyreapi-0.0.1.dist-info/top_level.txt,sha256=GsXUFItM5Ozy2wtCqd9eIumaXq1MUY0DsyVWuvGyQH4,6
19
+ spyreapi-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2025] [2025]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ spyre