Skip to main content

An unofficial package help developers to implement ZATCA (Fatoora) QR code easily which required for e-invoicing

Project description

ZATCA (Fatoora) QR-Code Implementation

An unofficial package help developers to implement ZATCA (Fatoora) QR code easily which required for e-invoicing

PyPI - Python Version PyPI License
test-fatoora Upload Python Package
Code style: black
Table of Contents
  1. Requirements
  2. Installation
  3. Usage
  4. Discussions
  5. Issues
  6. Security
  7. Donating
  8. Project use this package
  9. License

Requirements

Installation

PyPi

$ pip3 install fatoora

GitHub

$ git clone https://github.com/TheAwiteb/fatoora/
$ cd fatoora
$ python3 setup.py install

Usage

Variables

Here the features of the variables of the Fatoora class will be explained

  • Seller’s name.
  • Seller’ tax number, which is the VAT registration number.
  • Invoice date, which is the timestamp of the electronic invoice.
  • Invoice total amount, which is the electronic invoice total with VAT.
  • Tax amount, which is the VAT total.
Name Feature How will it be in the tag How will it be when you call
seller_name saved directly without processing No changes will be made to it No changes will be made to it
tax_number receives the tax number as a text and a number as well, and save it as string number as string number as string
invoice_date receives the date as timestamp or datetime object, or string ISO 8601 Zulu format string of date as ISO 8601 Zulu format datetime object
total_amount receives the tax number as a text and a number as well It is of type str as float It is of type float
tax_amount same total_amount + Accept None value to get VAT auto from total_amount same total_amount same total_amount

Note: The tax_amount is rounded to the nearest two decimal places, if it is greater than that ( if tax_amount == 15 its will be 15.0)

Note: If you set tax_amount to None the vat_rates == 0.15 you can change it in Fatoora object


Generate Base64

from fatoora import Fatoora

fatoora_obj = Fatoora(
    seller_name="Awiteb",
    tax_number=1234567891, # or "1234567891"
    invoice_date=1635872693.3186214, # timestamp or datetime object, or string ISO 8601 Zulu format
    total_amount=100, # or 100.0, 100.00, "100.0", "100.00"
    tax_amount=15, # or 15.0, 15.00, "15.0", "15.00"
)

print(fatoora_obj.base64)
# AQZBd2l0ZWICCjEyMzQ1Njc4OTEDFDIwMjEtMTEtMDJUMTc6MDQ6NTNaBAUxMDAuMAUEMTUuMA==

Render A QR Code Image

You can render the tags as QR code image easily

The content is the base64 of the invoice

from fatoora import Fatoora

fatoora_obj = Fatoora(
    seller_name="Awiteb",
    tax_number=1234567891,
    invoice_date=1635872693.3186214,
    total_amount=100,
    tax_amount=15,
)

fatoora_obj.qrcode("qr_code.png")
qr_code.png

The content is the invoice url

from fatoora import Fatoora

fatoora_obj = Fatoora(
    seller_name="Awiteb",
    tax_number=1234567891,
    invoice_date=1635872693.3186214,
    total_amount=100,
    tax_amount=15,
    qrcode_url="https://example.com"
)

fatoora_obj.qrcode("qr_code_with_url.png")
qr_code_with_url.png

Generate hash (sha256)

from fatoora import Fatoora

fatoora_obj = Fatoora(
    seller_name="Awiteb",
    tax_number=1234567891, 
    invoice_date=1635872693.3186214,
    total_amount=100, 
    tax_amount=15, 
)

print(fatoora_obj.hash)
# 20b8ddb6ed9cb98be3d8535a1f4f28e35888842c1b0aed0e90c3e7fb51080dd9

Read qr code

from fatoora import Fatoora

fatoora_obj = Fatoora(
    seller_name="Awiteb",
    tax_number=1234567891, 
    invoice_date=1635872693.3186214,
    total_amount=100, 
    tax_amount=15, 
)

