Skip to content

Commit

Permalink
Merge pull request #5 from dseichter/dseichter/issue4
Browse files Browse the repository at this point in the history
Dseichter/issue4
  • Loading branch information
Daniel Seichter authored Jul 8, 2024
2 parents 1f912e1 + 200c1a8 commit 9f8b4df
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 30 deletions.
79 changes: 75 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,42 @@ jobs:
run: pip install -r src/requirements.txt

- name: Build Windows binary
run: pyinstaller --onefile -w src/vatvalidation.py -n VATValidation-windows-${{ github.ref_name }}.exe
run: pyinstaller --onefile -w src/vatvalidation.py -n VATValidation-windows-${{ github.ref_name }}.exe --icon=icons/Tick_Box.ico

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: VATValidation-windows-${{ github.ref_name }}.exe
path: dist/VATValidation-windows-${{ github.ref_name }}.exe
path: dist/VATValidation-windows-${{ github.ref_name }}.exe

build-windows-binary-cli:
runs-on: windows-latest
steps:

- name: 'Checkout'
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Create and start virtual environment
run: |
python3 -m venv venv
venv\Scripts\activate.bat
- name: Install dependencies
run: pip install -r src/requirements.txt

- name: Build Windows binary
run: pyinstaller --onefile -w src/vatvalidation_cli.py -n VATValidation-cli-windows-${{ github.ref_name }}.exe

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: VATValidation-cli-windows-${{ github.ref_name }}.exe
path: dist/VATValidation-cli-windows-${{ github.ref_name }}.exe

build-linux-binary:
runs-on: ubuntu-latest
Expand All @@ -60,14 +89,46 @@ jobs:
run: pip install -r src/requirements.txt

- name: Build Linux binary
run: pyinstaller --onefile src/vatvalidation.py -n VATValidation-linux-${{ github.ref_name }}
run: pyinstaller --onefile src/vatvalidation.py -n VATValidation-linux-${{ github.ref_name }} --icon=icons/Tick_Box.ico

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: VATValidation-linux-${{ github.ref_name }}
path: dist/VATValidation-linux-${{ github.ref_name }}

build-linux-binary-cli:
runs-on: ubuntu-latest
steps:

- name: 'Checkout'
uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get install build-essential libgtk-3-dev

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Create and start virtual environment
run: |
python3 -m venv venv
source venv/bin/activate
- name: Install dependencies
run: pip install -r src/requirements.txt

- name: Build Linux binary
run: pyinstaller --onefile src/vatvalidation.py -n VATValidation-cli-linux-${{ github.ref_name }}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: VATValidation-cli-linux-${{ github.ref_name }}
path: dist/VATValidation-cli-linux-${{ github.ref_name }}

deploy:
runs-on: ubuntu-latest
needs: [build-windows-binary, build-linux-binary]
Expand All @@ -76,10 +137,18 @@ jobs:
with:
name: VATValidation-linux-${{ github.ref_name }}

- uses: actions/download-artifact@v4
with:
name: VATValidation-cli-linux-${{ github.ref_name }}

- uses: actions/download-artifact@v4
with:
name: VATValidation-windows-${{ github.ref_name }}.exe

- uses: actions/download-artifact@v4
with:
name: VATValidation-cli-windows-${{ github.ref_name }}.exe

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
Expand All @@ -91,4 +160,6 @@ jobs:
generate_release_notes: true
files: |
VATValidation-linux-${{ github.ref_name }}
VATValidation-windows-${{ github.ref_name }}.exe
VATValidation-windows-${{ github.ref_name }}.exe
VATValidation-cli-linux-${{ github.ref_name }}
VATValidation-cli-windows-${{ github.ref_name }}.exe
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@ If you like this software, please don't hesitate to give it a :star: or send me

VAT Validation supports you in checking and validating your master data. Whether you want to check a VAT number directly at your workplace or integrate it into your ERP/CRM applications.

