stackin-python-sdk 0.7.0__tar.gz → 0.8.0__tar.gz
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.
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/PKG-INFO +80 -3
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/README.md +79 -2
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/pyproject.toml +2 -2
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/stackin/__init__.py +1 -1
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/stackin/br/product.py +11 -2
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/LICENSE +0 -0
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/stackin/br/__init__.py +0 -0
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/stackin/br/tax.py +0 -0
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/stackin/core/__init__.py +0 -0
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/stackin/core/address.py +0 -0
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/stackin/core/client.py +0 -0
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/stackin/core/exceptions.py +0 -0
- {stackin_python_sdk-0.7.0 → stackin_python_sdk-0.8.0}/stackin/core/types.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stackin-python-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Python SDK for issuing, consulting and cancelling electronic invoices.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -47,7 +47,73 @@ Description-Content-Type: text/markdown
|
|
|
47
47
|
|
|
48
48
|
Python SDK for fiscal document issuance — a handful of business fields, nothing about certificates, XML, XSD, signing or SOAP. The API resolves all of that from the issuer's own configuration, identified by `api_key`.
|
|
49
49
|
|
|
50
|
-
**One class, `Invoice`** — `issue()`/`consult()`/`cancel()`/`reissue()`/`correct()`/`invalidate()`/`pdf()`/`received()`/`manifest()`, nothing else to instantiate. Each line item is a `Product` (`stackin.br`) — `description
|
|
50
|
+
**One class, `Invoice`** — `issue()`/`consult()`/`cancel()`/`reissue()`/`correct()`/`invalidate()`/`pdf()`/`received()`/`manifest()`, nothing else to instantiate. Each line item is a `Product` (`stackin.br`) — `description` plus either `unit_price` or `amount` are universal, everything else (`ncm`/`cfop`/`cest`/tax groups...) is Brazil-specific and only required for NFE; NFSE ignores it.
|
|
51
|
+
|
|
52
|
+
## What a line item is worth
|
|
53
|
+
|
|
54
|
+
`unit_price` is the price of **one unit**. `amount` is the **gross total of
|
|
55
|
+
the line's products**, before discount, freight, insurance and other
|
|
56
|
+
expenses. Send either; sending both asserts that they agree.
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from decimal import Decimal
|
|
60
|
+
|
|
61
|
+
# One unit
|
|
62
|
+
Product(description="Consultoria", quantity=Decimal("1"), unit_price=Decimal("1500.00"))
|
|
63
|
+
|
|
64
|
+
# More than one unit — amount is computed as 2 x 120.00 = 240.00
|
|
65
|
+
Product(description="Teclado", quantity=Decimal("2"), unit_price=Decimal("120.00"))
|
|
66
|
+
|
|
67
|
+
# A fractional quantity — 1.5 x 30.00 = 45.00
|
|
68
|
+
Product(description="Cabo", quantity=Decimal("1.5"), unit_price=Decimal("30.00"))
|
|
69
|
+
|
|
70
|
+
# Legacy: amount alone still means the line's gross total
|
|
71
|
+
Product(description="Servico", quantity=Decimal("3"), amount=Decimal("150.00"))
|
|
72
|
+
|
|
73
|
+
# Both, checked against each other before the document is transmitted
|
|
74
|
+
Product(
|
|
75
|
+
description="Teclado",
|
|
76
|
+
quantity=Decimal("2"),
|
|
77
|
+
unit_price=Decimal("120.00"),
|
|
78
|
+
amount=Decimal("240.00"),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# With charges: 5000.00 - 100.50 + 40.00 + 10.00 = 4949.50 on the note
|
|
82
|
+
Product(
|
|
83
|
+
description="Servidor",
|
|
84
|
+
quantity=Decimal("2"),
|
|
85
|
+
unit_price=Decimal("2500.00"),
|
|
86
|
+
discount=100.50,
|
|
87
|
+
freight=40.00,
|
|
88
|
+
insurance=10.00,
|
|
89
|
+
)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Amounts that do not add up are refused before the authorizer sees them,
|
|
93
|
+
with a `422` naming the line and both numbers:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"detail": {
|
|
98
|
+
"code": "ITEM_TOTAL_MISMATCH",
|
|
99
|
+
"field": "items[0].amount",
|
|
100
|
+
"message": "amount is 50.00, but quantity x unit_price is 150.00.",
|
|
101
|
+
"expected": "150.00",
|
|
102
|
+
"received": "50.00"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Migrating
|
|
108
|
+
|
|
109
|
+
```text
|
|
110
|
+
Before: quantity = 3, amount = 150.00
|
|
111
|
+
After: quantity = 3, unit_price = 50.00
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Nothing has to migrate. `amount` keeps the meaning it always had and is
|
|
115
|
+
not deprecated in this release; a line sent with `amount` alone is built
|
|
116
|
+
exactly as it was before.
|
|
51
117
|
|
|
52
118
|
## Install
|
|
53
119
|
|
|
@@ -60,6 +126,8 @@ pip install stackin-python-sdk
|
|
|
60
126
|
Get an `api_key` from the [stackin dashboard](https://app.stackin.io) — select the issuing company, then Settings → API key (context `sdk`). One key per issuing company, shown once at creation. The API resolves the issuer (CNPJ, state, address, certificate, environment) entirely from it; nothing about the issuer is ever passed on a call.
|
|
61
127
|
|
|
62
128
|
```python
|
|
129
|
+
from decimal import Decimal
|
|
130
|
+
|
|
63
131
|
from stackin import Invoice, DocumentType, Address
|
|
64
132
|
from stackin.br import Product # Brazil-specific line item — NCM/CFOP
|
|
65
133
|
|
|
@@ -90,7 +158,16 @@ client.issue(
|
|
|
90
158
|
document_type=DocumentType.NFE,
|
|
91
159
|
client_name="Buyer Company Ltd",
|
|
92
160
|
tax_id="11111111111111",
|
|
93
|
-
items=[
|
|
161
|
+
items=[
|
|
162
|
+
Product(
|
|
163
|
+
description="Teclado",
|
|
164
|
+
quantity=Decimal("2"),
|
|
165
|
+
unit_price=Decimal("120.00"),
|
|
166
|
+
unit="UN",
|
|
167
|
+
ncm="84716052",
|
|
168
|
+
cfop="5102",
|
|
169
|
+
)
|
|
170
|
+
],
|
|
94
171
|
recipient_address=Address(
|
|
95
172
|
street="Avenida Atlantica",
|
|
96
173
|
number="500",
|
|
@@ -18,7 +18,73 @@
|
|
|
18
18
|
|
|
19
19
|
Python SDK for fiscal document issuance — a handful of business fields, nothing about certificates, XML, XSD, signing or SOAP. The API resolves all of that from the issuer's own configuration, identified by `api_key`.
|
|
20
20
|
|
|
21
|
-
**One class, `Invoice`** — `issue()`/`consult()`/`cancel()`/`reissue()`/`correct()`/`invalidate()`/`pdf()`/`received()`/`manifest()`, nothing else to instantiate. Each line item is a `Product` (`stackin.br`) — `description
|
|
21
|
+
**One class, `Invoice`** — `issue()`/`consult()`/`cancel()`/`reissue()`/`correct()`/`invalidate()`/`pdf()`/`received()`/`manifest()`, nothing else to instantiate. Each line item is a `Product` (`stackin.br`) — `description` plus either `unit_price` or `amount` are universal, everything else (`ncm`/`cfop`/`cest`/tax groups...) is Brazil-specific and only required for NFE; NFSE ignores it.
|
|
22
|
+
|
|
23
|
+
## What a line item is worth
|
|
24
|
+
|
|
25
|
+
`unit_price` is the price of **one unit**. `amount` is the **gross total of
|
|
26
|
+
the line's products**, before discount, freight, insurance and other
|
|
27
|
+
expenses. Send either; sending both asserts that they agree.
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from decimal import Decimal
|
|
31
|
+
|
|
32
|
+
# One unit
|
|
33
|
+
Product(description="Consultoria", quantity=Decimal("1"), unit_price=Decimal("1500.00"))
|
|
34
|
+
|
|
35
|
+
# More than one unit — amount is computed as 2 x 120.00 = 240.00
|
|
36
|
+
Product(description="Teclado", quantity=Decimal("2"), unit_price=Decimal("120.00"))
|
|
37
|
+
|
|
38
|
+
# A fractional quantity — 1.5 x 30.00 = 45.00
|
|
39
|
+
Product(description="Cabo", quantity=Decimal("1.5"), unit_price=Decimal("30.00"))
|
|
40
|
+
|
|
41
|
+
# Legacy: amount alone still means the line's gross total
|
|
42
|
+
Product(description="Servico", quantity=Decimal("3"), amount=Decimal("150.00"))
|
|
43
|
+
|
|
44
|
+
# Both, checked against each other before the document is transmitted
|
|
45
|
+
Product(
|
|
46
|
+
description="Teclado",
|
|
47
|
+
quantity=Decimal("2"),
|
|
48
|
+
unit_price=Decimal("120.00"),
|
|
49
|
+
amount=Decimal("240.00"),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# With charges: 5000.00 - 100.50 + 40.00 + 10.00 = 4949.50 on the note
|
|
53
|
+
Product(
|
|
54
|
+
description="Servidor",
|
|
55
|
+
quantity=Decimal("2"),
|
|
56
|
+
unit_price=Decimal("2500.00"),
|
|
57
|
+
discount=100.50,
|
|
58
|
+
freight=40.00,
|
|
59
|
+
insurance=10.00,
|
|
60
|
+
)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Amounts that do not add up are refused before the authorizer sees them,
|
|
64
|
+
with a `422` naming the line and both numbers:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"detail": {
|
|
69
|
+
"code": "ITEM_TOTAL_MISMATCH",
|
|
70
|
+
"field": "items[0].amount",
|
|
71
|
+
"message": "amount is 50.00, but quantity x unit_price is 150.00.",
|
|
72
|
+
"expected": "150.00",
|
|
73
|
+
"received": "50.00"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Migrating
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
Before: quantity = 3, amount = 150.00
|
|
82
|
+
After: quantity = 3, unit_price = 50.00
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Nothing has to migrate. `amount` keeps the meaning it always had and is
|
|
86
|
+
not deprecated in this release; a line sent with `amount` alone is built
|
|
87
|
+
exactly as it was before.
|
|
22
88
|
|
|
23
89
|
## Install
|
|
24
90
|
|
|
@@ -31,6 +97,8 @@ pip install stackin-python-sdk
|
|
|
31
97
|
Get an `api_key` from the [stackin dashboard](https://app.stackin.io) — select the issuing company, then Settings → API key (context `sdk`). One key per issuing company, shown once at creation. The API resolves the issuer (CNPJ, state, address, certificate, environment) entirely from it; nothing about the issuer is ever passed on a call.
|
|
32
98
|
|
|
33
99
|
```python
|
|
100
|
+
from decimal import Decimal
|
|
101
|
+
|
|
34
102
|
from stackin import Invoice, DocumentType, Address
|
|
35
103
|
from stackin.br import Product # Brazil-specific line item — NCM/CFOP
|
|
36
104
|
|
|
@@ -61,7 +129,16 @@ client.issue(
|
|
|
61
129
|
document_type=DocumentType.NFE,
|
|
62
130
|
client_name="Buyer Company Ltd",
|
|
63
131
|
tax_id="11111111111111",
|
|
64
|
-
items=[
|
|
132
|
+
items=[
|
|
133
|
+
Product(
|
|
134
|
+
description="Teclado",
|
|
135
|
+
quantity=Decimal("2"),
|
|
136
|
+
unit_price=Decimal("120.00"),
|
|
137
|
+
unit="UN",
|
|
138
|
+
ncm="84716052",
|
|
139
|
+
cfop="5102",
|
|
140
|
+
)
|
|
141
|
+
],
|
|
65
142
|
recipient_address=Address(
|
|
66
143
|
street="Avenida Atlantica",
|
|
67
144
|
number="500",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "stackin-python-sdk"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.8.0"
|
|
4
4
|
authors = [
|
|
5
5
|
{ name = "Fernando Celmer", email = "email@fernandocelmer.com" },
|
|
6
6
|
]
|
|
@@ -45,7 +45,7 @@ Changelog = "https://github.com/stackin-io/stackin-python-sdk/releases"
|
|
|
45
45
|
|
|
46
46
|
[tool.poetry]
|
|
47
47
|
name = "stackin-python-sdk"
|
|
48
|
-
version = "0.
|
|
48
|
+
version = "0.8.0"
|
|
49
49
|
description = "Python SDK for issuing, consulting and cancelling electronic invoices."
|
|
50
50
|
authors = ["Fernando Celmer <email@fernandocelmer.com>"]
|
|
51
51
|
readme = "README.md"
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from decimal import Decimal
|
|
5
6
|
from typing import Annotated, Any
|
|
6
7
|
|
|
7
8
|
from pydantic import BaseModel, Field
|
|
@@ -36,11 +37,17 @@ _BR_FIELDS = {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
|
|
40
|
+
def _decimal_str(value: Decimal | None) -> str | None:
|
|
41
|
+
"""JSON has no decimal; a float would lose the tenth place."""
|
|
42
|
+
return None if value is None else format(value, "f")
|
|
43
|
+
|
|
44
|
+
|
|
39
45
|
class Product(BaseModel):
|
|
40
46
|
"""One product or service line item on an invoice."""
|
|
41
47
|
|
|
42
48
|
description: str = Field(..., min_length=1)
|
|
43
|
-
amount:
|
|
49
|
+
amount: Decimal | None = Field(default=None, gt=0)
|
|
50
|
+
unit_price: Decimal | None = Field(default=None, gt=0)
|
|
44
51
|
unit: str = Field(default="UN")
|
|
45
52
|
quantity: float = Field(default=1.0, gt=0)
|
|
46
53
|
barcode: str | None = Field(default=None)
|
|
@@ -102,6 +109,7 @@ class Product(BaseModel):
|
|
|
102
109
|
exclude={
|
|
103
110
|
"description",
|
|
104
111
|
"amount",
|
|
112
|
+
"unit_price",
|
|
105
113
|
"tax",
|
|
106
114
|
*_BR_FIELDS,
|
|
107
115
|
*_NFSE_FIELDS,
|
|
@@ -116,7 +124,8 @@ class Product(BaseModel):
|
|
|
116
124
|
data["br"] = br
|
|
117
125
|
return {
|
|
118
126
|
"description": self.description,
|
|
119
|
-
"amount": self.amount,
|
|
127
|
+
"amount": _decimal_str(self.amount),
|
|
128
|
+
"unit_price": _decimal_str(self.unit_price),
|
|
120
129
|
"product": data,
|
|
121
130
|
"service_code": self.service_code,
|
|
122
131
|
"discount": self.service_discount,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|