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": "RON",
"referenceCurrencyCode": "EUR",
'exchangeRate': 4.9767,
'originalNetAmount': 497.67,
'originalNetAmountCurrency': 100,
'originalVatAmount': 94.56,
'originalVatAmountCurrency': 19,
'netAmount': 497.67,
'netAmountCurrency': 100,
'vatAmount': 94.56,
'vatAmountCurrency': 19,
'grossAmount': 592.23,
'grossAmountCurrency': 119,
"paymentTypeId": 3,
'partner': {
'isLegalPerson': True,
'partnerName': 'DIGITAL KEEZ SRL',
'identificationNumber': '37888790'
},
"invoiceDetails": [
{
"itemExternalId": itemEid,
"measureUnitId": 1,
"quantity": 2,
'unitPrice': 248.835,
'unitPriceCurrency': 100,
'originalNetAmount': 497.67,
'originalNetAmountCurrency': 100,
'originalVatAmount': 19,
'originalVatAmountCurrency': 94.56,
'netAmount': 497.67,
'netAmountCurrency': 100,
'vatAmount': 94.56,
'vatAmountCurrency': 19,
'grossAmount': 592.23,
'grossAmountCurrency': 119,
}
]
}
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!')