From 85a70da07da2af0326f59c302be94778ef6ca68a Mon Sep 17 00:00:00 2001 From: Julien Aldon Date: Fri, 20 Feb 2026 17:36:32 +0100 Subject: [PATCH] add max payment method for cheque --- README.md | 19 +++-------- .../alembic/versions/7854064278ce_message.py | 33 +++++++++++++++++++ backend/src/models.py | 1 + backend/src/productors/service.py | 3 +- frontend/locales/en.json | 2 ++ frontend/locales/fr.json | 2 ++ .../PaymentMethods/Cheque/index.tsx | 19 +++++++---- .../src/components/Productors/Modal/index.tsx | 22 +++++++++---- frontend/src/pages/Contract/index.tsx | 5 +-- frontend/src/services/resources/productors.ts | 1 + 10 files changed, 75 insertions(+), 32 deletions(-) create mode 100644 backend/alembic/versions/7854064278ce_message.py diff --git a/README.md b/README.md index e8e84f2..7d3387b 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,11 @@ ## backend\src\contracts\contracts.py -- Send contract to referer - Extract recap -- Extract all contracts -- store total price + +## Payment method max cheque number + +## Link products to a form ## Wording @@ -28,14 +29,4 @@ ### Contact -## Migrations - -- use alembic for migration management - -## Filter forms in home view - -## Only show current season (if multiple form, only show the one with latest start date) - -## Update contract after register - -## Default filter +## Update contract after (without registration) diff --git a/backend/alembic/versions/7854064278ce_message.py b/backend/alembic/versions/7854064278ce_message.py new file mode 100644 index 0000000..9521bd5 --- /dev/null +++ b/backend/alembic/versions/7854064278ce_message.py @@ -0,0 +1,33 @@ +"""message + +Revision ID: 7854064278ce +Revises: c0b1073a8394 +Create Date: 2026-02-20 17:17:25.739406 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + +import sqlmodel.sql.sqltypes + +# revision identifiers, used by Alembic. +revision: str = '7854064278ce' +down_revision: Union[str, Sequence[str], None] = 'c0b1073a8394' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + """Upgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('paymentmethod', sa.Column('max', sa.Integer(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade() -> None: + """Downgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('paymentmethod', 'max') + # ### end Alembic commands ### diff --git a/backend/src/models.py b/backend/src/models.py index d5e8f6a..9ce18fd 100644 --- a/backend/src/models.py +++ b/backend/src/models.py @@ -36,6 +36,7 @@ class UserCreate(UserBase): class PaymentMethodBase(SQLModel): name: str details: str + max: int | None class PaymentMethod(PaymentMethodBase, table=True): id: int | None = Field(default=None, primary_key=True) diff --git a/backend/src/productors/service.py b/backend/src/productors/service.py index 247b13e..89a8a0a 100644 --- a/backend/src/productors/service.py +++ b/backend/src/productors/service.py @@ -47,7 +47,8 @@ def update_one(session: Session, id: int, productor: models.ProductorUpdate) -> models.PaymentMethod( name=pm["name"], details=pm["details"], - productor_id=id + productor_id=id, + max=pm["max"] ) ) del productor_updates["payment_methods"] diff --git a/frontend/locales/en.json b/frontend/locales/en.json index 5e00fa2..22bd8f1 100644 --- a/frontend/locales/en.json +++ b/frontend/locales/en.json @@ -92,6 +92,8 @@ "templates": "templates", "users": "users", "forms": "contract forms", + "max cheque number": "max cheque number", + "can be empty default to 3": "can be empty default to 3", "form": "contract form", "select a form": "select a form", "download contracts": "download contracts", diff --git a/frontend/locales/fr.json b/frontend/locales/fr.json index d4ee378..e0ae3f8 100644 --- a/frontend/locales/fr.json +++ b/frontend/locales/fr.json @@ -94,6 +94,8 @@ "by selecting a form here you can download all contracts of your form": "en selectionnant un formulaire, vous téléchargez tous les contrats pour un formulaire donné.", "edit user": "modifier l'utilisateur·trice", "remove user": "supprimer l'utilisateur·trice", + "max cheque number": "numbre maximum de cheques possible", + "can be empty default to 3": "optionnel, la valeur par défaut est à 3 cheques", "all forms": "tous les formulaires de contrat", "create new form": "créer un nouveau formulaire de contrat", "actions": "actions", diff --git a/frontend/src/components/PaymentMethods/Cheque/index.tsx b/frontend/src/components/PaymentMethods/Cheque/index.tsx index 0bbb8dc..64fde29 100644 --- a/frontend/src/components/PaymentMethods/Cheque/index.tsx +++ b/frontend/src/components/PaymentMethods/Cheque/index.tsx @@ -1,13 +1,14 @@ import { t } from "@/config/i18n"; import type { ContractInputs } from "@/services/resources/contracts"; -import { Group, NumberInput, Stack, Text, TextInput, Title } from "@mantine/core"; +import type { Productor } from "@/services/resources/productors"; +import { Group, NumberInput, Stack, TextInput, Title } from "@mantine/core"; import type { UseFormReturnType } from "@mantine/form"; -import { useEffect } from "react"; +import { useEffect, useMemo } from "react"; export type ContractChequeProps = { inputForm: UseFormReturnType; price: number; - chequeOrder: string; + productor: Productor; }; export type Cheque = { @@ -15,7 +16,7 @@ export type Cheque = { value: string; }; -export function ContractCheque({ inputForm, price, chequeOrder }: ContractChequeProps) { +export function ContractCheque({ inputForm, price, productor }: ContractChequeProps) { useEffect(() => { if (!inputForm.values.payment_method.includes("cheque")) { return; @@ -41,9 +42,13 @@ export function ContractCheque({ inputForm, price, chequeOrder }: ContractCheque // eslint-disable-next-line react-hooks/exhaustive-deps }, [inputForm.values.cheque_quantity, price, inputForm.values.cheques]); + const paymentMethod = useMemo(() => { + return productor?.payment_methods.find((el) => el.name === "cheque") + }, [productor]); + return ( - {`${t("order name")} : ${chequeOrder}`} + {`${t("order name")} : ${paymentMethod?.details}`} @@ -64,7 +69,7 @@ export function ContractCheque({ inputForm, price, chequeOrder }: ContractCheque {...inputForm.getInputProps(`cheques.${index}.name`)} error={ cheque.name == "" ? - {inputForm?.errors.cheques} : + inputForm?.errors.cheques : null } /> diff --git a/frontend/src/components/Productors/Modal/index.tsx b/frontend/src/components/Productors/Modal/index.tsx index a56ffc7..7d1e901 100644 --- a/frontend/src/components/Productors/Modal/index.tsx +++ b/frontend/src/components/Productors/Modal/index.tsx @@ -3,7 +3,9 @@ import { Group, Modal, MultiSelect, + NumberInput, Select, + Stack, TextInput, Title, type ModalBaseProps, @@ -107,6 +109,7 @@ export function ProductorModal({ existing ?? { name, details: "", + max: null, } ); }), @@ -115,12 +118,19 @@ export function ProductorModal({ /> {form.values.payment_methods.map((method, index) => method.name === "cheque" ? ( - + + + + ) : null, )} diff --git a/frontend/src/pages/Contract/index.tsx b/frontend/src/pages/Contract/index.tsx index db07b10..a175421 100644 --- a/frontend/src/pages/Contract/index.tsx +++ b/frontend/src/pages/Contract/index.tsx @@ -286,10 +286,7 @@ export function Contract() { /> {inputForm.values.payment_method === "cheque" ? ( el.name === "cheque") - ?.details || "" - } + productor={form?.productor} price={price} inputForm={inputForm} /> diff --git a/frontend/src/services/resources/productors.ts b/frontend/src/services/resources/productors.ts index 4cab000..9845d9c 100644 --- a/frontend/src/services/resources/productors.ts +++ b/frontend/src/services/resources/productors.ts @@ -9,6 +9,7 @@ export const PaymentMethods = [ export type PaymentMethod = { name: string; details: string; + max: number | null; }; export type Productor = {