Centralized purchases: manual input (#1935)¶
Backfilled plan. The feature shipped in two PRs plus one follow-up:
- #2017 (
5c30b52d0) — first cut:unitandcoef_to_kgadded to the centralized-purchase factor. - #2078 (
818aec4d8) — decision reversal:unitandcoef_to_kgmoved off the factor and onto the data entry. The factor keeps onlyname(classification) andef_kg_co2eq_per_kg(value). This is the settled shape. - Follow-up (this branch) — locked manual input to kg (coef forced to 1, hidden from the form) and fixed the coefficient label.
Data shape¶
- Entry (
backend/app/modules/purchase/data_entries.py,PurchaseCentralizedHandlerCreate):name,unit(free string, e.g.kg,liter),annual_consumption,coef_to_kg,note.annual_consumptionandcoef_to_kgmust be non-negative;unithas no allow-list. - Factor (
backend/app/modules/purchase/factors.py):name+ef_kg_co2eq_per_kg, matched viakind_field = "name".
Formula¶
backend/app/modules/purchase/handlers.py, PurchaseCentralizedModuleHandler.resolve_computations:
kg_co2eq = annual_consumption × coef_to_kg × ef_kg_co2eq_per_kg
coef_to_kg converts the entry's unit to kilograms of product (1 liter of liquid nitrogen = 0.8 kg); the factor's ef_kg_co2eq_per_kg then converts kg of product to kg CO₂-eq. The entry's unit is display/sort/filter only and never enters the computation. The same contract applies to CSV-ingested entries (purchases_centralized_data.csv: unit_institutional_id, name, unit, annual_consumption, coef_to_kg, note, kg_co2eq).
Follow-up: kg-only manual input + label fix¶
Manual input is deliberately kg-only, so a hand-typed row can never disagree with itself: the user cannot modify unit (read-only "kg") nor coef_to_kg (forced to 1). CSV/backoffice entries are the path for other units (liter + 0.8 etc.) and keep their real per-entry values.
frontend/src/constant/module-config/purchase.ts:unitkeepsdefault: 'kg'+readOnlyWhenFilled: true;coef_to_kggetsdefault: 1+hideIn: { form: true }(noeditableInline), so it disappears from the form but stays a sortable table column. Form ratios back to1/3for the three visible fields.frontend/src/components/organisms/module/ModuleForm.vue: the create-pathinit()now also seeds defaults for form-hidden fields (generic, config-driven), since the visible-field loop skips them andbuildPayloadonly sends seeded keys. The edit path returns early after copyingrowData, so editing an existing CSV row never clobbers its stored coef.frontend/src/i18n/purchase.ts:purchase.inputs.coef_to_kglabel corrected from "Conversion coefficient to kg CO₂-eq" to "Conversion coefficient to kg" (fr: "Coefficient de conversion en kg"), since the coefficient converts to kg of product, not kg CO₂-eq.backend/INPUT_DATA/purchases_centralized_factors.csv: stale pre-#2078 header (name,unit,coef_to_kg,ef_kg_co2eq_per_kg) reduced to the current contract (name,ef_kg_co2eq_per_kg).
Environments that uploaded centralized factors before #2078 must re-upload them with the 2-column format.