## Command Line tool

If you want to check batch files (e.g. json, csv or XLSX) you can download the releases like VATValidation-cli-windows-v2024-07-08.exe and rename it to vatvalidation_cli.exe.

Just run the tool and by providing an input and an output file. For further information, please run

``vatvalidation_cli.exe``

```shell
usage: vatvalidation_cli.py [-h] [--version] --input INPUT --output OUTPUT

VAT-Validation CLI - v2024-07-06

options:
-h, --help show this help message and exit
--version show program's version number and exit
--input INPUT Input file path for VAT numbers.
--output OUTPUT Output file path for validation results.
For more information, visit our GitHub repository: https://github.com/dseichter/VATValidation License: MIT License - see LICENSE file at the root of the repository for details.
```
Only batch processing is provided.
## Graphical User Interface
I provide a graphical user interface for single and batch validation.
### Single Validation
You can use the software at your workplace and check directly against the official supported interfaces of BZSt, VIES and/or HMRC.
Expand Down
Binary file added icons/Tick_Box.ico
Binary file not shown.
18 changes: 14 additions & 4 deletions src/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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", iscli=False):
"""
Validate the batch file and write the results to the output file.
"""
Expand All @@ -21,13 +21,20 @@ def validatebatch(inputfile, outputfile="", type="vies", lang="en"):

match ext:
case "csv":
processcsv(inputfile, outputfile, type, lang)
resultcode = processcsv(inputfile, outputfile, type, lang)
if iscli:
return resultcode
case "xlsx":
processxlsx(inputfile, outputfile, type, lang)
resultcode = processxlsx(inputfile, outputfile, type, lang)
if iscli:
return resultcode
case "json":
processjson(inputfile, outputfile, type, lang)
resultcode = processjson(inputfile, outputfile, type, lang)
if iscli:
return resultcode
case _:
print("Unsupported file format")
return 127


def processcsv(inputfile, outputfile, type, lang):
Expand Down Expand Up @@ -56,6 +63,7 @@ def processcsv(inputfile, outputfile, type, lang):
town=row["town"],
type=type,
lang=lang,
iscli=True
)
# append the result to the results list
results.append(message)
Expand Down Expand Up @@ -88,6 +96,7 @@ def processxlsx(inputfile, outputfile, type, lang):
town=row["town"],
type=type,
lang=lang,
iscli=True,
)
# append the result to the results list
results.append(message)
Expand Down Expand Up @@ -117,6 +126,7 @@ def processjson(inputfile, outputfile, type, lang):
town=row["town"],
type=type,
lang=lang,
iscli=True,
)
# append the result to the results list
results.append(message)
Expand Down
2 changes: 1 addition & 1 deletion src/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging


