Features: 1) Add optional currency parameter to resolve_price_with_currency for enhanced flexibility;
Fixes: 1) Address minor spacing inconsistencies in list comprehension and JSON detection logic; Extra: 1) Update `.gitignore` to exclude `.astro/` directory.
This commit is contained in:
parent
b105561c10
commit
6ce7b7a6f9
2 changed files with 8 additions and 5 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -64,6 +64,9 @@ htmlcov/
|
|||
.cover
|
||||
.pybuilder/
|
||||
|
||||
# Astro
|
||||
.astro/
|
||||
|
||||
# Celery
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
|
|
|||
8
core/vendors/__init__.py
vendored
8
core/vendors/__init__.py
vendored
|
|
@ -37,7 +37,7 @@ class AbstractVendor:
|
|||
if total == 0:
|
||||
return []
|
||||
chunk_size = max(1, (total + num_chunks - 1) // num_chunks)
|
||||
return [data[i : i + chunk_size] for i in range(0, total, chunk_size)]
|
||||
return [data[i: i + chunk_size] for i in range(0, total, chunk_size)]
|
||||
|
||||
@staticmethod
|
||||
def auto_convert_value(value):
|
||||
|
|
@ -162,13 +162,13 @@ class AbstractVendor:
|
|||
|
||||
return round(price, 2)
|
||||
|
||||
def resolve_price_with_currency(self, price, provider):
|
||||
def resolve_price_with_currency(self, price, provider, currency=None):
|
||||
rates = get_rates(provider)
|
||||
|
||||
rate = rates.get(self.currency)
|
||||
rate = rates.get(currency or self.currency)
|
||||
|
||||
if not rate:
|
||||
raise RatesError(f"No rate found for {self.currency} in {rates} with probider {provider}...")
|
||||
raise RatesError(f"No rate found for {currency or self.currency} in {rates} with probider {provider}...")
|
||||
|
||||
return round(price / rate, 2) if rate else round(price, 2)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue