33from .api_service import FlickAPI , Config
44
55
6- class Devices ():
6+ class Device ():
77 """ The Devices class. """
88
99 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
2323class EGSData :
2424 """ The EGSData class. """
2525
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 ]):
2727 """
2828 Initializes an instance of EGSData.
2929
@@ -36,7 +36,8 @@ def __init__(self, vat_name: str, vat_number: str, devices: List[Devices]):
3636 self .vat_number = vat_number
3737 self .devices = devices
3838
39- def to_json (self ):
39+ def to_dict (self ):
40+ """ function to convert class to dictionary """
4041
4142 out = {
4243 "vat_name" : self .vat_name ,
@@ -89,7 +90,8 @@ def __init__(self,
8990 self .building = building
9091 self .postal_zone = postal_zone
9192
92- def to_json (self ):
93+ def to_dict (self ):
94+ """ function to convert class to dictionary """
9395
9496 out = {
9597 "party_name_ar" : self .party_name_ar ,
@@ -121,7 +123,7 @@ def __init__(self, invoice_id: str, issue_date: str, issue_time: str):
121123 self .issue_time = issue_time
122124
123125
124- class LineItems :
126+ class LineItem :
125127 """ The LineItems class. """
126128
127129 def __init__ (self ,
@@ -140,7 +142,7 @@ def __init__(self,
140142 self .tax_percentage = tax_percentage
141143
142144
143- class AdvanceInvoices :
145+ class AdvanceInvoice :
144146 """ The AdvanceInvoices class. """
145147
146148 def __init__ (self ,
@@ -155,7 +157,8 @@ def __init__(self,
155157 self .tax_amount = tax_amount
156158 self .invoices = invoices
157159
158- def to_json (self ):
160+ def to_dict (self ):
161+ """ function to convert class to dictionary """
159162
160163 out = {
161164 "tax_category" : self .tax_category ,
@@ -177,21 +180,22 @@ class AdvanceDetails:
177180 def __init__ (self ,
178181 advance_amount : float ,
179182 total_amount : float ,
180- advance_invoices : AdvanceInvoices
183+ advance_invoices : AdvanceInvoice
181184 ):
182185 self .advance_amount = advance_amount
183186 self .total_amount = total_amount
184187 self .advance_invoices = advance_invoices
185188
186- def to_json (self ):
189+ def to_dict (self ):
190+ """ function to convert class to dictionary """
187191
188192 out = {
189193 "advance_amount" : self .advance_amount ,
190194 "total_amount" : self .total_amount ,
191195 }
192196 advance_invoices = []
193197 for advance_invoice in self .advance_invoices :
194- advance_invoices .append (advance_invoice .to_json ())
198+ advance_invoices .append (advance_invoice .to_dict ())
195199 out ["advance_invoices" ] = advance_invoices
196200
197201 return out
@@ -208,7 +212,7 @@ def __init__(self,
208212 doc_type : str ,
209213 inv_type : str ,
210214 payment_method : int ,
211- lineitems : LineItems ,
215+ lineitems : LineItem ,
212216 party_details : PartyDetails ,
213217 advance_details : AdvanceDetails = None ,
214218 has_advance : bool = None ,
@@ -228,7 +232,8 @@ def __init__(self,
228232 self .total_tax = total_tax
229233 self .lineitems = lineitems
230234
231- def to_json (self ):
235+ def to_dict (self ):
236+ """ function to convert class to dictionary """
232237
233238 out = {
234239 "egs_uuid" : self .egs_uuid ,
@@ -242,12 +247,12 @@ def to_json(self):
242247 "currency" : self .currency ,
243248 "total_tax" : self .total_tax ,
244249 }
245- out ["party_details" ] = self .party_details .to_json ()
250+ out ["party_details" ] = self .party_details .to_dict ()
246251 lineitems = []
247252 for lineitem in self .lineitems :
248253 lineitems .append (lineitem .__dict__ )
249254 out ["lineitems" ] = lineitems
250- out ["advance_details" ] = self .advance_details .to_json ()
255+ out ["advance_details" ] = self .advance_details .to_dict ()
251256
252257 return out
253258
@@ -305,7 +310,7 @@ async def onboard_egs(self, egs_data: EGSData):
305310
306311 try :
307312 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 :
309314 if response .status == 200 :
310315 response_text = await response .text ()
311316 # Process the response data here
@@ -360,7 +365,7 @@ async def generate_invoice(self, invoice_data: InvoiceData):
360365 """
361366 try :
362367 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 :
364369 if response .status == 200 :
365370 response_text = await response .text ()
366371 # Process the response data here
0 commit comments