Exemplu RON - RON cu discount procentual pe detaliu¶
Atenționare
La nivelul fiecarui detaliu:
{
"discountType": "Percent",
"discountPercent": 25,
"discountValueOnNet": True
}
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": 20241212,
"dueDate": 20241212,
"vatOnCollection": False,
"currencyCode": "RON",
"paymentTypeId": 3,
"originalNetAmount": 115,
"originalVatAmount": 21.85,
"netAmount": 86.25,
"vatAmount": 16.39,
"grossAmount": 102.64,
"discountType": None,
"discountPercent": None,
"discountValueOnNet": True,
"discountNetValue": 28.75,
"discountVatValue": 5.46,
"discountGrossValue": 34.21,
'partner': {
'isLegalPerson': True,
'partnerName': 'DIGITAL KEEZ SRL',
'identificationNumber': '37888790',
'countryCode': 'RO'
},
"invoiceDetails": [
{
"itemExternalId": itemEid,
"measureUnitId": 1,
"unitPrice": 115,
"quantity": 1,
"originalNetAmount": 115,
"originalVatAmount": 21.85,
"netAmount": 86.25,
"vatPercent": 19,
"vatAmount": 16.39,
"grossAmount": 102.64,
"discountType": "Percent",
"discountPercent": 25,
"discountValueOnNet": True,
"discountNetValue": 28.75,
"discountVatValue": 5.46,
"discountGrossValue": 34.21,
}
]
}
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!')