Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sivadasrajan committed Oct 17, 2023
1 parent ce5e788 commit df7112e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 31 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ result = loop.run_until_complete(api.generate_invoice(invoiceData))

1. Here's an Example of how you can **onboard multiple EGS to ZATCA Portal** [If you are onboarding PoS devices or VAT-Group members, this comes handy].

2. Examples are included in the examples folder as well

```python
import asyncio
from flick.api_service import Config
from flick.bills import Bills,EGSData,Devices
from flick.bills import Bills,EGSData,Device

config = Config('sandbox', 'your-api-key')

Expand All @@ -81,7 +83,7 @@ egs_data = EGSData(
vat_name='Test Co.',
vat_number='300000000000003',
devices=[
Devices(
Device(
device_name='TestEGS1',
city='Riyadh',
city_subdiv='Test Dist.',
Expand All @@ -93,7 +95,7 @@ egs_data = EGSData(
branch_name='Riyad Branc h 1',
branch_industry='Retail',
otp='123321',
), Devices(
), Device(
device_name='TestEGS2',
city='Riyadh',
city_subdiv='Test Dist.',
Expand Down Expand Up @@ -122,7 +124,7 @@ print(result)
```python
import asyncio
from flick.api_service import Config
from flick.bills import Bills, InvoiceData, PartyAddId, PartyDetails, AdvanceDetails, AdvanceInvoices, Invoice, LineItems
from flick.bills import Bills, InvoiceData, PartyAddId, PartyDetails, AdvanceDetails, AdvanceInvoice, Invoice, LineItem

config = Config('sandbox', 'your-api-key')

