from working_examples.keez_public_api import KeezPublicApi
class Service:
def __init__(self):
token_url = 'https://staging.keez.ro/idp/connect/token'
api_url = f'https://staging.keez.ro/api/v1.0/public-api'
application_id = {APPLICATION_ID}
secret = {SECRET}
self.client_eid = {CLIENT_EID}
self.wrapper_service = KeezPublicApi(application_id=application_id, secret=secret, token_url=token_url, api_url=api_url)
def getItems(self):
return self.wrapper_service.items(self.client_eid)
def validateInvoice(self, invoiceEid):
self.wrapper_service.validate_invoice(self.client_eid, invoiceEid)
def createItem(self):
code = 'SERV_DIV' # Se completeaza codul articolului pe baza caruia articolul poate fi gasit ulterior
data = {
'code': 'SERV_DIV',
'name': 'Servicii diverse', # Se completeaza numele articolului, acesta trebuie sa fie unic, iar daca mai exista in aplicatie, se va cauta pe baza codului
'currencyCode': 'RON',
'measureUnitId': 1,
'isActive': True,
'categoryExternalId': 'MISCSRV'
}
# Se cauta articolul deja existent pe baza codului, daca acesta exista se va folosi, daca nu se va crea
items = self.getItems()
itemExternalId = next((p for p in items if p['code'] == code), None)
if itemExternalId:
return itemExternalId
return self.wrapper_service.create_item(self.client_eid, data)
def createInvoice(self, itemEid):
data = {
"series": "SERIE",
"documentDate": 20240216,
"dueDate": 20240216,
"vatOnCollection": False,
"currencyCode": "EUR",
"referenceCurrencyCode": "EUR",
"exchangeRate": 1,
"originalNetAmount": 100,
"originalVatAmount": 0,
"netAmount": 100,
"vatAmount": 0,
"grossAmount": 100,
"paymentTypeId": 3,
'partner': {
'isLegalPerson': True,
'partnerName': 'TeamViewer Germany GmbH',
'identificationNumber': 'DE245838579'
},
"invoiceDetails": [
{
"itemExternalId": itemEid,
"measureUnitId": 1,
"quantity": 2,
"unitPrice": 50,
"originalNetAmount": 100,
"originalVatAmount": 0,
"netAmount": 100,
"vatAmount": 0,
"grossAmount": 100
}
]
}
return self.wrapper_service.create_invoice(self.client_eid, data)
if __name__ == '__main__':
service = Service()
itemEid = service.createItem().get('externalId')
print('Create item all good!')
invoiceEid = service.createInvoice(itemEid).get('externalId')
print('Create invoice all good!')
service.validateInvoice(invoiceEid)
print('Validate invoice all good!')
print('Done!')