Skip to content

Commit

Permalink
Finalize first version of VAT Validation rewritten as Open Source
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Seichter committed Jul 6, 2024
1 parent 671ecad commit 5438068
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 728 deletions.
674 changes: 0 additions & 674 deletions LICENCE

This file was deleted.

36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,38 @@ Export your master data into a file (JSON, XLSX or CSV) format and check them co

![batch validation](images/batch.png "VAT Validation Batch Processing")

The imported files needs to include the following fields/columns:

* key1
* key2
* ownvat
* foreignvat
* company
* street
* zip
* town

The output file (logfile) contains the following information:

* key1
* key2
* ownvat
* foreignvat
* type
* valid
* errorcode
* errorcode_description
* valid_from
* valid_to
* timestamp
* company
* address
* town
* zip
* street

Depending on your imported data and used interface, some keys won't have values.

## Configuration

The configuration is done really simple. Change to the configuration tab and enter your own vat. This will be used for the single validation as default VAT.
Expand All @@ -34,6 +66,10 @@ Next to this, you can choose your default interface. If you own a german VAT, it

In case you are using CSV, you can choose the delimiter for your import and export files.

# Known issues

At the moment there are several known issues. You will find them in the issues. If you encounter any further issue, please add an issue.

# Contributing

If you want to contribute by fixing an issue, add a new function or just optimize something, a simple instruction how to start development.
Expand Down
99 changes: 53 additions & 46 deletions src/batch.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,63 @@
# Import the VATValidation library
import single
import helper
import settings

# import common libraries
import pandas as pd
import json

columns = ['key1', 'key2', 'ownvat', 'foreignvat', 'company', 'street', 'zip', 'town']
columns = ["key1", "key2", "ownvat", "foreignvat", "company", "street", "zip", "town"]


def validatebatch(inputfile, outputfile='', type='vies', lang='en'):
def validatebatch(inputfile, outputfile="", type="vies", lang="en"):
"""
Validate the batch file and write the results to the output file.
"""
# get the file extension
ext = inputfile.split('.')[-1].lower()
ext = inputfile.split(".")[-1].lower()

# if the output file is not set, use the input file with a different extension
if not outputfile:
outputfile = inputfile.replace(ext, f"log.{ext}")

match ext:
case 'csv':
case "csv":
processcsv(inputfile, outputfile, type, lang)
case 'xlsx':
case "xlsx":
processxlsx(inputfile, outputfile, type, lang)
case 'json':
case "json":
processjson(inputfile, outputfile, type, lang)
case _:
print('Unsupported file format')
print("Unsupported file format")


def processcsv(inputfile, outputfile, type, lang):

# read csv with columns
data = pd.read_csv(inputfile, names=columns, delimiter=helper.load_value_from_json_file('delimiter'))
data = pd.read_csv(
inputfile,
names=columns,
delimiter=settings.load_value_from_json_file("delimiter"),
)
# create a list to store the results
results = []
# iterate over the rows
for index, row in data.iterrows():
# skip first line, because it contains the column names
if index == 0:
continue
# validate the row
_, message = single.validatesingle(key1=row['key1'],
key2=row['key2'],
ownvat=row['ownvat'],
foreignvat=row['foreignvat'],
company=row['company'],
street=row['street'],
zip=row['zip'],
town=row['town'],
type=type,
lang=lang)
message = single.validatesingle(
key1=row["key1"],
key2=row["key2"],
ownvat=row["ownvat"],
foreignvat=row["foreignvat"],
company=row["company"],
street=row["street"],
zip=row["zip"],
town=row["town"],
type=type,
lang=lang,
)
# append the result to the results list
message = json.loads(message)
results.append(message)

# load the results into a DataFrame
Expand All @@ -71,18 +77,19 @@ def processxlsx(inputfile, outputfile, type, lang):
# iterate over the rows
for index, row in data.iterrows():
# validate the row
_, message = single.validatesingle(key1=row['key1'],
key2=row['key2'],
ownvat=row['ownvat'],
foreignvat=row['foreignvat'],
company=row['company'],
street=row['street'],
zip=row['zip'],
town=row['town'],
type=type,
lang=lang)
_, message = single.validatesingle(
key1=row["key1"],
key2=row["key2"],
ownvat=row["ownvat"],
foreignvat=row["foreignvat"],
company=row["company"],
street=row["street"],
zip=row["zip"],
town=row["town"],
type=type,
lang=lang,
)
# append the result to the results list
message = json.loads(message)
results.append(message)

# load the results into a DataFrame
Expand All @@ -93,29 +100,29 @@ def processxlsx(inputfile, outputfile, type, lang):


def processjson(inputfile, outputfile, type, lang):

data = pd.read_json(inputfile)
# create a list to store the results
results = []
# iterate over the rows
for index, row in data.iterrows():
# validate the row
_, message = single.validatesingle(key1=row['key1'],
key2=row['key2'],
ownvat=row['ownvat'],
foreignvat=row['foreignvat'],
company=row['company'],
street=row['street'],
zip=row['zip'],
town=row['town'],
type=type,
lang=lang)
_, message = single.validatesingle(
key1=row["key1"],
key2=row["key2"],
ownvat=row["ownvat"],
foreignvat=row["foreignvat"],
company=row["company"],
street=row["street"],
zip=row["zip"],
town=row["town"],
type=type,
lang=lang,
)
# append the result to the results list
message = json.loads(message)
results.append(message)

# load the results into a DataFrame
dataframe = pd.DataFrame(results)

# save the dateframe to a json file
dataframe.to_json(outputfile, orient='records', lines=False, indent=2)
dataframe.to_json(outputfile, orient="records", lines=False, indent=2)
5 changes: 0 additions & 5 deletions src/validate_vies.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def start_validation(payload):

logger.debug(resp.data)
node = dom.documentElement
print(resp.data)
result = {}
try:
result["traderName"] = (
Expand Down Expand Up @@ -156,9 +155,6 @@ def start_validation(payload):

logger.debug(result)
# bring result in right format
print("before validationresult")
print("result", result)
print("payload", payload)
validationresult = {
"key1": payload["key1"],
"key2": payload["key2"],
Expand All @@ -177,7 +173,6 @@ def start_validation(payload):
"zip": "",
"street": "",
}
print(validationresult)
return validationresult
except Exception as e:
logger.error(repr(e))
Expand Down
2 changes: 0 additions & 2 deletions src/validate_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,4 @@ def start_validation(payload):
else:
response = validate_vies.start_validation(payload)

print(response)

return response
7 changes: 6 additions & 1 deletion src/vatvalidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def validateBatch(self, event):
wx.MessageBox(
"Are you sure you want to start the batch validation?",
"Batch Validation",
wx.YES_NO | wx.ICON_HAND,
wx.YES_NO | wx.ICON_QUESTION,
)
== wx.NO
):
Expand All @@ -166,6 +166,11 @@ def validateBatch(self, event):
lang=settings.load_value_from_json_file("language"),
)

# if done, show a message box
wx.MessageBox(
"Batch validation done.", "Batch Validation", wx.OK | wx.ICON_INFORMATION
)

def checkForUpdates(self, event):
if helper.check_for_new_release():
result = wx.MessageBox(
Expand Down

0 comments on commit 5438068

Please sign in to comment.