Expand Down Expand Up @@ -155,7 +157,7 @@ invoice_data = InvoiceData(
advance_amount=575,
total_amount=2875,
advance_invoices=[
AdvanceInvoices(
AdvanceInvoice(
tax_category='S',
tax_percentage=0.15,
taxable_amount=500,
Expand All @@ -171,14 +173,14 @@ invoice_data = InvoiceData(
],
),
lineitems=[
LineItems(
LineItem(
name_ar='متحرك',
quantity=1,
tax_category='S',
tax_exclusive_price=750,
tax_percentage=0.15,
),
LineItems(
LineItem(
name_ar='حاسوب محمول',
quantity=1,
tax_category='S',
Expand Down
8 changes: 4 additions & 4 deletions examples/generate_invoice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
from flick.api_service import Config
from flick.bills import Bills, InvoiceData, PartyAddId, PartyDetails, AdvanceDetails, AdvanceInvoices, Invoice, LineItems
from flick.bills import Bills, InvoiceData, PartyAddId, PartyDetails, AdvanceDetails, AdvanceInvoice, Invoice, LineItem

config = Config('sandbox', 'your-api-key')

Expand Down Expand Up @@ -33,7 +33,7 @@
advance_amount=575,
total_amount=2875,
advance_invoices=[
AdvanceInvoices(
AdvanceInvoice(
tax_category='S',
tax_percentage=0.15,
taxable_amount=500,
Expand All @@ -49,14 +49,14 @@
],
),
lineitems=[
LineItems(
LineItem(
name_ar='متحرك',
quantity=1,
tax_category='S',
tax_exclusive_price=750,
tax_percentage=0.15,
),
LineItems(
LineItem(
name_ar='حاسوب محمول',
quantity=1,
tax_category='S',
Expand Down
6 changes: 3 additions & 3 deletions examples/onboard_egs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
from flick.api_service import Config
from flick.bills import Bills,EGSData,Devices
from flick.bills import Bills,EGSData,Device

config = Config('sandbox', 'your-api-key')

Expand All @@ -10,7 +10,7 @@
vat_name='Test Co.',
vat_number='300000000000003',
devices=[
Devices(
Device(
device_name='TestEGS1',
city='Riyadh',
city_subdiv='Test Dist.',
Expand All @@ -22,7 +22,7 @@
branch_name='Riyad Branc h 1',
branch_industry='Retail',
otp='123321',
), Devices(
), Device(
device_name='TestEGS2',
city='Riyadh',
city_subdiv='Test Dist.',
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

setup(
name = "flick-python-sdk",
version = "0.0.14",
version = "1.0.0",
author = "Sivadas Rajan",
author_email = "[email protected]",
description = "A Python wrapper for interacting with APIs from Flick.",
long_description = long_description,
long_description_content_type = "text/markdown",
install_requires=["aiohttp>=3.5.0"],
url = "https://pypi.org/project/flick-python-sdk/",
maintainer="Sivadas Rajan",
maintainer_email="[email protected]",
project_urls = {
"Bug Tracker": "https://github.com/flick-network/flick-python-sdk/issues",
},
Expand Down
37 changes: 21 additions & 16 deletions src/flick/bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .api_service import FlickAPI, Config


class Devices():
class Device():
""" The Devices class. """

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):
Expand All @@ -23,7 +23,7 @@ def __init__(self, device_name: str, city: str, city_subdiv: str, street: str, p
class EGSData:
""" The EGSData class. """

def __init__(self, vat_name: str, vat_number: str, devices: List[Devices]):
def __init__(self, vat_name: str, vat_number: str, devices: List[Device]):
"""
Initializes an instance of EGSData.
Expand All @@ -36,7 +36,8 @@ def __init__(self, vat_name: str, vat_number: str, devices: List[Devices]):
self.vat_number = vat_number
self.devices = devices

def to_json(self):
def to_dict(self):
""" function to convert class to dictionary """

out = {
"vat_name": self.vat_name,
Expand Down Expand Up @@ -89,7 +90,8 @@ def __init__(self,
self.building = building
self.postal_zone = postal_zone

def to_json(self):
def to_dict(self):
""" function to convert class to dictionary """

out = {
"party_name_ar": self.party_name_ar,
Expand Down Expand Up @@ -121,7 +123,7 @@ def __init__(self, invoice_id: str, issue_date: str, issue_time: str):
self.issue_time = issue_time


class LineItems:
class LineItem:
""" The LineItems class. """

def __init__(self,
Expand All @@ -140,7 +142,7 @@ def __init__(self,
self.tax_percentage = tax_percentage


class AdvanceInvoices:
class AdvanceInvoice:
""" The AdvanceInvoices class. """

def __init__(self,
Expand All @@ -155,7 +157,8 @@ def __init__(self,
self.tax_amount = tax_amount
self.invoices = invoices

def to_json(self):
def to_dict(self):
""" function to convert class to dictionary """

out = {
"tax_category": self.tax_category,
Expand All @@ -177,21 +180,22 @@ class AdvanceDetails:
def __init__(self,
advance_amount: float,
total_amount: float,
advance_invoices: AdvanceInvoices
advance_invoices: AdvanceInvoice
):
self.advance_amount = advance_amount
self.total_amount = total_amount
self.advance_invoices = advance_invoices

def to_json(self):
def to_dict(self):
""" function to convert class to dictionary """

out = {
"advance_amount": self.advance_amount,
"total_amount": self.total_amount,
}
advance_invoices = []
for advance_invoice in self.advance_invoices:
advance_invoices.append(advance_invoice.to_json())
advance_invoices.append(advance_invoice.to_dict())
out["advance_invoices"] = advance_invoices

return out
Expand All @@ -208,7 +212,7 @@ def __init__(self,
doc_type: str,
inv_type: str,
payment_method: int,
lineitems: LineItems,
lineitems: LineItem,
party_details: PartyDetails,
advance_details: AdvanceDetails = None,
has_advance: bool = None,
Expand All @@ -228,7 +232,8 @@ def __init__(self,
self.total_tax = total_tax
self.lineitems = lineitems

def to_json(self):
def to_dict(self):
""" function to convert class to dictionary """

out = {
"egs_uuid": self.egs_uuid,
Expand All @@ -242,12 +247,12 @@ def to_json(self):
"currency": self.currency,
"total_tax": self.total_tax,
}
out["party_details"] = self.party_details.to_json()
out["party_details"] = self.party_details.to_dict()
lineitems = []
for lineitem in self.lineitems:
lineitems.append(lineitem.__dict__)
out["lineitems"] = lineitems
out["advance_details"] = self.advance_details.to_json()
out["advance_details"] = self.advance_details.to_dict()

return out

Expand Down Expand Up @@ -305,7 +310,7 @@ async def onboard_egs(self, egs_data: EGSData):

try:
async with FlickAPI(config=self.config) as session:
async with session.request('POST', '/egs/onboard', data=json.dumps(egs_data.to_json())) as response:
async with session.request('POST', '/egs/onboard', data=json.dumps(egs_data.to_dict())) as response:
if response.status == 200:
response_text = await response.text()
# Process the response data here
Expand Down Expand Up @@ -360,7 +365,7 @@ async def generate_invoice(self, invoice_data: InvoiceData):
"""
try:
async with FlickAPI(config=self.config) as session:
async with session.request('POST', '/invoice/generate', data=json.dumps(invoice_data.to_json())) as response:
async with session.request('POST', '/invoice/generate', data=json.dumps(invoice_data.to_dict())) as response:
if response.status == 200:
response_text = await response.text()
# Process the response data here
Expand Down

0 comments on commit df7112e

Please sign in to comment.