diff --git a/app/core/config.py b/app/core/config.py index aec069195..1937b5287 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -192,8 +192,8 @@ class Settings(BaseSettings): # Hyperion follows Semantic Versioning # https://semver.org/ - HYPERION_VERSION: str = "3.0.1" - MINIMAL_TITAN_VERSION_CODE: int = 130 + HYPERION_VERSION: str = "3.0.2" + MINIMAL_TITAN_VERSION_CODE: int = 113 ###################################### # Automatically generated parameters # diff --git a/app/modules/cdr/cruds_cdr.py b/app/modules/cdr/cruds_cdr.py index 8df7528c0..3cac5f983 100644 --- a/app/modules/cdr/cruds_cdr.py +++ b/app/modules/cdr/cruds_cdr.py @@ -480,7 +480,25 @@ async def delete_purchase( db: AsyncSession, user_id: str, product_variant_id: UUID, + product_id: UUID, ): + fields = ( + ( + await db.execute( + select(models_cdr.CustomDataField).where( + models_cdr.CustomDataField.product_id == product_id, + ), + ) + ) + .scalars() + .all() + ) + await db.execute( + delete(models_cdr.CustomData).where( + models_cdr.CustomData.user_id == user_id, + models_cdr.CustomData.field_id.in_([field.id for field in fields]), + ), + ) await db.execute( delete(models_cdr.Purchase).where( models_cdr.Purchase.user_id == user_id, diff --git a/app/modules/cdr/endpoints_cdr.py b/app/modules/cdr/endpoints_cdr.py index 626ce709a..4037c4e09 100644 --- a/app/modules/cdr/endpoints_cdr.py +++ b/app/modules/cdr/endpoints_cdr.py @@ -393,7 +393,7 @@ async def generate_and_send_results( product.id, ), ) - variant_ids = [v.id for v in product_variants] + variant_ids = [v.id for v in variants] purchases = await cruds_cdr.get_all_purchases(db) if len(purchases) == 0: raise HTTPException( @@ -1767,6 +1767,7 @@ async def delete_purchase( user_id=user_id, product_variant_id=product_variant_id, db=db, + product_id=product.id, ) cruds_cdr.create_action(db, db_action) await db.commit() diff --git a/app/modules/cdr/utils_cdr.py b/app/modules/cdr/utils_cdr.py index 1a48826e2..e428bcb41 100644 --- a/app/modules/cdr/utils_cdr.py +++ b/app/modules/cdr/utils_cdr.py @@ -176,8 +176,8 @@ def construct_dataframe_from_users_purchases( """ columns = ["Nom", "Prénom", "Surnom", "Email"] data = ["", "", "", "Prix"] - field_to_column = {} - variant_to_column = {} + field_to_column: dict[UUID, str] = {} + variant_to_column: dict[UUID, str] = {} for product in products: product_variants = [ variant for variant in variants if variant.product_id == product.id @@ -189,7 +189,7 @@ def construct_dataframe_from_users_purchases( columns.extend( [f"{product.name_fr} : {field.name}" for field in fields], ) - data.extend([str(variant.price) for variant in product_variants]) + data.extend([str(variant.price / 100) for variant in product_variants]) data.extend([" " for _ in fields]) field_to_column.update( @@ -241,14 +241,15 @@ def construct_dataframe_from_users_purchases( df.loc[user_id, "Prénom"] = user.firstname df.loc[user_id, "Surnom"] = user.nickname df.loc[user_id, "Email"] = user.email - if all(purchase.validated for purchase in users_purchases[user_id]): - df.loc[user_id, "Panier payé"] = True - else: - df.loc[user_id, "Panier payé"] = False - df.loc[user_id, "Commentaire"] = "Manquant : \n-" + "\n-".join( - variant_to_column[purchase.product_variant_id] - for purchase in users_purchases[user_id] - if not purchase.validated - ) + if user_id in users_purchases: + if all(purchase.validated for purchase in users_purchases[user_id]): + df.loc[user_id, "Panier payé"] = True + else: + df.loc[user_id, "Panier payé"] = False + df.loc[user_id, "Commentaire"] = "Manquant : \n-" + "\n-".join( + variant_to_column[purchase.product_variant_id] + for purchase in users_purchases[user_id] + if not purchase.validated + ) df.fillna("", inplace=True) return df diff --git a/tests/test_cdr.py b/tests/test_cdr.py index e3fd238fc..dcbf82035 100644 --- a/tests/test_cdr.py +++ b/tests/test_cdr.py @@ -2750,3 +2750,30 @@ async def test_delete_customdata(client: TestClient): headers={"Authorization": f"Bearer {token_bde}"}, ) assert response.status_code == 204 + + +async def test_customdata_deletion_on_purchase_deletion(client: TestClient): + field = models_cdr.CustomDataField( + id=uuid.uuid4(), + product_id=product.id, + name="Supprime", + ) + await add_object_to_db(field) + customdata = models_cdr.CustomData( + field_id=field.id, + user_id=cdr_user.id, + value="Edit", + ) + await add_object_to_db(customdata) + + response = client.delete( + f"/cdr/users/{cdr_user.id}/purchases/{variant.id}/", + headers={"Authorization": f"Bearer {token_admin}"}, + ) + assert response.status_code == 204 + + response = client.get( + f"/cdr/sellers/{seller.id}/products/{product.id}/users/{cdr_user.id}/data/{field.id}/", + headers={"Authorization": f"Bearer {token_admin}"}, + ) + assert response.status_code == 404