Skip to content

Commit 266c259

Browse files
feat(api): api update
1 parent e07f048 commit 266c259

File tree

4 files changed

+103
-28
lines changed

4 files changed

+103
-28
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 118
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-b070c1d97a6e3b400f43d2bce36c22ed89d432345b26374728c55dd0a20f0afa.yml
3-
openapi_spec_hash: dba4ff52c381cda6159fc56d8b77eb32
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-15e42bc01739abea4a925894a1a7de447de40b003a3433461952e8e06919588b.yml
3+
openapi_spec_hash: 8a0bc5b6ab417f7256cbf83d70c459a3
44
config_hash: 1f73a949b649ecfe6ec68ba1bb459dc2

src/orb/resources/invoice_line_items.py

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
from __future__ import annotations
44

5-
from typing import Union
5+
from typing import Union, Optional
66
from datetime import date
77

88
import httpx
99

1010
from .. import _legacy_response
1111
from ..types import invoice_line_item_create_params
12-
from .._types import Body, Query, Headers, NotGiven, not_given
12+
from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
1313
from .._utils import maybe_transform, async_maybe_transform
1414
from .._compat import cached_property
1515
from .._resource import SyncAPIResource, AsyncAPIResource
@@ -46,9 +46,10 @@ def create(
4646
amount: str,
4747
end_date: Union[str, date],
4848
invoice_id: str,
49-
name: str,
5049
quantity: float,
5150
start_date: Union[str, date],
51+
item_id: Optional[str] | Omit = omit,
52+
name: Optional[str] | Omit = omit,
5253
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
5354
# The extra values given here take precedence over values defined on the client or passed to this method.
5455
extra_headers: Headers | None = None,
@@ -62,20 +63,40 @@ def create(
6263
This can only
6364
be done for invoices that are in a `draft` status.
6465
66+
The behavior depends on which parameters are provided:
67+
68+
- If `item_id` is provided without `name`: The item is looked up by ID, and the
69+
item's name is used for the line item.
70+
- If `name` is provided without `item_id`: An item with the given name is
71+
searched for in the account. If found, that item is used. If not found, a new
72+
item is created with that name. The new item's name is used for the line item.
73+
- If both `item_id` and `name` are provided: The item is looked up by ID for
74+
association, but the provided `name` is used for the line item (not the item's
75+
name).
76+
6577
Args:
6678
amount: The total amount in the invoice's currency to add to the line item.
6779
6880
end_date: A date string to specify the line item's end date in the customer's timezone.
6981
7082
invoice_id: The id of the Invoice to add this line item.
7183
72-
name: The item name associated with this line item. If an item with the same name
73-
exists in Orb, that item will be associated with the line item.
74-
7584
quantity: The number of units on the line item
7685
7786
start_date: A date string to specify the line item's start date in the customer's timezone.
7887
88+
item_id: The id of the item to associate with this line item. If provided without `name`,
89+
the item's name will be used for the price/line item. If provided with `name`,
90+
the item will be associated but `name` will be used for the line item. At least
91+
one of `name` or `item_id` must be provided.
92+
93+
name: The name to use for the line item. If `item_id` is not provided, Orb will search
94+
for an item with this name. If found, that item will be associated with the line
95+
item. If not found, a new item will be created with this name. If `item_id` is
96+
provided, this name will be used for the line item, but the item association
97+
will be based on `item_id`. At least one of `name` or `item_id` must be
98+
provided.
99+
79100
extra_headers: Send extra headers
80101
81102
extra_query: Add additional query parameters to the request
@@ -93,9 +114,10 @@ def create(
93114
"amount": amount,
94115
"end_date": end_date,
95116
"invoice_id": invoice_id,
96-
"name": name,
97117
"quantity": quantity,
98118
"start_date": start_date,
119+
"item_id": item_id,
120+
"name": name,
99121
},
100122
invoice_line_item_create_params.InvoiceLineItemCreateParams,
101123
),
@@ -136,9 +158,10 @@ async def create(
136158
amount: str,
137159
end_date: Union[str, date],
138160
invoice_id: str,
139-
name: str,
140161
quantity: float,
141162
start_date: Union[str, date],
163+
item_id: Optional[str] | Omit = omit,
164+
name: Optional[str] | Omit = omit,
142165
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
143166
# The extra values given here take precedence over values defined on the client or passed to this method.
144167
extra_headers: Headers | None = None,
@@ -152,20 +175,40 @@ async def create(
152175
This can only
153176
be done for invoices that are in a `draft` status.
154177
178+
The behavior depends on which parameters are provided:
179+
180+
- If `item_id` is provided without `name`: The item is looked up by ID, and the
181+
item's name is used for the line item.
182+
- If `name` is provided without `item_id`: An item with the given name is
183+
searched for in the account. If found, that item is used. If not found, a new
184+
item is created with that name. The new item's name is used for the line item.
185+
- If both `item_id` and `name` are provided: The item is looked up by ID for
186+
association, but the provided `name` is used for the line item (not the item's
187+
name).
188+
155189
Args:
156190
amount: The total amount in the invoice's currency to add to the line item.
157191
158192
end_date: A date string to specify the line item's end date in the customer's timezone.
159193
160194
invoice_id: The id of the Invoice to add this line item.
161195
162-
name: The item name associated with this line item. If an item with the same name
163-
exists in Orb, that item will be associated with the line item.
164-
165196
quantity: The number of units on the line item
166197
167198
start_date: A date string to specify the line item's start date in the customer's timezone.
168199
200+
item_id: The id of the item to associate with this line item. If provided without `name`,
201+
the item's name will be used for the price/line item. If provided with `name`,
202+
the item will be associated but `name` will be used for the line item. At least
203+
one of `name` or `item_id` must be provided.
204+
205+
name: The name to use for the line item. If `item_id` is not provided, Orb will search
206+
for an item with this name. If found, that item will be associated with the line
207+
item. If not found, a new item will be created with this name. If `item_id` is
208+
provided, this name will be used for the line item, but the item association
209+
will be based on `item_id`. At least one of `name` or `item_id` must be
210+
provided.
211+
169212
extra_headers: Send extra headers
170213
171214
extra_query: Add additional query parameters to the request
@@ -183,9 +226,10 @@ async def create(
183226
"amount": amount,
184227
"end_date": end_date,
185228
"invoice_id": invoice_id,
186-
"name": name,
187229
"quantity": quantity,
188230
"start_date": start_date,
231+
"item_id": item_id,
232+
"name": name,
189233
},
190234
invoice_line_item_create_params.InvoiceLineItemCreateParams,
191235
),

src/orb/types/invoice_line_item_create_params.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Union
5+
from typing import Union, Optional
66
from datetime import date
77
from typing_extensions import Required, Annotated, TypedDict
88

@@ -21,15 +21,26 @@ class InvoiceLineItemCreateParams(TypedDict, total=False):
2121
invoice_id: Required[str]
2222
"""The id of the Invoice to add this line item."""
2323

24-
name: Required[str]
25-
"""The item name associated with this line item.
26-
27-
If an item with the same name exists in Orb, that item will be associated with
28-
the line item.
29-
"""
30-
3124
quantity: Required[float]
3225
"""The number of units on the line item"""
3326

3427
start_date: Required[Annotated[Union[str, date], PropertyInfo(format="iso8601")]]
3528
"""A date string to specify the line item's start date in the customer's timezone."""
29+
30+
item_id: Optional[str]
31+
"""The id of the item to associate with this line item.
32+
33+
If provided without `name`, the item's name will be used for the price/line
34+
item. If provided with `name`, the item will be associated but `name` will be
35+
used for the line item. At least one of `name` or `item_id` must be provided.
36+
"""
37+
38+
name: Optional[str]
39+
"""The name to use for the line item.
40+
41+
If `item_id` is not provided, Orb will search for an item with this name. If
42+
found, that item will be associated with the line item. If not found, a new item
43+
will be created with this name. If `item_id` is provided, this name will be used
44+
for the line item, but the item association will be based on `item_id`. At least
45+
one of `name` or `item_id` must be provided.
46+
"""

tests/api_resources/test_invoice_line_items.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,30 @@ def test_method_create(self, client: Orb) -> None:
2424
amount="12.00",
2525
end_date=parse_date("2023-09-22"),
2626
invoice_id="4khy3nwzktxv7",
27-
name="Item Name",
2827
quantity=1,
2928
start_date=parse_date("2023-09-22"),
3029
)
3130
assert_matches_type(InvoiceLineItemCreateResponse, invoice_line_item, path=["response"])
3231

32+
@parametrize
33+
def test_method_create_with_all_params(self, client: Orb) -> None:
34+
invoice_line_item = client.invoice_line_items.create(
35+
amount="12.00",
36+
end_date=parse_date("2023-09-22"),
37+
invoice_id="4khy3nwzktxv7",
38+
quantity=1,
39+
start_date=parse_date("2023-09-22"),
40+
item_id="4khy3nwzktxv7",
41+
name="Item Name",
42+
)
43+
assert_matches_type(InvoiceLineItemCreateResponse, invoice_line_item, path=["response"])
44+
3345
@parametrize
3446
def test_raw_response_create(self, client: Orb) -> None:
3547
response = client.invoice_line_items.with_raw_response.create(
3648
amount="12.00",
3749
end_date=parse_date("2023-09-22"),
3850
invoice_id="4khy3nwzktxv7",
39-
name="Item Name",
4051
quantity=1,
4152
start_date=parse_date("2023-09-22"),
4253
)
@@ -52,7 +63,6 @@ def test_streaming_response_create(self, client: Orb) -> None:
5263
amount="12.00",
5364
end_date=parse_date("2023-09-22"),
5465
invoice_id="4khy3nwzktxv7",
55-
name="Item Name",
5666
quantity=1,
5767
start_date=parse_date("2023-09-22"),
5868
) as response:
@@ -76,19 +86,30 @@ async def test_method_create(self, async_client: AsyncOrb) -> None:
7686
amount="12.00",
7787
end_date=parse_date("2023-09-22"),
7888
invoice_id="4khy3nwzktxv7",
79-
name="Item Name",
8089
quantity=1,
8190
start_date=parse_date("2023-09-22"),
8291
)
8392
assert_matches_type(InvoiceLineItemCreateResponse, invoice_line_item, path=["response"])
8493

