Skip to content

Commit e0585c1

Browse files
authored
feat(presentation_group_keys): Support presentation group keys feature (#399)
- Update responses of usage, projected and current usage - Update invoice to include fee presentation_breakdowns - Add option to filter_by_presentation in current_usage
1 parent fd6d0d5 commit e0585c1

17 files changed

Lines changed: 241 additions & 9 deletions

lago_python_client/customers/clients.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def current_usage(
4747
filter_by_charge_id: Optional[str] = None,
4848
filter_by_charge_code: Optional[str] = None,
4949
filter_by_group: Optional[dict] = None,
50+
filter_by_presentation: Optional[Union[str, list[str]]] = None,
5051
full_usage: Optional[bool] = None,
5152
charge_id: Optional[str] = None,
5253
charge_code: Optional[str] = None,
@@ -76,6 +77,12 @@ def current_usage(
7677
if filter_by_group is not None:
7778
warnings.warn("filter_by_group is deprecated, use group instead", DeprecationWarning, stacklevel=2)
7879
query_params["filter_by_group"] = json.dumps(filter_by_group)
80+
if filter_by_presentation is not None:
81+
query_params["filter_by_presentation"] = (
82+
filter_by_presentation
83+
if isinstance(filter_by_presentation, str)
84+
else json.dumps(filter_by_presentation)
85+
)
7986
if full_usage is not None:
8087
query_params["full_usage"] = str(full_usage).lower()
8188

lago_python_client/models/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@
138138
from .customer_usage import (
139139
Metric as Metric,
140140
)
141+
from .customer_usage import (
142+
PresentationBreakdown as PresentationBreakdown,
143+
)
144+
from .customer_usage import (
145+
PresentationBreakdowns as PresentationBreakdowns,
146+
)
141147
from .event import BatchEvent as BatchEvent
142148
from .event import Event as Event
143149
from .fee import Fee as Fee

lago_python_client/models/customer_projected_usage.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from lago_python_client.base_model import BaseModel
44

55
from ..base_model import BaseResponseModel
6+
from .customer_usage import PresentationBreakdowns
67

78

89
class Metric(BaseModel):
@@ -27,6 +28,8 @@ class ProjectedChargeFilterUsage(BaseModel):
2728
projected_amount_cents: int
2829
events_count: int
2930
pricing_unit_details: Optional[PricingUnitDetails]
31+
presentation_breakdowns: Optional[PresentationBreakdowns]
32+
projected_presentation_breakdowns: Optional[PresentationBreakdowns]
3033

3134

3235
class ChargeObject(BaseModel):
@@ -44,6 +47,8 @@ class ProjectedGroupedUsage(BaseModel):
4447
grouped_by: Dict[str, Optional[str]]
4548
filters: List[ProjectedChargeFilterUsage]
4649
pricing_unit_details: Optional[PricingUnitDetails]
50+
presentation_breakdowns: Optional[PresentationBreakdowns]
51+
projected_presentation_breakdowns: Optional[PresentationBreakdowns]
4752

4853

4954
class ProjectedChargeUsage(BaseModel):
@@ -58,6 +63,8 @@ class ProjectedChargeUsage(BaseModel):
5863
filters: List[ProjectedChargeFilterUsage]
5964
grouped_usage: Optional[List[ProjectedGroupedUsage]]
6065
pricing_unit_details: Optional[PricingUnitDetails]
66+
presentation_breakdowns: Optional[PresentationBreakdowns]
67+
projected_presentation_breakdowns: Optional[PresentationBreakdowns]
6168

6269

6370
class CustomerProjectedUsageResponse(BaseResponseModel):

lago_python_client/models/customer_usage.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ class PricingUnitDetails(BaseModel):
1818
conversion_rate: float
1919

2020

21+
class PresentationBreakdown(BaseModel):
22+
presentation_by: Dict[str, str]
23+
units: str
24+
25+
26+
class PresentationBreakdowns(BaseModel):
27+
__root__: List[PresentationBreakdown]
28+
29+
2130
class ChargeFilterUsage(BaseModel):
2231
invoice_display_name: Optional[str]
2332
values: Optional[Dict[str, List[str]]]
@@ -26,6 +35,7 @@ class ChargeFilterUsage(BaseModel):
2635
amount_cents: int
2736
events_count: int
2837
pricing_unit_details: Optional[PricingUnitDetails]
38+
presentation_breakdowns: Optional[PresentationBreakdowns]
2939

3040

3141
class ChargeObject(BaseModel):
@@ -42,6 +52,7 @@ class GroupedUsage(BaseModel):
4252
grouped_by: Dict[str, Optional[str]]
4353
filters: List[ChargeFilterUsage]
4454
pricing_unit_details: Optional[PricingUnitDetails]
55+
presentation_breakdowns: Optional[PresentationBreakdowns]
4556

4657

4758
class ChargeUsage(BaseModel):
@@ -55,6 +66,7 @@ class ChargeUsage(BaseModel):
5566
filters: List[ChargeFilterUsage]
5667
grouped_usage: Optional[List[GroupedUsage]]
5768
pricing_unit_details: Optional[PricingUnitDetails]
69+
presentation_breakdowns: Optional[PresentationBreakdowns]
5870

5971

6072
class CustomerUsageResponse(BaseResponseModel):

lago_python_client/models/fee.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, Dict, List, Optional
22

33
from ..base_model import BaseModel, BaseResponseModel
4+
from .customer_usage import PresentationBreakdowns
45
from .invoice_item import InvoiceItemResponse
56

67

@@ -75,6 +76,7 @@ class FeeResponse(BaseResponseModel):
7576
to_date: Optional[str]
7677
amount_details: Optional[Dict[str, Any]]
7778
pricing_unit_details: Optional[PricingUnitDetails]
79+
presentation_breakdowns: Optional[PresentationBreakdowns]
7880
billing_entity_code: Optional[str]
7981

8082
item: Optional[InvoiceItemResponse]

tests/fixtures/charge.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
"min_amount_cents": 0,
1313
"prorated": false,
1414
"properties": {
15-
"amount": "0.22"
15+
"amount": "0.22",
16+
"presentation_group_keys": [
17+
{
18+
"value": "region",
19+
"options": {
20+
"display_in_invoice": true
21+
}
22+
}
23+
]
1624
},
1725
"filters": [],
1826
"taxes": [],

tests/fixtures/customer_past_usage.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,23 @@
4646
"amount_cents": 123,
4747
"short_name": "CR",
4848
"conversion_rate": 1.0
49-
}
49+
},
50+
"presentation_breakdowns": [
51+
{
52+
"presentation_by": {
53+
"team": "engineering"
54+
},
55+
"units": "2.0"
56+
}
57+
]
58+
}
59+
],
60+
"presentation_breakdowns": [
61+
{
62+
"presentation_by": {
63+
"team": "engineering"
64+
},
65+
"units": "3.0"
5066
}
5167
]
5268
}