fatoora_obj.qrcode("qr_code.png")

print(Fatoora.read_qrcode("qr_code.png", dct=True))
# {'seller_name': 'Awiteb', 'tax_number': '1234567891', 'invoice_date': '2021-11-02T17:04:53Z', 'total_amount': '100.0', 'tax_amount': '15.0'}

print(Fatoora.read_qrcode("qr_code.png", dct=False))
# AQZBd2l0ZWICCjEyMzQ1Njc4OTEDFDIwMjEtMTEtMDJUMTc6MDQ6NTNaBAUxMDAuMAUEMTUuMA==

Extra Methods

from fatoora import Fatoora
fatoora_obj = Fatoora(
    seller_name="Awiteb",
    tax_number=1234567891, 
    invoice_date=1635872693.3186214,
    total_amount=100, 
    tax_amount=15, 
)

print(fatoora_obj.invoice_date.year)
# 2021

print(fatoora_obj.invoice_date.isoformat())
# 2021-11-02T17:04:53

print(fatoora_obj.invoice_date.timestamp())
# 1635861893.0

print(fatoora_obj.json())
# '{"seller_name": "Awiteb", "tax_number": "1234567891", "invoice_date": "2021-11-02T17:04:53Z", "total_amount": "100.0", "tax_amount": "15.0"}'

print(fatoora_obj.dict())
# {'seller_name': 'Awiteb', 'tax_number': '1234567891', 'invoice_date': '2021-11-02T17:04:53Z', 'total_amount': '100.0', 'tax_amount': '15.0'}

# Use class to get fatoora details by base64

print(Fatoora.base2dict(fatoora_obj.base64))
# {'seller_name': 'Awiteb', 'tax_number': '1234567891', 'invoice_date': '2021-11-02T17:04:53Z', 'total_amount': '100.0', 'tax_amount': '15.0'}

Extra Functions

import fatoora

print(fatoora.is_valid_iso8601_zulu_format("invalid date"))
# False

print(fatoora.is_valid_iso8601_zulu_format("2021-11-02T17:04:53Z"))
# True

Discussions

Question, feature request, discuss about fatoora here

Issues

You can report a bug from here

Security

If you discover any security related issues.

Donating

Note: This address for BEP20 tokens

Currency Address
Binance BNB 0x4ab0974c7dfcdcdf24d8323a93b061d41e9cf3f0
Binance USD BUSD 0x4ab0974c7dfcdcdf24d8323a93b061d41e9cf3f0
Tether USDT 0x4ab0974c7dfcdcdf24d8323a93b061d41e9cf3f0
Bitcoin BTC 0x4ab0974c7dfcdcdf24d8323a93b061d41e9cf3f0
Bitcoin Cash BCH 0x4ab0974c7dfcdcdf24d8323a93b061d41e9cf3f0

Project use this package

RAQ ERP - raqss.co

If you are interested in adding your project to the list, you can make a PR and add it

License

The MIT License (MIT). Please see License File for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fatoora-2.1.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fatoora-2.1.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file fatoora-2.1.1.tar.gz.

File metadata

  • Download URL: fatoora-2.1.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for fatoora-2.1.1.tar.gz
Algorithm Hash digest
SHA256 fbc23273122cb1d700518a3b797c268fc3496e0cbfe9ea6336c43b9c32364327
MD5 e45d61db3b13480b09aa60aa96529927
BLAKE2b-256 80c6f7d025359cbf3d3b92c262b9c1193644fd0645b1585b35d242ba534f0be9

See more details on using hashes here.

File details

Details for the file fatoora-2.1.1-py3-none-any.whl.

File metadata

  • Download URL: fatoora-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for fatoora-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 729dc03a8afd0c52b70d0a18dc6ef3ffd9457205ad590c097769542b760b0d75
MD5 ef67121eb1321aa3afc1ebc938328bb0
BLAKE2b-256 6cc5355d9a92ecff4f961dff11148d56586c81d240b09667be07771dcbf612fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page