From 47a6bbc82059222a3d3bdd09a1ef0f7ad0c244eb Mon Sep 17 00:00:00 2001 From: Jonatas Oliveira Date: Sun, 6 Oct 2024 15:59:45 +0200 Subject: [PATCH] chore: add logs --- app/campaign/repository.py | 7 +++++-- app/cart/services.py | 6 +++++- app/entities/cart.py | 3 +++ app/payment/services.py | 3 +++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/campaign/repository.py b/app/campaign/repository.py index 21d41c61..bc1e8a0b 100644 --- a/app/campaign/repository.py +++ b/app/campaign/repository.py @@ -1,6 +1,7 @@ from datetime import UTC, datetime from sqlalchemy import select from app.infra.models import CampaignDB +from loguru import logger def get_campaign( @@ -9,10 +10,12 @@ def get_campaign( free_shipping: bool = False, ): """Get campaign.""" + logger.debug('Query Campaign') today = datetime.now(tz=UTC) + logger.debug(f'{today}') query = (select(CampaignDB) - .where(CampaignDB.start_date >= today) - .where(CampaignDB.end_date <= today) + # .where(CampaignDB.start_date >= today) + # .where(CampaignDB.end_date <= today) .where(CampaignDB.active.is_(True)) ) if free_shipping: diff --git a/app/cart/services.py b/app/cart/services.py index 230c03a8..7db49dca 100644 --- a/app/cart/services.py +++ b/app/cart/services.py @@ -1,5 +1,6 @@ # ruff: noqa: PLR1714 from contextlib import suppress +from decimal import Decimal import re from app.campaign import repository as campaign_repository @@ -184,6 +185,7 @@ def calculate_freight( ) -> CartBase: """Calculate Freight.""" with session.begin() as transaction: + logger.debug("Search campaign") campaign = campaign_repository.get_campaign( free_shipping=True, transaction=transaction, @@ -206,8 +208,10 @@ def calculate_freight( freight_package=freight_package, zipcode=cart.zipcode, ) + logger.debug(f'Campaign: {campaign}') if campaign and cart.subtotal > campaign.min_purchase_value: - freight.price = 0 + logger.debug('Campaign') + freight.price = Decimal(0.01) cart.freight = freight return cart diff --git a/app/entities/cart.py b/app/entities/cart.py index 5253d137..d9459ad2 100644 --- a/app/entities/cart.py +++ b/app/entities/cart.py @@ -186,7 +186,10 @@ def calculate_subtotal( raise CouponLimitPriceError self.discount = coupon.discount_price self.subtotal = subtotal - self.discount + logger.debug(f'Frete {self.freight}') + logger.debug(f'Preco {self.freight.price}') if self.freight and self.freight.price >= 0: + logger.debug('Sum freight') self.total = (subtotal + self.freight.price) - self.discount except TypeError as err: logger.error('Price or quantity not found in cart item') diff --git a/app/payment/services.py b/app/payment/services.py index 8ae01a4e..6b80c73d 100644 --- a/app/payment/services.py +++ b/app/payment/services.py @@ -18,12 +18,14 @@ async def update_payment( ) -> None: """Update payment.""" order_id, user = None, None + logger.debug(f'Data Payment {payment_data}') payment = bootstrap.payment.get_payment_status( payment_id=payment_data.data.id, payment_gateway='MERCADOPAGO', ) logger.info(f'Gateway {payment}') logger.info(f'Status {payment["status"]}') + payment_db = None async with bootstrap.db().begin() as session: payment_db = await bootstrap.payment_repository.update_payment_status( payment_data.data.id, @@ -39,6 +41,7 @@ async def update_payment( ) order_id = payment_db[0].order_id if payment['status'] == 'approved' or payment['status'] == 'authorized': + logger.debug(f'PAyment DB {payment_db}') await report_repository.update_payment_commissions( paid_status=True, payment_id=payment_db.payment_id,