tests/fixtures/customer_projected_usage.json

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,23 @@
4949
"amount_cents": 123,
5050
"short_name": "CR",
5151
"conversion_rate": 1.0
52-
}
52+
},
53+
"presentation_breakdowns": [
54+
{
55+
"presentation_by": {
56+
"team": "engineering"
57+
},
58+
"units": "2.0"
59+
}
60+
],
61+
"projected_presentation_breakdowns": [
62+
{
63+
"presentation_by": {
64+
"team": "engineering"
65+
},
66+
"units": "4.0"
67+
}
68+
]
5369
}
5470
],
5571
"grouped_usage": [
@@ -67,6 +83,22 @@
6783
"short_name": "CR",
6884
"conversion_rate": 1.2
6985
},
86+
"presentation_breakdowns": [
87+
{
88+
"presentation_by": {
89+
"team": "operations"
90+
},
91+
"units": "1.0"
92+
}
93+
],
94+
"projected_presentation_breakdowns": [
95+
{
96+
"presentation_by": {
97+
"team": "operations"
98+
},
99+
"units": "2.0"
100+
}
101+
],
70102
"filters": [
71103
{
72104
"units": "3.0",
@@ -79,10 +111,42 @@
79111
"france"
80112
]
81113
},
82-
"pricing_unit_details": null
114+
"pricing_unit_details": null,
115+
"presentation_breakdowns": [
116+
{
117+
"presentation_by": {
118+
"team": "support"
119+
},
120+
"units": "1.0"
121+
}
122+
],
123+
"projected_presentation_breakdowns": [
124+
{
125+
"presentation_by": {
126+
"team": "support"
127+
},
128+
"units": "2.0"
129+
}
130+
]
83131
}
84132
]
85133
}
134+
],
135+
"presentation_breakdowns": [
136+
{
137+
"presentation_by": {
138+
"team": "engineering"
139+
},
140+
"units": "3.0"
141+
}
142+
],
143+
"projected_presentation_breakdowns": [
144+
{
145+
"presentation_by": {
146+
"team": "engineering"
147+
},
148+
"units": "6.0"
149+
}
86150
]
87151
}
88152
]

tests/fixtures/customer_usage.json

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@
4646
"amount_cents": 123,
4747
"short_name": "CR",
4848
"conversion_rate": 1.0
49-
}
49+
},
50+
"presentation_breakdowns": [
51+
{
52+
"presentation_by": {
53+
"team": "engineering"
54+
},
55+
"units": "2.0"
56+
}
57+
]
5058
}
5159
],
5260
"grouped_usage": [
@@ -63,6 +71,14 @@
6371
"short_name": "CR",
6472
"conversion_rate": 1.2
6573
},
74+
"presentation_breakdowns": [
75+
{
76+
"presentation_by": {
77+
"team": "operations"
78+
},
79+
"units": "1.0"
80+
}
81+
],
6682
"filters": [
6783
{
6884
"units": "3.0",
@@ -74,10 +90,26 @@
7490
"france"
7591
]
7692
},
77-
"pricing_unit_details": null
93+
"pricing_unit_details": null,
94+
"presentation_breakdowns": [
95+
{
96+
"presentation_by": {
97+
"team": "support"
98+
},
99+
"units": "1.0"
100+
}
101+
]
78102
}
79103
]
80104
}
105+
],
106+
"presentation_breakdowns": [
107+
{
108+
"presentation_by": {
109+
"team": "engineering"
110+
},
111+
"units": "3.0"
112+
}
81113
]
82114
}
83115
]

tests/fixtures/fee.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
"precise_unit_amount": "12.00",
4040
"conversion_rate": 1.0
4141
},
42+
"presentation_breakdowns": [
43+
{
44+
"presentation_by": {
45+
"team": "engineering"
46+
},
47+
"units": "10.0"
48+
}
49+
],
4250
"applied_taxes": [
4351
{
4452
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",

0 commit comments

Comments
 (0)