Skip to content

Commit

Permalink
chore: add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatasoli committed Oct 6, 2024
1 parent 180f54d commit 47a6bbc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/campaign/repository.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion app/cart/services.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions app/entities/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 3 additions & 0 deletions app/payment/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 47a6bbc

Please sign in to comment.