diff --git a/core/vendors/__init__.py b/core/vendors/__init__.py index 8441b433..f83627d9 100644 --- a/core/vendors/__init__.py +++ b/core/vendors/__init__.py @@ -34,7 +34,7 @@ from evibes.utils.misc import LogLevel from payments.errors import RatesError from payments.utils import get_rates -async_logger = get_task_logger(__name__) +async_logger = get_task_logger("vendors") logger = logging.getLogger("django") @@ -106,7 +106,6 @@ class AbstractVendor: self.vendor_name = vendor_name self.currency = currency self.blocked_attributes: list[Any] = [] - self.log(LogLevel.INFO, f"Initializing {self}...") def __str__(self) -> str: return self.get_vendor_instance(safe=True).name if self.get_vendor_instance() else self.vendor_name @@ -316,14 +315,18 @@ class AbstractVendor: return round(price, 2) def resolve_price_with_currency(self, price: float | int | Decimal, provider: str, currency: str = "") -> float: + if all([not currency, not self.currency]): + raise ValueError("Currency must be provided.") + if currency == self.currency or currency == settings.CURRENCY_CODE: return float(price) + rates = get_rates(provider) rate = rates.get(currency or self.currency) if rates else 1 if not rate: - raise RatesError(f"No rate found for {currency or self.currency} in {rates} with probider {provider}...") + raise RatesError(f"No rate found for {currency} in {rates} with probider {provider}...") return float(round(price / rate, 2)) if rate else float(round(price, 2)) # type: ignore [arg-type, operator]