Skip to content

Commit

Permalink
Add quantity support on quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsieurV committed Feb 15, 2021
1 parent c978398 commit 2e5d582
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ indent_style = space
indent_size = 4

[Makefile]
indent_style = tab
indent_style = tab

[*.hy]
indent_size = 2
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="tqwgp-parser",
version="0.0.3",
version="0.0.4",
url="https://github.com/YtoTech/talk-quote-work-getpaid-parser",
license="AGPL-3.0",
author="Yoan Tournade",
Expand Down
25 changes: 25 additions & 0 deletions tests/test_definitions_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def load_definition_from_file(path):
SAMPLE_DIR + "TESLA-SECTIONS/quote.yml"
)
TESLA_BATCHES_QUOTE = load_definition_from_file(SAMPLE_DIR + "TESLA-BATCHES/quote.yml")
TESLA_QUANTITIES_QUOTE = load_definition_from_file(SAMPLE_DIR + "TESLA-QUANTITIES/quote.yml")

# TODO Make an universal data validation framework.
QUOTE_MANDATORY_ENTRIES = [
Expand Down Expand Up @@ -107,6 +108,7 @@ def test_parse_simple_quote():
assert quote["optional_price"]["total_vat_excl"] == 14000
assert len(quote["all_prestations"]) == 4
assert len(quote["optional_prestations"]) == 1
assert quote["has_quantities"] is False
assert quote["prestations"][0]["title"] == "Création des configurations sur le CPQ"
assert quote["prestations"][0]["price"] == 5000
assert quote["prestations"][0]["optional"] is False
Expand Down Expand Up @@ -297,6 +299,29 @@ def test_parse_quote_with_optional_sections():
assert quote["sections"][1]["optional"] == True


def test_parse_quote_with_quantities():
"""
Parse a quote definition including quantities.
"""
quote = parse_quote(TESLA_QUANTITIES_QUOTE)
checkQuote(quote)
assert quote["title"] == "Configurateur de Tesla Model 3"
assert quote["sect"]["logo"]["path"] == "tests/samples/tesla_logo.png"
assert quote["sect"]["logo"]["file"] == "tests/samples/tesla_logo.png"
assert quote["has_quantities"] is True
assert quote["price"]["total_vat_excl"] == 35000
assert len(quote["prestations"]) == 2
assert len(quote["all_prestations"]) == 2
assert len(quote["optional_prestations"]) == 0
assert quote["prestations"][0]["title"] == "Création des configurations sur le CPQ"
assert quote["prestations"][0]["price"] == 5000
assert quote["prestations"][0]["optional"] is False
assert quote["prestations"][0]["quantity"] == 1
assert quote["prestations"][1]["title"] == "Intégration de l'UI"
assert quote["prestations"][1]["price"] == 10000
assert quote["prestations"][1]["optional"] is False
assert quote["prestations"][1]["quantity"] == 3

# ------------------------------------------------------------------------------
# Invoices.
# ------------------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion tqwgp_parser/parser.hy
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@
(merge-dicts [
(parse-dict-values prestation
["title"]
["price" "description" "batch" "optional"])
["price" "quantity" "description" "batch" "optional"])
{
"quantity" (get-default prestation "quantity" 1)
"section" (get-default (if (none? section) {} section) "title" None)
"batch" (parse-batch (get-default prestation "batch" (get-default (if (none? section) {} section) "batch" None)))
"optional" (get-default prestation "optional" (get-default (if (none? section) {} section) "optional" False))
Expand Down Expand Up @@ -259,6 +260,7 @@
(setv (, all-optional-prestations optional-sections)
(parse-all-prestations (recompose-optional-prestations sections all-prestations)))
(setv vat-rate (get-default definition "vat_rate" None))
(setv has-quantities (any (map (fn [prestation] (> (get prestation "quantity") 1)) all-prestations)))
(merge-dicts [
;; TODO Make the validation of the input dict recursive.
(parse-dict-values definition
Expand All @@ -273,6 +275,7 @@
"all_prestations" all-prestations
"sections" sections
;; Derive from section and all_prestations.
"has_quantities" has-quantities
"prestations" (recompose-prestations sections all-prestations)
"optional_prestations" all-optional-prestations
"optional_sections" optional-sections
Expand Down

0 comments on commit 2e5d582

Please sign in to comment.