Skip to content

Commit

Permalink
add invoices (#6)
Browse files Browse the repository at this point in the history
* add invoices
  • Loading branch information
dmitry-sinina authored Dec 29, 2023
1 parent 7267018 commit 598fa63
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 11 deletions.
32 changes: 21 additions & 11 deletions examples/simple_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from yeti_switch_api.orm import OrmClient
from yeti_switch_api.orm import Contractor
from yeti_switch_api.orm.billing import Invoice
from yeti_switch_api.orm.system import SmtpConnection

# For demonstration purpose only: below lines logs all HTTP requests to stdout
Expand All @@ -19,10 +20,10 @@
# here library usage starts
OrmClient(
{
"API_ROOT": "http://127.0.0.1:4321/api/rest/admin",
"API_ROOT": "https://demo.yeti-switch.org/api/rest/admin",
"AUTH_CREDS": {
"login": "admin",
"password": "qweasd",
"password": "111111",
},
"VALIDATE_SSL": True,
"TIMEOUT": 1,
Expand Down Expand Up @@ -50,15 +51,15 @@
"name": "test_python",
"enabled": True,
"customer": True,
},
relationships={
"smtp-connection": {
"data": {
"type": SmtpConnection.Meta.type,
"id": found_smtp_connections[0].id,
}
}
},
}
# relationships={
# "smtp-connection": {
# "data": {
# "type": SmtpConnection.Meta.type,
# "id": found_smtp_connections[0].id,
# }
# }
# },
)
print("new_contractor before create", new_contractor.raw_object)
new_contractor.create()
Expand All @@ -74,3 +75,12 @@
print("contractor found", contractor.raw_object)

print(contractor.creatable_fields())


# get invoices
invs = Invoice.get_list()
if len(invs) == 0:
print("No invoices found")
else:
for inv in invs:
print("Invoices found:", inv.raw_object)
5 changes: 5 additions & 0 deletions yeti_switch_api/orm/billing/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
from .contact import Contact # noqa: F401
from .invoice import Invoice # noqa: F401
from .invoice_originated_destination import InvoiceOriginatedDestination # noqa: F401
from .invoice_originated_network import InvoiceOriginatedNetwork # noqa: F401
from .invoice_terminated_destination import InvoiceTerminatedDestination # noqa: F401
from .invoice_terminated_network import InvoiceTerminatedNetwork # noqa: F401
46 changes: 46 additions & 0 deletions yeti_switch_api/orm/billing/invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from ..base_model import BaseModel, AttributeField, RelationField


class Invoice(BaseModel):
class Meta:
path = "billing/invoices"
type = "invoices"

account = RelationField("account")
originated_destinations = RelationField("originated-destinations")
originated_networks = RelationField("originated-networks")
terminated_destinations = RelationField("terminated-destinations")
terminated_networks = RelationField("terminated-networks")

reference = AttributeField("reference")
state = AttributeField("state")
invoice_type = AttributeField("invoice-type")
start_date = AttributeField("start-date")
end_date = AttributeField("end-date")
amount_spent = AttributeField("amount-spent")
amount_earned = AttributeField("amount-earned")

originated_amount_spent = AttributeField("originated-amount-spent")
originated_amount_earned = AttributeField("originated-amount-earned")
originated_calls_count = AttributeField("originated-calls-count")
originated_successful_calls_count = AttributeField(
"originated-successful-calls-count"
)
originated_calls_duration = AttributeField("originated-calls-duration")
originated_billing_duration = AttributeField("originated-billing-duration")
originated_first_call_at = AttributeField("originated-first-call-at")
originated_last_call_at = AttributeField("originated-last-call-at")

terminated_amount_spent = AttributeField("terminated-amount-spent")
terminated_amount_earned = AttributeField("terminated-amount-earned")
terminated_calls_count = AttributeField("terminated-calls-count")
terminated_successful_calls_count = AttributeField(
"terminated-successful-calls-count"
)
terminated_calls_duration = AttributeField("terminated-calls-duration")
terminated_billing_duration = AttributeField("terminated-billing-duration")
terminated_first_call_at = AttributeField("terminated-first-call-at")
terminated_last_call_at = AttributeField("terminated-last-call-at")

def creatable_fields(self):
return ["account", "start_date", "end_date"]
22 changes: 22 additions & 0 deletions yeti_switch_api/orm/billing/invoice_originated_destination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from ..base_model import BaseModel, AttributeField, RelationField


class InvoiceOriginatedDestination(BaseModel):
class Meta:
path = "billing/invoice-originated-destinations"
type = "invoice-originated-destinations"

invoice = RelationField("invoice")
country = RelationField("country")
network = RelationField("network")

amount = AttributeField("amount")
billing_duration = AttributeField("billing-duration")
calls_count = AttributeField("calls-count")
successful_calls_count = AttributeField("successful-calls-count")
calls_duration = AttributeField("calls-duration")
dst_prefix = AttributeField("dst-prefix")
first_call_at = AttributeField("first-call-at")
last_call_at = AttributeField("last-call-at")
rate = AttributeField("rate")
spent = AttributeField("spent")
21 changes: 21 additions & 0 deletions yeti_switch_api/orm/billing/invoice_originated_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from ..base_model import BaseModel, AttributeField, RelationField


