Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/modules/amap/cruds_amap.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ async def create_cash_of_user(
raise ValueError(err)


async def add_cash(db: AsyncSession, user_id: str, amount: float):
async def add_cash(db: AsyncSession, user_id: str, amount: int):
result = await db.execute(
select(models_amap.Cash).where(models_amap.Cash.user_id == user_id)
)
Expand All @@ -378,7 +378,7 @@ async def add_cash(db: AsyncSession, user_id: str, amount: float):
raise ValueError("Error during cash edition")


async def remove_cash(db: AsyncSession, user_id: str, amount: float):
async def remove_cash(db: AsyncSession, user_id: str, amount: int):
result = await db.execute(
select(models_amap.Cash).where(models_amap.Cash.user_id == user_id)
)
Expand Down
16 changes: 8 additions & 8 deletions app/modules/amap/endpoints_amap.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ async def add_order_to_delievery(
status_code=403, detail="You are not allowed to add this order"
)

amount = 0.0
amount = 0
for product_id, product_quantity in zip(
order.products_ids, order.products_quantity
):
Expand Down Expand Up @@ -483,7 +483,7 @@ async def add_order_to_delievery(
productsret = await cruds_amap.get_products_of_order(db=db, order_id=order_id)

hyperion_amap_logger.info(
f"Add_order_to_delivery: An order has been created for user {order.user_id} for an amount of {amount}€. ({request_id})"
f"Add_order_to_delivery: An order has been created for user {order.user_id} for an amount of {amount//100}€{amount%100}. ({request_id})"
)
productsret
return schemas_amap.OrderReturn(productsdetail=productsret, **orderret.__dict__)
Expand Down Expand Up @@ -553,7 +553,7 @@ async def edit_order_from_delivery(
):
raise HTTPException(status_code=400, detail="Invalid request")

amount = 0.0
amount = 0
for product_id, product_quantity in zip(
order.products_ids, order.products_quantity
):
Expand Down Expand Up @@ -601,7 +601,7 @@ async def edit_order_from_delivery(
amount=previous_amount,
)
hyperion_amap_logger.info(
f"Edit_order: Order {order_id} has been edited for user {db_order.user_id}. Amount was {previous_amount}€, is now {amount}€. ({request_id})"
f"Edit_order: Order {order_id} has been edited for user {db_order.user_id}. Amount was {previous_amount//100}€{previous_amount%100}, is now {amount//100}€{amount%100}. ({request_id})"
)

except ValueError as error:
Expand Down Expand Up @@ -674,7 +674,7 @@ async def remove_order(
amount=amount,
)
hyperion_amap_logger.info(
f"Delete_order: Order {order_id} by {order.user_id} was deleted. {amount}€ were refunded. ({request_id})"
f"Delete_order: Order {order_id} by {order.user_id} was deleted. {amount//100}€{amount%100} were refunded. ({request_id})"
)
return Response(status_code=204)

Expand Down Expand Up @@ -869,7 +869,7 @@ async def create_cash_of_user(
)

hyperion_amap_logger.info(
f"Create_cash_of_user: A cash has been created for user {cash_db.user_id} for an amount of {cash_db.balance}€. ({request_id})"
f"Create_cash_of_user: A cash has been created for user {cash_db.user_id} for an amount of {cash_db.balance//100}€{cash_db.balance%100}. ({request_id})"
)

# We can not directly return the cash_db because it does not contain the user.
Expand All @@ -886,7 +886,7 @@ async def create_cash_of_user(
context=f"amap-cash-{user_id}",
is_visible=True,
title="AMAP - Solde mis à jour",
content=f"Votre nouveau solde est de {result.balance} €.",
content=f"Votre nouveau solde est de {result.balance//100}€{result.balance%100}.",
# The notification will expire in 3 days
expire_on=now.replace(day=now.day + 3),
)
Expand Down Expand Up @@ -931,7 +931,7 @@ async def edit_cash_by_id(
await cruds_amap.add_cash(user_id=user_id, amount=balance.balance, db=db)

hyperion_amap_logger.info(
f"Edit_cash_by_id: Cash has been updated for user {cash.user_id} from an amount of {cash.balance}€ to an amount of {balance.balance}€. ({request_id})"
f"Edit_cash_by_id: Cash has been updated for user {cash.user_id} from an amount of {cash.balance//100}€{cash.balance%100} to an amount of {balance.balance//100}€{balance.balance%100}. ({request_id})"
)


Expand Down
8 changes: 4 additions & 4 deletions app/modules/amap/models_amap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from datetime import date, datetime

from sqlalchemy import Date, DateTime, Enum, Float, ForeignKey, Integer, String
from sqlalchemy import Date, DateTime, Enum, ForeignKey, Integer, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from app.core.models_core import CoreUser
Expand Down Expand Up @@ -39,7 +39,7 @@ class Product(Base):
name: Mapped[Mapped[str]] = mapped_column(
String, index=True, nullable=False, unique=True
)
price: Mapped[float] = mapped_column(Float, nullable=False)
price: Mapped[int] = mapped_column(Integer, nullable=False)
category: Mapped[str] = mapped_column(String, index=True, nullable=False)


Expand Down Expand Up @@ -79,7 +79,7 @@ class Order(Base):
secondary="amap_order_content",
viewonly=True,
)
amount: Mapped[float] = mapped_column(Float, nullable=False)
amount: Mapped[int] = mapped_column(Integer, nullable=False)
collection_slot: Mapped[AmapSlotType] = mapped_column(
Enum(AmapSlotType), nullable=False
)
Expand All @@ -96,7 +96,7 @@ class Cash(Base):
String, ForeignKey("core_user.id"), primary_key=True
)
user: Mapped[CoreUser] = relationship("CoreUser")
balance: Mapped[float] = mapped_column(Float, nullable=False)
balance: Mapped[int] = mapped_column(Integer, nullable=False)


class AmapInformation(Base):
Expand Down
8 changes: 4 additions & 4 deletions app/modules/amap/schemas_amap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ProductBase(BaseModel):
"""Base schema for AMAP products"""

name: str
price: float
price: int # The price is in cents to avoid rounding error


class ProductSimple(ProductBase):
Expand All @@ -30,7 +30,7 @@ class ProductSimple(ProductBase):
class ProductEdit(BaseModel):
category: str | None = None
name: str | None = None
price: float | None = None
price: int | None = None


class ProductComplete(ProductSimple):
Expand Down Expand Up @@ -114,7 +114,7 @@ class AddProductDelivery(BaseModel):


class CashBase(BaseModel):
balance: float
balance: int
user_id: str
model_config = ConfigDict(from_attributes=True)

Expand All @@ -128,7 +128,7 @@ class CashDB(CashBase):


class CashEdit(BaseModel):
balance: float
balance: int


class Information(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion app/modules/raffle/cruds_raffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ async def create_cash_of_user(
raise err


async def edit_cash(db: AsyncSession, user_id: str, amount: float):
async def edit_cash(db: AsyncSession, user_id: str, amount: int):
await db.execute(
update(models_raffle.Cash)
.where(models_raffle.Cash.user_id == user_id)
Expand Down
13 changes: 9 additions & 4 deletions app/modules/raffle/endpoints_raffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,13 @@ async def get_raffle_stats(
tickets = await cruds_raffle.get_tickets_by_raffleid(db=db, raffle_id=raffle_id)

tickets_sold = len(tickets)
amount_raised = sum(
[ticket.pack_ticket.price / ticket.pack_ticket.pack_size for ticket in tickets]
amount_raised = int(
sum(
[
ticket.pack_ticket.price / ticket.pack_ticket.pack_size
for ticket in tickets
]
)
)

return schemas_raffle.RaffleStats(
Expand Down Expand Up @@ -459,7 +464,7 @@ async def buy_ticket(
user_id=user.id,
)
balance = models_raffle.Cash(
**new_cash_db.dict(),
**new_cash_db.model_dump(),
)
await cruds_raffle.create_cash_of_user(
cash=balance,
Expand Down Expand Up @@ -499,7 +504,7 @@ async def buy_ticket(
firstname=user.firstname, name=user.name, nickname=user.nickname
)
hyperion_raffle_logger.info(
f"Add_ticket_to_user: A pack of {pack_ticket.pack_size} tickets of type {pack_id} has been buyed by user {display_name}({user.id}) for an amount of {pack_ticket.price}€. ({request_id})"
f"Add_ticket_to_user: A pack of {pack_ticket.pack_size} tickets of type {pack_id} has been buyed by user {display_name}({user.id}) for an amount of {pack_ticket.price//100}€{pack_ticket.price%100}. ({request_id})"
)

return tickets
Expand Down
6 changes: 3 additions & 3 deletions app/modules/raffle/models_raffle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Models file for module_tombola"""

from sqlalchemy import Enum, Float, ForeignKey, Integer, String
from sqlalchemy import Enum, ForeignKey, Integer, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from app.core.models_core import CoreGroup, CoreUser
Expand Down Expand Up @@ -30,7 +30,7 @@ class PackTicket(Base):
id: Mapped[str] = mapped_column(
String, primary_key=True, index=True, nullable=False
)
price: Mapped[float] = mapped_column(Float, nullable=False)
price: Mapped[int] = mapped_column(Integer, nullable=False)
pack_size: Mapped[int] = mapped_column(Integer, nullable=False)
raffle_id: Mapped[str] = mapped_column(
ForeignKey("raffle.id"), index=True, nullable=False
Expand Down Expand Up @@ -80,6 +80,6 @@ class Cash(Base):
user_id: Mapped[str] = mapped_column(
String, ForeignKey("core_user.id"), primary_key=True
)
balance: Mapped[float] = mapped_column(Float, nullable=False)
balance: Mapped[int] = mapped_column(Integer, nullable=False)

user: Mapped[CoreUser] = relationship("CoreUser")
10 changes: 5 additions & 5 deletions app/modules/raffle/schemas_raffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RaffleComplete(RaffleBase):

class RaffleStats(BaseModel):
tickets_sold: int
amount_raised: float
amount_raised: int


class PrizeBase(BaseModel):
Expand Down Expand Up @@ -55,15 +55,15 @@ class PrizeComplete(PrizeBase):


class PackTicketBase(BaseModel):
price: float
price: int
pack_size: int
raffle_id: str
model_config = ConfigDict(from_attributes=True)


class PackTicketEdit(BaseModel):
raffle_id: str | None = None
price: float | None = None
price: int | None = None
pack_size: int | None = None
model_config = ConfigDict(from_attributes=True)

Expand Down Expand Up @@ -97,7 +97,7 @@ class TicketComplete(TicketSimple):


class CashBase(BaseModel):
balance: float
balance: int
user_id: str
model_config = ConfigDict(from_attributes=True)

Expand All @@ -111,4 +111,4 @@ class CashDB(CashBase):


class CashEdit(BaseModel):
balance: float
balance: int
8 changes: 4 additions & 4 deletions tests/test_amap.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ async def init_objects():
student_user = await create_user_with_groups([GroupType.student])

product = models_amap.Product(
id=str(uuid.uuid4()), name="Tomato", price=1.5, category="Test"
id=str(uuid.uuid4()), name="Tomato", price=150, category="Test"
)
await add_object_to_db(product)
deletable_product = models_amap.Product(
id=str(uuid.uuid4()), name="Deletable Tomato", price=1.5, category="Test"
id=str(uuid.uuid4()), name="Deletable Tomato", price=150, category="Test"
)
await add_object_to_db(deletable_product)

Expand Down Expand Up @@ -117,7 +117,7 @@ def test_create_product():

response = client.post(
"/amap/products",
json={"name": "test", "price": 0.1, "category": "test"},
json={"name": "test", "price": 10, "category": "test"},
headers={"Authorization": f"Bearer {token}"},
)
assert response.status_code == 201
Expand All @@ -139,7 +139,7 @@ def test_edit_product():

response = client.patch(
f"/amap/products/{product.id}",
json={"name": "testupdate", "price": 0.1, "category": "test"},
json={"name": "testupdate", "price": 10, "category": "test"},
headers={"Authorization": f"Bearer {token}"},
)
assert response.status_code == 204
Expand Down
14 changes: 7 additions & 7 deletions tests/test_raffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ async def init_objects():
await add_object_to_db(raffle_to_draw)

packticket = models_raffle.PackTicket(
id=str(uuid.uuid4()), price=1.0, pack_size=1, raffle_id=raffle.id
id=str(uuid.uuid4()), price=100, pack_size=1, raffle_id=raffle.id
)
await add_object_to_db(packticket)

packticket_to_draw = models_raffle.PackTicket(
id=str(uuid.uuid4()), price=1.0, pack_size=1, raffle_id=raffle_to_draw.id
id=str(uuid.uuid4()), price=100, pack_size=1, raffle_id=raffle_to_draw.id
)
await add_object_to_db(packticket_to_draw)

packticket_to_delete = models_raffle.PackTicket(
id=str(uuid.uuid4()), price=1.0, pack_size=1, raffle_id=raffle_to_delete.id
id=str(uuid.uuid4()), price=100, pack_size=1, raffle_id=raffle_to_delete.id
)
await add_object_to_db(packticket_to_delete)

Expand Down Expand Up @@ -127,7 +127,7 @@ async def init_objects():
)
await add_object_to_db(prize_to_draw)

cash = models_raffle.Cash(user_id=student_user.id, balance=66)
cash = models_raffle.Cash(user_id=student_user.id, balance=6600)
await add_object_to_db(cash)


Expand Down Expand Up @@ -270,7 +270,7 @@ def test_get_raffle_stats():
headers={"Authorization": f"Bearer {token}"},
)
assert response.status_code == 200
assert response.json()["amount_raised"] == 1.0
assert response.json()["amount_raised"] == 100


# # tickets
Expand Down Expand Up @@ -377,7 +377,7 @@ def test_create_packtickets():
"/tombola/pack_tickets",
json={
"raffle_id": raffle.id,
"price": 1.23,
"price": 123,
"pack_size": 5,
},
headers={"Authorization": f"Bearer {token}"},
Expand All @@ -392,7 +392,7 @@ def test_edit_packtickets():
f"/tombola/pack_tickets/{packticket.id}",
json={
"raffle_id": raffle.id,
"price": 10.0,
"price": 1000,
"pack_size": 5,
},
headers={"Authorization": f"Bearer {token}"},
Expand Down