3
3
from .api_service import FlickAPI , Config
4
4
5
5
6
- class Devices ():
6
+ class Device ():
7
7
""" The Devices class. """
8
8
9
9
def __init__ (self , device_name : str , city : str , city_subdiv : str , street : str , plot : str , building : str , postal : str , branch_name : str , branch_industry : str , otp : str ):
@@ -23,7 +23,7 @@ def __init__(self, device_name: str, city: str, city_subdiv: str, street: str, p
23
23
class EGSData :
24
24
""" The EGSData class. """
25
25
26
- def __init__ (self , vat_name : str , vat_number : str , devices : List [Devices ]):
26
+ def __init__ (self , vat_name : str , vat_number : str , devices : List [Device ]):
27
27
"""
28
28
Initializes an instance of EGSData.
29
29
@@ -36,7 +36,8 @@ def __init__(self, vat_name: str, vat_number: str, devices: List[Devices]):
36
36
self .vat_number = vat_number
37
37
self .devices = devices
38
38
39
- def to_json (self ):
39
+ def to_dict (self ):
40
+ """ function to convert class to dictionary """
40
41
41
42
out = {
42
43
"vat_name" : self .vat_name ,
@@ -89,7 +90,8 @@ def __init__(self,
89
90
self .building = building
90
91
self .postal_zone = postal_zone
91
92
92
- def to_json (self ):
93
+ def to_dict (self ):
94
+ """ function to convert class to dictionary """
93
95
94
96
out = {
95
97
"party_name_ar" : self .party_name_ar ,
@@ -121,7 +123,7 @@ def __init__(self, invoice_id: str, issue_date: str, issue_time: str):
121
123
self .issue_time = issue_time
122
124
123
125
124
- class LineItems :
126
+ class LineItem :
125
127
""" The LineItems class. """
126
128
127
129
def __init__ (self ,
@@ -140,7 +142,7 @@ def __init__(self,
140
142
self .tax_percentage = tax_percentage
141
143
142
144
143
- class AdvanceInvoices :
145
+ class AdvanceInvoice :
144
146
""" The AdvanceInvoices class. """
145
147
146
148
def __init__ (self ,
@@ -155,7 +157,8 @@ def __init__(self,
155
157
self .tax_amount = tax_amount
156
158
self .invoices = invoices
157
159
158
- def to_json (self ):
160
+ def to_dict (self ):
161
+ """ function to convert class to dictionary """
159
162
160
163
out = {
161
164
"tax_category" : self .tax_category ,
@@ -177,21 +180,22 @@ class AdvanceDetails:
177
180
def __init__ (self ,
178
181
advance_amount : float ,
179
182
total_amount : float ,
180
- advance_invoices : AdvanceInvoices
183
+ advance_invoices : AdvanceInvoice
181
184
):
182
185
self .advance_amount = advance_amount
183
186
self .total_amount = total_amount
184
187
self .advance_invoices = advance_invoices
185
188
186
- def to_json (self ):
189
+ def to_dict (self ):
190
+ """ function to convert class to dictionary """
187
191
188
192
out = {
189
193
"advance_amount" : self .advance_amount ,
190
194
"total_amount" : self .total_amount ,
191
195
}
192
196
advance_invoices = []
193
197
for advance_invoice in self .advance_invoices :
194
- advance_invoices .append (advance_invoice .to_json ())
198
+ advance_invoices .append (advance_invoice .to_dict ())
195
199
out ["advance_invoices" ] = advance_invoices
196
200
197
201
return out
@@ -208,7 +212,7 @@ def __init__(self,
208
212
doc_type : str ,
209
213
inv_type : str ,
210
214
payment_method : int ,
211
- lineitems : LineItems ,
215
+ lineitems : LineItem ,
212
216
party_details : PartyDetails ,
213
217
advance_details : AdvanceDetails = None ,
214
218
has_advance : bool = None ,
@@ -228,7 +232,8 @@ def __init__(self,
228
232
self .total_tax = total_tax
229
233
self .lineitems = lineitems
230
234
231
- def to_json (self ):
235
+ def to_dict (self ):
236
+ """ function to convert class to dictionary """
232
237
233
238
out = {
234
239
"egs_uuid" : self .egs_uuid ,
@@ -242,12 +247,12 @@ def to_json(self):
242
247
"currency" : self .currency ,
243
248
"total_tax" : self .total_tax ,
244
249
}
245
- out ["party_details" ] = self .party_details .to_json ()
250
+ out ["party_details" ] = self .party_details .to_dict ()
246
251
lineitems = []
247
252
for lineitem in self .lineitems :
248
253
lineitems .append (lineitem .__dict__ )
249
254
out ["lineitems" ] = lineitems
250
- out ["advance_details" ] = self .advance_details .to_json ()
255
+ out ["advance_details" ] = self .advance_details .to_dict ()
251
256
252
257
return out
253
258
@@ -305,7 +310,7 @@ async def onboard_egs(self, egs_data: EGSData):
305
310
306
311
try :
307
312
async with FlickAPI (config = self .config ) as session :
308
- async with session .request ('POST' , '/egs/onboard' , data = json .dumps (egs_data .to_json ())) as response :
313
+ async with session .request ('POST' , '/egs/onboard' , data = json .dumps (egs_data .to_dict ())) as response :
309
314
if response .status == 200 :
310
315
response_text = await response .text ()
311
316
# Process the response data here
@@ -360,7 +365,7 @@ async def generate_invoice(self, invoice_data: InvoiceData):
360
365
"""
361
366
try :
362
367
async with FlickAPI (config = self .config ) as session :
363
- async with session .request ('POST' , '/invoice/generate' , data = json .dumps (invoice_data .to_json ())) as response :
368
+ async with session .request ('POST' , '/invoice/generate' , data = json .dumps (invoice_data .to_dict ())) as response :
364
369
if response .status == 200 :
365
370
response_text = await response .text ()
366
371
# Process the response data here
0 commit comments