class InvoiceOriginatedNetwork(BaseModel):
class Meta:
path = "billing/invoice-originated-networks"
type = "invoice-originated-networks"

invoice = RelationField("invoice")
country = RelationField("country")
network = RelationField("network")

amount = AttributeField("amount")
billing_duration = AttributeField("billing-duration")
calls_count = AttributeField("calls-count")
successful_calls_count = AttributeField("successful-calls-count")
calls_duration = AttributeField("calls-duration")
first_call_at = AttributeField("first-call-at")
last_call_at = AttributeField("last-call-at")
rate = AttributeField("rate")
spent = AttributeField("spent")
22 changes: 22 additions & 0 deletions yeti_switch_api/orm/billing/invoice_terminated_destination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from ..base_model import BaseModel, AttributeField, RelationField


class InvoiceTerminatedDestination(BaseModel):
class Meta:
path = "billing/invoice-terminated-destinations"
type = "invoice-terminated-destinations"

invoice = RelationField("invoice")
country = RelationField("country")
network = RelationField("network")

amount = AttributeField("amount")
billing_duration = AttributeField("billing-duration")
calls_count = AttributeField("calls-count")
successful_calls_count = AttributeField("successful-calls-count")
calls_duration = AttributeField("calls-duration")
dst_prefix = AttributeField("dst-prefix")
first_call_at = AttributeField("first-call-at")
last_call_at = AttributeField("last-call-at")
rate = AttributeField("rate")
spent = AttributeField("spent")
21 changes: 21 additions & 0 deletions yeti_switch_api/orm/billing/invoice_terminated_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from ..base_model import BaseModel, AttributeField, RelationField


class InvoiceTerminatedNetwork(BaseModel):
class Meta:
path = "billing/invoice-terminated-networks"
type = "invoice-terminated-networks"

invoice = RelationField("invoice")
country = RelationField("country")
network = RelationField("network")

amount = AttributeField("amount")
billing_duration = AttributeField("billing-duration")
calls_count = AttributeField("calls-count")
successful_calls_count = AttributeField("successful-calls-count")
calls_duration = AttributeField("calls-duration")
first_call_at = AttributeField("first-call-at")
last_call_at = AttributeField("last-call-at")
rate = AttributeField("rate")
spent = AttributeField("spent")
16 changes: 16 additions & 0 deletions yeti_switch_api/orm/orm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
from ..common import build_client_config
from .routing import Rateplan, RoutingTag
from .billing import Contact
from .billing import Invoice
from .billing import InvoiceOriginatedDestination
from .billing import InvoiceOriginatedNetwork
from .billing import InvoiceTerminatedDestination
from .billing import InvoiceTerminatedNetwork
from .contractor import Contractor
from .system import SmtpConnection
from .system import Country
from .system import Network
from .system import NetworkType


class OrmClient:
Expand All @@ -23,6 +31,14 @@ def __new__(cls, config, **kwargs):
def __register_models(cls):
cls.__register_model(Contractor)
cls.__register_model(Contact)
cls.__register_model(Invoice)
cls.__register_model(InvoiceOriginatedDestination)
cls.__register_model(InvoiceOriginatedNetwork)
cls.__register_model(InvoiceTerminatedDestination)
cls.__register_model(InvoiceTerminatedNetwork)
cls.__register_model(Country)
cls.__register_model(Network)
cls.__register_model(NetworkType)
cls.__register_model(Rateplan)
cls.__register_model(RoutingTag)
cls.__register_model(SmtpConnection)
Expand Down
3 changes: 3 additions & 0 deletions yeti_switch_api/orm/system/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from .smtp_connection import SmtpConnection # noqa: F401
from .country import Country # noqa: F401
from .network import Network # noqa: F401
from .network_type import NetworkType # noqa: F401
10 changes: 10 additions & 0 deletions yeti_switch_api/orm/system/country.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ..base_model import BaseModel, AttributeField, RelationField # noqa: F401


class Country(BaseModel):
class Meta:
path = "system/countries"
type = "countries"

name = AttributeField("name")
host = AttributeField("iso2")
10 changes: 10 additions & 0 deletions yeti_switch_api/orm/system/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ..base_model import BaseModel, AttributeField, RelationField # noqa: F401


class Network(BaseModel):
class Meta:
path = "system/networks"
type = "networks"

name = AttributeField("name")
type = RelationField("network-type")
9 changes: 9 additions & 0 deletions yeti_switch_api/orm/system/network_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ..base_model import BaseModel, AttributeField, RelationField # noqa: F401


class NetworkType(BaseModel):
class Meta:
path = "system/network-types"
type = "network-types"

name = AttributeField("name")

0 comments on commit 598fa63

Please sign in to comment.