Skip to content

Commit

Permalink
Initial working code and specification
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsieurV committed Jan 15, 2021
1 parent d98ac32 commit 79deb54
Show file tree
Hide file tree
Showing 18 changed files with 1,423 additions and 7 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: python
python:
- '2.6'
- '2.7'
- '3.5'
- '3.6'
- '3.8'
- '3.9'
install:
- pip install pipenv
- make install-dev
- make install-package-in-venv
script:
- make test
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

install:
pipenv install

install-dev:
pipenv install --dev

test:
pipenv run pytest -vv

install-package-in-venv:
pipenv uninstall --skip-lock tqwgp_parser
pipenv run python setup.py install

test-package-in-venv: install-package-in-venv test

format:
pipenv run black .

release:
pipenv run python setup.py sdist
pipenv run python setup.py bdist_wheel --universal
pipenv run twine check dist/*
pipenv run twine upload dist/*
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ hy = "*"
[dev-packages]
black = "*"
pytest = "*"
pyyaml = "*"

[requires]
python_version = "3"
21 changes: 20 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

126 changes: 123 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,147 @@ pip install tgwpg-parser

## Parsing proposals

Create and parse a quote:
First, declare your quote data:

```python
my_proposal = {
"title": "Tesla Model 3 Configurator",
"date": "29 novembre 2016",
"place": "Philadelphie",
"version": "v1",
"sect": {
"email": "[email protected]",
"logo": "tests/samples/tesla_logo.png",
"name": "BF Printer \\& Co",
},
"legal": {
"address": {
"city": "Philadelphie",
"line1": "E Thompson Saint",
"zip": "19125",
},
"siret": "999999999 00099",
},
"author": {
"civility": "M.",
"mobile": "07.73.35.51.00",
"name": "Benjamin Franklin",
"role": "membre",
},
"client": {
"contact": {
"civility": "M.",
"name": "Elon Musk",
"role": "CEO",
"sason": "son",
},
"legal": {
"address": {
"city": "Chambourcy",
"line1": "103 Route de Mantes",
"zip": "78240",
},
"siret": "524335262 00084",
},
"name": "Tesla",
},
"object": "The current proposal includes ...\n",
"prestations": [
{
"description": "Files for describing the steps of product configuration, their prices, etc.",
"price": 5000,
"title": "Definition of configurations",
}
],
}
```

> Note: your can look at more complete and various samples in [`tests/samples`](tests/samples).
You can then process this proposal data using `tqwgp_parser.parse_quote`:

```python
import pprint
from tqwgp_parser import parse_quote

my_parsed_proposal = parse_quote(my_proposal)
pprint.pprint(my_parsed_proposal)
```

> Pro-tip: the data can be declared in flat files, for eg. using Yaml or Json formats. It could also be loaded from a database: this is your choice!
## Parsing invoices

Create and parse invoices:
Declare your invoices data:

```python
my_invoices = {
"sect": {"email": "[email protected]", "name": "BF Printer \\& Co"},
"legal": {
"address": {
"city": "Philadelphie",
"line1": "E Thompson Saint",
"zip": "19125",
},
"siret": "999999999 00099",
},
"author": {
"civility": "M.",
"mobile": "07.73.35.51.00",
"name": "Benjamin Franklin",
"role": "membre",
},
"client": {
"contact": {
"civility": "M.",
"name": "Elon Musk",
"role": "CEO",
"sason": "son",
},
"legal": {
"address": {
"city": "Chambourcy",
"line1": "103 Route de Mantes",
"zip": "78240",
},
"siret": "524335262 00084",
},
"name": "Tesla",
},
"invoices": [
{
"date": "5 janvier 2017",
"lines": [{"price": 12000, "title": "Acompte devis 16-TESLA-01"}],
"number": "17001",
"vat_rate": 20,
}
],
}
```

And process it with the help of `tqwgp_parser.parse_invoices`:

```python
import pprint
from tqwgp_parser import parse_invoices

my_parsed_invoices = parse_invoices(my_invoices)
pprint.pprint(my_parsed_invoices)
```

## Going further

You could then feed the processed data to your own document edition toolchain to create PDFs from it. This could include using Pandoc and LaTeX to edit the PDF (see for eg. [mrzool's invoice-boilerplate](https://github.com/mrzool/invoice-boilerplate/) setup) ; or sending it to an online PDF compiler with your own template (for eg. with a LaTeX template and [LaTeX-on-HTTP](https://github.com/YtoTech/latex-on-http), or with HTML/CSS and [WeasyPrint](https://github.com/Kozea/WeasyPrint/tree/gh-pages/samples/invoice)).

You may also use the parsed data in a web application.

-------------------

# TQWGP text-base documents specification

The format of the TQWGP text-base documents is not finalized.

We'll use this repository as a working specification, through the samples and tests.
We'll use this repository as a working specification, through the [samples](tests/samples) and [tests](tests).


-------------------
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
description="A library for parsing Talk Quote Work Get-Paid (TQWGP) text-based compliant sales and accounting documents.",
long_description=readme_markdown,
long_description_content_type="text/markdown",
packages=["tqwgp-parser"],
packages=["tqwgp_parser"],
include_package_data=True,
zip_safe=True,
package_data={
"tqwgp_parser": ["*.hy"],
},
zip_safe=False,
platforms="any",
install_requires=["hy"],
)
93 changes: 93 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
my_proposal = {
"title": "Tesla Model 3 Configurator",
"date": "29 novembre 2016",
"place": "Philadelphie",
"version": "v1",
"sect": {
"email": "[email protected]",
"logo": "tests/samples/tesla_logo.png",
"name": "BF Printer \\& Co",
},
"legal": {
"address": {
"city": "Philadelphie",
"line1": "E Thompson Saint",
"zip": "19125",
},
"siret": "999999999 00099",
},
"author": {
"civility": "M.",
"mobile": "07.73.35.51.00",
"name": "Benjamin Franklin",
"role": "membre",
},
"client": {
"contact": {
"civility": "M.",
"name": "Elon Musk",
"role": "CEO",
"sason": "son",
},
"legal": {
"address": {
"city": "Chambourcy",
"line1": "103 Route de Mantes",
"zip": "78240",
},
"siret": "524335262 00084",
},
"name": "Tesla",
},
"object": "The current proposal includes ...\n",
"prestations": [
{
"description": "Files for describing the steps of product configuration, their prices, etc.",
"price": 5000,
"title": "Definition of configurations",
}
],
}

my_invoices = {
"sect": {"email": "[email protected]", "name": "BF Printer \\& Co"},
"legal": {
"address": {
"city": "Philadelphie",
"line1": "E Thompson Saint",
"zip": "19125",
},
"siret": "999999999 00099",
},
"author": {
"civility": "M.",
"mobile": "07.73.35.51.00",
"name": "Benjamin Franklin",
"role": "membre",
},
"client": {
"contact": {
"civility": "M.",
"name": "Elon Musk",
"role": "CEO",
"sason": "son",
},
"legal": {
"address": {
"city": "Chambourcy",
"line1": "103 Route de Mantes",
"zip": "78240",
},
"siret": "524335262 00084",
},
"name": "Tesla",
},
"invoices": [
{
"date": "5 janvier 2017",
"lines": [{"price": 12000, "title": "Acompte devis 16-TESLA-01"}],
"number": "17001",
"vat_rate": 20,
}
],
}
Loading

0 comments on commit 79deb54

Please sign in to comment.