94+
@parametrize
95+
async def test_method_create_with_all_params(self, async_client: AsyncOrb) -> None:
96+
invoice_line_item = await async_client.invoice_line_items.create(
97+
amount="12.00",
98+
end_date=parse_date("2023-09-22"),
99+
invoice_id="4khy3nwzktxv7",
100+
quantity=1,
101+
start_date=parse_date("2023-09-22"),
102+
item_id="4khy3nwzktxv7",
103+
name="Item Name",
104+
)
105+
assert_matches_type(InvoiceLineItemCreateResponse, invoice_line_item, path=["response"])
106+
85107
@parametrize
86108
async def test_raw_response_create(self, async_client: AsyncOrb) -> None:
87109
response = await async_client.invoice_line_items.with_raw_response.create(
88110
amount="12.00",
89111
end_date=parse_date("2023-09-22"),
90112
invoice_id="4khy3nwzktxv7",
91-
name="Item Name",
92113
quantity=1,
93114
start_date=parse_date("2023-09-22"),
94115
)
@@ -104,7 +125,6 @@ async def test_streaming_response_create(self, async_client: AsyncOrb) -> None:
104125
amount="12.00",
105126
end_date=parse_date("2023-09-22"),
106127
invoice_id="4khy3nwzktxv7",
107-
name="Item Name",
108128
quantity=1,
109129
start_date=parse_date("2023-09-22"),
110130
) as response:

0 commit comments

Comments
 (0)