diff --git a/backend/lcfs/web/api/fuel_supply/schema.py b/backend/lcfs/web/api/fuel_supply/schema.py index 68300b1e0..60592dffe 100644 --- a/backend/lcfs/web/api/fuel_supply/schema.py +++ b/backend/lcfs/web/api/fuel_supply/schema.py @@ -119,9 +119,7 @@ class FuelSupplyCreateUpdateSchema(BaseSchema): fuel_category_id: int end_use_id: Optional[int] = None provision_of_the_act_id: int - quantity: int = Field( - ..., gt=0, description="Quantity supplied must be greater than 0" - ) + quantity: int units: str fuel_type_other: Optional[str] = None fuel_code_id: Optional[int] = None diff --git a/backend/lcfs/web/api/notional_transfer/schema.py b/backend/lcfs/web/api/notional_transfer/schema.py index 6ca7085ea..5f6571e57 100644 --- a/backend/lcfs/web/api/notional_transfer/schema.py +++ b/backend/lcfs/web/api/notional_transfer/schema.py @@ -20,9 +20,7 @@ class NotionalTransferCreateSchema(BaseSchema): address_for_service: str fuel_category: str received_or_transferred: ReceivedOrTransferredEnumSchema - quantity: int = Field( - ..., gt=0, description="Quantity supplied must be greater than 0" - ) + quantity: int notional_transfer_id: Optional[int] = None compliance_report_id: int deleted: Optional[bool] = None diff --git a/backend/lcfs/web/api/other_uses/schema.py b/backend/lcfs/web/api/other_uses/schema.py index 5f2b27727..51327f772 100644 --- a/backend/lcfs/web/api/other_uses/schema.py +++ b/backend/lcfs/web/api/other_uses/schema.py @@ -83,9 +83,7 @@ class OtherUsesCreateSchema(BaseSchema): fuel_type: str fuel_category: str provision_of_the_act: str - quantity_supplied: int = Field( - ..., gt=0, description="Quantity supplied must be greater than 0" - ) + quantity_supplied: int units: str expected_use: str fuel_code: Optional[str] = None diff --git a/backend/lcfs/web/api/transaction/schema.py b/backend/lcfs/web/api/transaction/schema.py index 8bd05856d..ad0d8411e 100644 --- a/backend/lcfs/web/api/transaction/schema.py +++ b/backend/lcfs/web/api/transaction/schema.py @@ -71,9 +71,7 @@ class TransactionViewSchema(BaseSchema): transaction_type: str from_organization: Optional[str] = None to_organization: str - quantity: int = Field( - ..., gt=0, description="Quantity supplied must be greater than 0" - ) + quantity: int price_per_unit: Optional[float] = None status: str create_date: datetime diff --git a/backend/lcfs/web/api/transfer/schema.py b/backend/lcfs/web/api/transfer/schema.py index 4d8826c10..889437c8a 100644 --- a/backend/lcfs/web/api/transfer/schema.py +++ b/backend/lcfs/web/api/transfer/schema.py @@ -48,9 +48,7 @@ class TransferSchema(BaseSchema): from_organization: TransferOrganizationSchema to_organization: TransferOrganizationSchema agreement_date: date - quantity: int = Field( - ..., gt=0, description="Quantity supplied must be greater than 0" - ) + quantity: int price_per_unit: float comments: Optional[List[TransferCommentSchema]] = None from_org_comment: Optional[str] = None diff --git a/frontend/src/views/AllocationAgreements/AddEditAllocationAgreements.jsx b/frontend/src/views/AllocationAgreements/AddEditAllocationAgreements.jsx index 664291e46..6de0b306a 100644 --- a/frontend/src/views/AllocationAgreements/AddEditAllocationAgreements.jsx +++ b/frontend/src/views/AllocationAgreements/AddEditAllocationAgreements.jsx @@ -68,27 +68,22 @@ export const AddEditAllocationAgreements = () => { } }, [location.state?.message, location.state?.severity]) - const validateField = ( - params, - field, - validationFn, - errorMessage, - alertRef - ) => { - const newValue = params.newValue + const validate = (params, validationFn, errorMessage, alertRef, field = null) => { + const value = field ? params.node?.data[field] : params; - if (params.colDef.field === field) { - if (!validationFn(newValue)) { - alertRef.current?.triggerAlert({ - message: errorMessage, - severity: 'error' - }) - return false - } + if (field && params.colDef.field !== field) { + return true; } - return true // Proceed with the update - } + if (!validationFn(value)) { + alertRef.current?.triggerAlert({ + message: errorMessage, + severity: 'error', + }); + return false; + } + return true; // Proceed with the update + }; const onGridReady = useCallback( async (params) => { @@ -168,17 +163,23 @@ export const AddEditAllocationAgreements = () => { const onCellEditingStopped = useCallback( async (params) => { - const isValid = validateField( + if (params.oldValue === params.newValue) return + + const isValid = validate( params, + (value) => { + return value !== null && !isNaN(value) && value > 0; + }, + 'Quantity supplied must be greater than 0.', + alertRef, 'quantity', - (value) => value !== null && !isNaN(value) && value > 0, - 'Quantity must be greater than 0.', - alertRef - ) + ); - if (!isValid) return + if (!isValid) { + return + } - if (params.oldValue === params.newValue) return + if (!isValid) return params.node.updateData({ ...params.node.data, diff --git a/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx b/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx index 8a8d50787..89d2af879 100644 --- a/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx +++ b/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx @@ -62,19 +62,20 @@ export const AddEditFuelSupplies = () => { } }, [location?.state?.message, location?.state?.severity]); - const validateField = (params, field, validationFn, errorMessage, alertRef) => { - const newValue = params.newValue; + const validate = (params, validationFn, errorMessage, alertRef, field = null) => { + const value = field ? params.node?.data[field] : params; - if (params.colDef.field === field) { - if (!validationFn(newValue)) { - alertRef.current?.triggerAlert({ - message: errorMessage, - severity: 'error', - }); - return false; - } + if (field && params.colDef.field !== field) { + return true; } + if (!validationFn(value)) { + alertRef.current?.triggerAlert({ + message: errorMessage, + severity: 'error', + }); + return false; + } return true; // Proceed with the update }; @@ -164,17 +165,21 @@ export const AddEditFuelSupplies = () => { const onCellEditingStopped = useCallback( async (params) => { - const isValid = validateField( + if (params.oldValue === params.newValue) return + + const isValid = validate( params, - 'quantity', - (value) => value !== null && !isNaN(value) && value > 0, + (value) => { + return value !== null && !isNaN(value) && value > 0; + }, 'Quantity supplied must be greater than 0.', - alertRef + alertRef, + 'quantity', ); - if (!isValid) return; - - if (params.oldValue === params.newValue) return + if (!isValid) { + return + } params.node.updateData({ ...params.node.data, diff --git a/frontend/src/views/FuelSupplies/_schema.jsx b/frontend/src/views/FuelSupplies/_schema.jsx index a4e074a3d..5a54ddf4e 100644 --- a/frontend/src/views/FuelSupplies/_schema.jsx +++ b/frontend/src/views/FuelSupplies/_schema.jsx @@ -102,7 +102,6 @@ export const fuelSupplyColDefs = (optionsData, errors, warnings) => [ params.data.provisionOfTheAct = null params.data.fuelCode = null params.data.fuelCodeId = null - params.data.quantity = 0 params.data.units = fuelType?.unit params.data.unrecognized = fuelType?.unrecognized } @@ -176,7 +175,6 @@ export const fuelSupplyColDefs = (optionsData, errors, warnings) => [ params.data.eer = null params.data.provisionOfTheAct = null params.data.fuelCode = null - params.data.quantity = 0 } return true }, diff --git a/frontend/src/views/NotionalTransfers/AddEditNotionalTransfers.jsx b/frontend/src/views/NotionalTransfers/AddEditNotionalTransfers.jsx index 9da54d835..313566dc0 100644 --- a/frontend/src/views/NotionalTransfers/AddEditNotionalTransfers.jsx +++ b/frontend/src/views/NotionalTransfers/AddEditNotionalTransfers.jsx @@ -47,19 +47,20 @@ export const AddEditNotionalTransfers = () => { } }, [location?.state?.message, location?.state?.severity]); - const validateField = (params, field, validationFn, errorMessage, alertRef) => { - const newValue = params.newValue; + const validate = (params, validationFn, errorMessage, alertRef, field = null) => { + const value = field ? params.node?.data[field] : params; - if (params.colDef.field === field) { - if (!validationFn(newValue)) { - alertRef.current?.triggerAlert({ - message: errorMessage, - severity: 'error', - }); - return false; - } + if (field && params.colDef.field !== field) { + return true; } + if (!validationFn(value)) { + alertRef.current?.triggerAlert({ + message: errorMessage, + severity: 'error', + }); + return false; + } return true; // Proceed with the update }; @@ -98,17 +99,21 @@ export const AddEditNotionalTransfers = () => { const onCellEditingStopped = useCallback( async (params) => { - const isValid = validateField( + if (params.oldValue === params.newValue) return + + const isValid = validate( params, + (value) => { + return value !== null && !isNaN(value) && value > 0; + }, + 'Quantity supplied must be greater than 0.', + alertRef, 'quantity', - (value) => value !== null && !isNaN(value) && value > 0, - 'Quantity must be greater than 0.', - alertRef ); - if (!isValid) return; - - if (params.oldValue === params.newValue) return + if (!isValid) { + return + } // Initialize updated data with 'pending' status params.node.updateData({ diff --git a/frontend/src/views/OtherUses/AddEditOtherUses.jsx b/frontend/src/views/OtherUses/AddEditOtherUses.jsx index 8edacd334..9b3c2f641 100644 --- a/frontend/src/views/OtherUses/AddEditOtherUses.jsx +++ b/frontend/src/views/OtherUses/AddEditOtherUses.jsx @@ -81,19 +81,20 @@ export const AddEditOtherUses = () => { return ciOfFuel; }, []); - const validateField = (params, field, validationFn, errorMessage, alertRef) => { - const newValue = params.newValue; + const validate = (params, validationFn, errorMessage, alertRef, field = null) => { + const value = field ? params.node?.data[field] : params; - if (params.colDef.field === field) { - if (!validationFn(newValue)) { - alertRef.current?.triggerAlert({ - message: errorMessage, - severity: 'error', - }); - return false; - } + if (field && params.colDef.field !== field) { + return true; } + if (!validationFn(value)) { + alertRef.current?.triggerAlert({ + message: errorMessage, + severity: 'error', + }); + return false; + } return true; // Proceed with the update }; @@ -185,17 +186,22 @@ export const AddEditOtherUses = () => { const onCellEditingStopped = useCallback( async (params) => { - const isValid = validateField( + if (params.oldValue === params.newValue) return + + const isValid = validate( params, - 'quantitySupplied', - (value) => value !== null && !isNaN(value) && value > 0, + (value) => { + return value !== null && !isNaN(value) && value > 0; + }, 'Quantity supplied must be greater than 0.', - alertRef + alertRef, + 'quantitySupplied', ); - if (!isValid) return; + if (!isValid) { + return + } - if (params.oldValue === params.newValue) return params.data.complianceReportId = complianceReportId params.data.validationStatus = 'pending'