VERSION = "v2024-07-06"
VERSION = "v2024-07-08"
UPDATEURL = 'https://api.github.com/repos/dseichter/VATValidation/releases/latest'
RELEASES = 'https://github.com/dseichter/VATValidation/releases'
NAME = 'VAT-Validation'
Expand Down
3 changes: 2 additions & 1 deletion src/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def validatesingle(
town="",
type="vies",
lang="en",
iscli=True
):
data = {
"key1": key1,
Expand All @@ -25,6 +26,6 @@ def validatesingle(
"type": type,
"lang": lang,
}
r = validate_workflow.start_validation(data)
r = validate_workflow.start_validation(data, iscli)

return r
4 changes: 2 additions & 2 deletions src/validate_bzst.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ def gettext(nodelist):

def load_codes(lang, errorcode):
if errorcode is None:
return None
return ""

for code in codes_bzst.returncodes:
if code["status"] == errorcode:
return code[lang]
return None


def start_validation(payload):
def start_validation(payload, iscli=True):
logger.debug(payload)

# map requested fields to bzst request
Expand Down
15 changes: 8 additions & 7 deletions src/validate_hmrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ def defaultencode(o):

def load_codes(lang, message):
if message is None:
return message

return ""
for code in codes_hmrc.returncodes:
if message.startswith(code["status"]):
return code[lang]
return message


def start_validation(payload):
def start_validation(payload, iscli=True):
try:
resp = http.request("GET", URL + payload["foreignvat"][2:])
logger.debug(resp.status, resp.data)
Expand All @@ -84,7 +83,9 @@ def start_validation(payload):
"type": "HMRC",
"valid": resp.status == 200,
"errorcode": result.get("errorcode", ""),
"errorcode_description": load_codes(payload["lang"], result["message"]),
"errorcode_description": load_codes(
payload["lang"], result.get("message", None)
),
"valid_from": "",
"valid_to": "",
"timestamp": datetime.datetime.now(datetime.timezone.utc).strftime(
Expand All @@ -94,9 +95,9 @@ def start_validation(payload):
if "target" in result:
validationresult["company"] = result["target"]["name"]
validationresult["address"] = (
result["target"]["address"]["line1"]
+ chr(13)
+ result["target"]["address"]["line2"]
result["target"]["address"]["line1"].strip() + ""
if iscli
else chr(13) + result["target"]["address"]["line2"].strip()
)
validationresult["town"] = ""
validationresult["zip"] = result["target"]["address"]["postcode"]
Expand Down
4 changes: 2 additions & 2 deletions src/validate_vies.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def defaultencode(o):

def load_codes(lang, errorcode):
if errorcode is None:
return None
return ""

for code in codes_vies.returncodes:
if code["status"] == errorcode:
return code[lang]
return None


def start_validation(payload):
def start_validation(payload, iscli=True):
logger.debug(payload)

foreign_vat = payload["foreignvat"]
Expand Down
8 changes: 4 additions & 4 deletions src/validate_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def return_fielderror(fieldname):
}


def start_validation(payload):
def start_validation(payload, iscli=True):
logger.debug(payload)

if "key1" not in payload:
Expand Down Expand Up @@ -86,10 +86,10 @@ def start_validation(payload):
if payload["ownvat"].upper().startswith("DE") and not payload[
"foreignvat"
].upper().startswith("GB"):
response = validate_bzst.start_validation(payload)
response = validate_bzst.start_validation(payload, iscli)
elif payload["foreignvat"].upper().startswith("GB"):
response = validate_hmrc.start_validation(payload)
response = validate_hmrc.start_validation(payload, iscli)
else:
response = validate_vies.start_validation(payload)
response = validate_vies.start_validation(payload, iscli)

return response
14 changes: 9 additions & 5 deletions src/vatvalidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ def vatvalidationClose(self, event):
self.Close()

def vatvalidationGitHub(self, event):
webbrowser.open_new_tab(
"https://github.com/dseichter/VATValidation"
)
webbrowser.open_new_tab("https://github.com/dseichter/VATValidation")

def validateSingle(self, event):
wx.MessageBox(
Expand All @@ -137,11 +135,17 @@ def validateSingle(self, event):
town=self.textTown.GetValue(),
type=settings.load_value_from_json_file("interface"),
lang=settings.load_value_from_json_file("language"),
iscli=False,
)

self.textResultIsValid.SetValue("Yes" if message["valid"] else "No")
self.textResultCode.SetValue(message["errorcode"])
self.textResultDetails.SetValue(message["errorcode_description"])
self.textResultDetails.SetValue(message.get("errorcode_description", ""))

# In case of empty errorcode_description, load the company, address twon, zip and street into textResultDetails
if message.get("errorcode_description", "") == "":
self.textResultDetails.SetValue(
f"Company: {message['company']}\nAddress: {message['address']}\nTown: {message['town']}\nZip: {message['zip']}\nStreet: {message['street']}"
)

def validateBatch(self, event):
if (
Expand Down
Loading

0 comments on commit 9f8b4df

Please sign in to comment.