@@ -728,6 +728,7 @@ async def create_product(
728728 name_fr = product .name_fr ,
729729 name_en = product .name_en ,
730730 available_online = product .available_online ,
731+ needs_validation = product .needs_validation ,
731732 description_fr = product .description_fr ,
732733 description_en = product .description_en ,
733734 related_membership_id = product .related_membership .id
@@ -923,6 +924,11 @@ async def create_product_variant(
923924 status_code = 403 ,
924925 detail = "CDR is closed. You cant add a new product." ,
925926 )
927+ if product and not product .needs_validation and product_variant .price != 0 :
928+ raise HTTPException (
929+ status_code = 403 ,
930+ detail = "A product that does not need validation must be free." ,
931+ )
926932 db_product_variant = models_cdr .ProductVariant (
927933 id = uuid4 (),
928934 product_id = product_id ,
@@ -1032,6 +1038,15 @@ async def update_product_variant(
10321038 status_code = 403 ,
10331039 detail = "This product has no related membership. You can't specify a membership duration." ,
10341040 )
1041+ if (
1042+ product_variant .price is not None
1043+ and db_product
1044+ and (not db_product .needs_validation and product_variant .price != 0 )
1045+ ):
1046+ raise HTTPException (
1047+ status_code = 403 ,
1048+ detail = "A product that does not need validation must be free." ,
1049+ )
10351050
10361051 await cruds_cdr .update_product_variant (
10371052 variant_id = variant_id ,
@@ -1266,6 +1281,7 @@ async def get_purchases_by_user_id(
12661281 name_fr = product .name_fr ,
12671282 name_en = product .name_en ,
12681283 available_online = product .available_online ,
1284+ needs_validation = product .needs_validation ,
12691285 description_fr = product .description_fr ,
12701286 description_en = product .description_en ,
12711287 related_membership = schemas_memberships .MembershipSimple (
@@ -1354,6 +1370,7 @@ async def get_purchases_by_user_id_by_seller_id(
13541370 name_fr = product .name_fr ,
13551371 name_en = product .name_en ,
13561372 available_online = product .available_online ,
1373+ needs_validation = product .needs_validation ,
13571374 description_fr = product .description_fr ,
13581375 description_en = product .description_en ,
13591376 related_membership = schemas_memberships .MembershipSimple (
@@ -1562,7 +1579,7 @@ async def mark_purchase_as_validated(
15621579 db = db ,
15631580 product_id = product_variant .product_id ,
15641581 )
1565- if not product :
1582+ if not product or not product . needs_validation :
15661583 raise HTTPException (
15671584 status_code = 404 ,
15681585 detail = "Invalid product." ,
0 commit comments