diff --git a/.editorconfig b/.editorconfig index 54303c4..be6171e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,4 +12,7 @@ indent_style = space indent_size = 4 [Makefile] -indent_style = tab \ No newline at end of file +indent_style = tab + +[*.hy] +indent_size = 2 diff --git a/setup.py b/setup.py index 6149b15..2013945 100644 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/tests/test_definitions_parsing.py b/tests/test_definitions_parsing.py index 664641e..fe8afc1 100644 --- a/tests/test_definitions_parsing.py +++ b/tests/test_definitions_parsing.py @@ -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 = [ @@ -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 @@ -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. # ------------------------------------------------------------------------------ diff --git a/tqwgp_parser/parser.hy b/tqwgp_parser/parser.hy index 575db12..ddd1c08 100644 --- a/tqwgp_parser/parser.hy +++ b/tqwgp_parser/parser.hy @@ -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)) @@ -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 @@ -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