Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Validata): Achats: Modifie le schéma pour accepter des decimal avec virgule #5001

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 2024-frontend/src/services/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ const getFieldType = (field) => {
return types[`${field.type}_enum`]
} else if (field.constraints.pattern && field.doc_enum && field.doc_enum_multiple) {
return types[`${field.type}_enum_multiple`]
} else if (field.constaints.pattern && field.doc_pattern) {
// examples: 'number'
return types[field.doc_pattern]
}
}
if (field.name in types) {
// examples: 'siret', 'siret_livreur_repas'
return types[field.name]
}
return types[field.type]
Expand Down
8 changes: 8 additions & 0 deletions api/tests/test_import_purchases.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class TestPurchaseSchema(TestCase):
def setUpTestData(cls):
cls.schema = json.load(open("data/schemas/imports/achats.json"))

def test_prix_ht_decimal(self):
field_index = next((i for i, f in enumerate(self.schema["fields"]) if f["name"] == "prix_ht"), None)
pattern = self.schema["fields"][field_index]["constraints"]["pattern"]
for VALUE_OK in ["1234", "1234.0", "1234.99", "1234,0", "1234,99"]:
self.assertTrue(re.match(pattern, VALUE_OK))
for VALUE_NOT_OK in ["", " ", "TEST", "1234.999", "1234.99.99", "1234,999", "1234,99,99"]:
self.assertFalse(re.match(pattern, VALUE_NOT_OK))

def test_famille_produits_regex(self):
field_index = next((i for i, f in enumerate(self.schema["fields"]) if f["name"] == "famille_produits"), None)
pattern = self.schema["fields"][field_index]["constraints"]["pattern"]
Expand Down
4 changes: 3 additions & 1 deletion data/schemas/imports/achats.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@
},
{
"constraints": {
"pattern": "^\\d+([.,]\\d{1,2})?$",
"required": true
},
"description": "",
"doc_pattern": "number",
"example": "1234.99",
"format": "default",
"name": "prix_ht",
"title": "Prix HT de l'achat",
"type": "number"
"type": "string"
},
{
"constraints": {
Expand Down
Loading