Exemplu RON - RON cu discount valoric net pe factura

Atenționare

La nivelul header-ului facturii, NU la nivelul detaliilor:

 {
    "discountType": "Value",
    "discountPercent": None,
    "discountValueOnNet": False,
    "discountNetValue": 84.03,
    "discountVatValue": 15.97,
    "discountGrossValue": 100,
}
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": 200,
            "originalVatAmount": 38,
            "netAmount": 115.97,
            "vatAmount": 22.03,
            "grossAmount": 138,
            "discountType": "Value",
            "discountPercent": None,
            "discountValueOnNet": False,
            "discountNetValue": 84.03,
            "discountVatValue": 15.97,
            "discountGrossValue": 100,
            'partner': {
                'isLegalPerson': True,
                'partnerName': 'DIGITAL KEEZ SRL',
                'identificationNumber': '37888790',
                'countryCode': 'RO'
            },
            "invoiceDetails": [
                {
                    "itemExternalId": itemEid,
                    "measureUnitId": 1,
                    "unitPrice": 200,
                    "quantity": 1,
                    "originalNetAmount": 200,
                    "originalVatAmount": 38,
                    "netAmount": 115.97,
                    "vatPercent": 19,
                    "vatAmount": 22.03,
                    "grossAmount": 138,
                    "discountType": "Value",
                    "discountPercent": None,
                    "discountValueOnNet": False,
                    "discountNetValue": 84.03,
                    "discountVatValue": 15.97,
                    "discountGrossValue": 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!')