Skip to content

Commit d5f37d9

Browse files
authored
feat(billing): list discounts in v2beta1 and update list consumptions response (#418)
1 parent 1fc6d4f commit d5f37d9

File tree

8 files changed

+742
-24
lines changed

8 files changed

+742
-24
lines changed

scaleway-async/scaleway_async/billing/v2beta1/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,45 @@
11
# This file was automatically generated. DO NOT EDIT.
22
# If you have any remark or suggestion do not hesitate to open an issue.
3+
from .types import DiscountDiscountMode
4+
from .types import DiscountFilterType
35
from .types import DownloadInvoiceRequestFileType
46
from .types import ExportInvoicesRequestFileType
57
from .types import ExportInvoicesRequestOrderBy
68
from .types import InvoiceType
79
from .types import ListConsumptionsRequestOrderBy
10+
from .types import ListDiscountsRequestOrderBy
811
from .types import ListInvoicesRequestOrderBy
912
from .types import ListTaxesRequestOrderBy
13+
from .types import Discount
14+
from .types import DiscountCoupon
15+
from .types import DiscountFilter
1016
from .types import Invoice
1117
from .types import ListConsumptionsResponse
1218
from .types import ListConsumptionsResponseConsumption
19+
from .types import ListDiscountsResponse
1320
from .types import ListInvoicesResponse
1421
from .types import ListTaxesResponse
1522
from .types import ListTaxesResponseTax
1623
from .api import BillingV2Beta1API
1724

1825
__all__ = [
26+
"DiscountDiscountMode",
27+
"DiscountFilterType",
1928
"DownloadInvoiceRequestFileType",
2029
"ExportInvoicesRequestFileType",
2130
"ExportInvoicesRequestOrderBy",
2231
"InvoiceType",
2332
"ListConsumptionsRequestOrderBy",
33+
"ListDiscountsRequestOrderBy",
2434
"ListInvoicesRequestOrderBy",
2535
"ListTaxesRequestOrderBy",
36+
"Discount",
37+
"DiscountCoupon",
38+
"DiscountFilter",
2639
"Invoice",
2740
"ListConsumptionsResponse",
2841
"ListConsumptionsResponseConsumption",
42+
"ListDiscountsResponse",
2943
"ListInvoicesResponse",
3044
"ListTaxesResponse",
3145
"ListTaxesResponseTax",

scaleway-async/scaleway_async/billing/v2beta1/api.py

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,22 @@
2121
ExportInvoicesRequestOrderBy,
2222
InvoiceType,
2323
ListConsumptionsRequestOrderBy,
24+
ListDiscountsRequestOrderBy,
2425
ListInvoicesRequestOrderBy,
2526
ListTaxesRequestOrderBy,
27+
Discount,
2628
Invoice,
2729
ListConsumptionsResponse,
2830
ListConsumptionsResponseConsumption,
31+
ListDiscountsResponse,
2932
ListInvoicesResponse,
3033
ListTaxesResponse,
3134
ListTaxesResponseTax,
3235
)
3336
from .marshalling import (
3437
unmarshal_Invoice,
3538
unmarshal_ListConsumptionsResponse,
39+
unmarshal_ListDiscountsResponse,
3640
unmarshal_ListInvoicesResponse,
3741
unmarshal_ListTaxesResponse,
3842
)
@@ -49,7 +53,7 @@ class BillingV2Beta1API(API):
4953
async def list_consumptions(
5054
self,
5155
*,
52-
order_by: ListConsumptionsRequestOrderBy = ListConsumptionsRequestOrderBy.UPDATED_AT_DATE_DESC,
56+
order_by: ListConsumptionsRequestOrderBy = ListConsumptionsRequestOrderBy.UPDATED_AT_DESC,
5357
page: Optional[int] = None,
5458
page_size: Optional[int] = None,
5559
organization_id: Optional[str] = None,
@@ -157,7 +161,7 @@ async def list_consumptions_all(
157161
async def list_taxes(
158162
self,
159163
*,
160-
order_by: ListTaxesRequestOrderBy = ListTaxesRequestOrderBy.UPDATED_AT_DATE_DESC,
164+
order_by: ListTaxesRequestOrderBy = ListTaxesRequestOrderBy.UPDATED_AT_DESC,
161165
page: Optional[int] = None,
162166
page_size: Optional[int] = None,
163167
organization_id: Optional[str] = None,
@@ -441,3 +445,63 @@ async def download_invoice(
441445
self._throw_on_error(res)
442446
json = res.json()
443447
return unmarshal_ScwFile(json) if json is not None else None
448+
449+
async def list_discounts(
450+
self,
451+
*,
452+
order_by: ListDiscountsRequestOrderBy = ListDiscountsRequestOrderBy.CREATION_DATE_DESC,
453+
page: Optional[int] = None,
454+
page_size: Optional[int] = None,
455+
organization_id: Optional[str] = None,
456+
) -> ListDiscountsResponse:
457+
"""
458+
459+
Usage:
460+
::
461+
462+
result = await api.list_discounts()
463+
"""
464+
465+
res = self._request(
466+
"GET",
467+
f"/billing/v2beta1/discounts",
468+
params={
469+
"order_by": order_by,
470+
"organization_id": organization_id
471+
or self.client.default_organization_id,
472+
"page": page,
473+
"page_size": page_size or self.client.default_page_size,
474+
},
475+
)
476+
477+
self._throw_on_error(res)
478+
return unmarshal_ListDiscountsResponse(res.json())
479+
480+
async def list_discounts_all(
481+
self,
482+
*,
483+
order_by: Optional[ListDiscountsRequestOrderBy] = None,
484+
page: Optional[int] = None,
485+
page_size: Optional[int] = None,
486+
organization_id: Optional[str] = None,
487+
) -> List[Discount]:
488+
"""
489+
:return: :class:`List[ListDiscountsResponse] <List[ListDiscountsResponse]>`
490+
491+
Usage:
492+
::
493+
494+
result = await api.list_discounts_all()
495+
"""
496+
497+
return await fetch_all_pages_async(
498+
type=ListDiscountsResponse,
499+
key="discounts",
500+
fetcher=self.list_discounts,
501+
args={
502+
"order_by": order_by,
503+
"page": page,
504+
"page_size": page_size,
505+
"organization_id": organization_id,
506+
},
507+
)

scaleway-async/scaleway_async/billing/v2beta1/marshalling.py

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,99 @@
88
)
99
from dateutil import parser
1010
from .types import (
11+
Discount,
12+
DiscountCoupon,
13+
DiscountFilter,
1114
Invoice,
1215
ListConsumptionsResponse,
1316
ListConsumptionsResponseConsumption,
17+
ListDiscountsResponse,
1418
ListInvoicesResponse,
1519
ListTaxesResponse,
1620
ListTaxesResponseTax,
1721
)
1822

1923

24+
def unmarshal_DiscountCoupon(data: Any) -> DiscountCoupon:
25+
if type(data) is not dict:
26+
raise TypeError(
27+
f"Unmarshalling the type 'DiscountCoupon' failed as data isn't a dictionary."
28+
)
29+
30+
args: Dict[str, Any] = {}
31+
32+
field = data.get("description", None)
33+
args["description"] = field
34+
35+
return DiscountCoupon(**args)
36+
37+
38+
def unmarshal_DiscountFilter(data: Any) -> DiscountFilter:
39+
if type(data) is not dict:
40+
raise TypeError(
41+
f"Unmarshalling the type 'DiscountFilter' failed as data isn't a dictionary."
42+
)
43+
44+
args: Dict[str, Any] = {}
45+
46+
field = data.get("type", None)
47+
args["type_"] = field
48+
49+
field = data.get("value", None)
50+
args["value"] = field
51+
52+
return DiscountFilter(**args)
53+
54+
55+
def unmarshal_Discount(data: Any) -> Discount:
56+
if type(data) is not dict:
57+
raise TypeError(
58+
f"Unmarshalling the type 'Discount' failed as data isn't a dictionary."
59+
)
60+
61+
args: Dict[str, Any] = {}
62+
63+
field = data.get("coupon", None)
64+
args["coupon"] = unmarshal_DiscountCoupon(field) if field is not None else None
65+
66+
field = data.get("creation_date", None)
67+
args["creation_date"] = parser.isoparse(field) if type(field) is str else field
68+
69+
field = data.get("description", None)
70+
args["description"] = field
71+
72+
field = data.get("filters", None)
73+
args["filters"] = (
74+
[unmarshal_DiscountFilter(v) for v in field] if field is not None else None
75+
)
76+
77+
field = data.get("id", None)
78+
args["id"] = field
79+
80+
field = data.get("mode", None)
81+
args["mode"] = field
82+
83+
field = data.get("organization_id", None)
84+
args["organization_id"] = field
85+
86+
field = data.get("start_date", None)
87+
args["start_date"] = parser.isoparse(field) if type(field) is str else field
88+
89+
field = data.get("stop_date", None)
90+
args["stop_date"] = parser.isoparse(field) if type(field) is str else field
91+
92+
field = data.get("value", None)
93+
args["value"] = field
94+
95+
field = data.get("value_remaining", None)
96+
args["value_remaining"] = field
97+
98+
field = data.get("value_used", None)
99+
args["value_used"] = field
100+
101+
return Discount(**args)
102+
103+
20104
def unmarshal_Invoice(data: Any) -> Invoice:
21105
if type(data) is not dict:
22106
raise TypeError(
@@ -28,9 +112,6 @@ def unmarshal_Invoice(data: Any) -> Invoice:
28112
field = data.get("billing_period", None)
29113
args["billing_period"] = parser.isoparse(field) if type(field) is str else field
30114

31-
field = data.get("customer_name", None)
32-
args["customer_name"] = field
33-
34115
field = data.get("due_date", None)
35116
args["due_date"] = parser.isoparse(field) if type(field) is str else field
36117

@@ -92,6 +173,9 @@ def unmarshal_ListConsumptionsResponseConsumption(
92173

93174
args: Dict[str, Any] = {}
94175

176+
field = data.get("billed_quantity", None)
177+
args["billed_quantity"] = field
178+
95179
field = data.get("category_name", None)
96180
args["category_name"] = field
97181

@@ -107,6 +191,9 @@ def unmarshal_ListConsumptionsResponseConsumption(
107191
field = data.get("sku", None)
108192
args["sku"] = field
109193

194+
field = data.get("unit", None)
195+
args["unit"] = field
196+
110197
field = data.get("value", None)
111198
args["value"] = unmarshal_Money(field) if field is not None else None
112199

@@ -163,6 +250,25 @@ def unmarshal_ListConsumptionsResponse(data: Any) -> ListConsumptionsResponse:
163250
return ListConsumptionsResponse(**args)
164251

165252

253+
def unmarshal_ListDiscountsResponse(data: Any) -> ListDiscountsResponse:
254+
if type(data) is not dict:
255+
raise TypeError(
256+
f"Unmarshalling the type 'ListDiscountsResponse' failed as data isn't a dictionary."
257+
)
258+
259+
args: Dict[str, Any] = {}
260+
261+
field = data.get("discounts", None)
262+
args["discounts"] = (
263+
[unmarshal_Discount(v) for v in field] if field is not None else None
264+
)
265+
266+
field = data.get("total_count", None)
267+
args["total_count"] = field
268+
269+
return ListDiscountsResponse(**args)
270+
271+
166272
def unmarshal_ListInvoicesResponse(data: Any) -> ListInvoicesResponse:
167273
if type(data) is not dict:
168274
raise TypeError(

0 commit comments

Comments
 (0)