Features: 1) Introduce VendorInactiveError for explicitly handling inactive vendors in core/vendors; 2) Update stock update process to skip inactive vendors and log warnings.
Fixes: 1) Add missing import for `VendorInactiveError` in `core/tasks.py`. Extra: 1) Refactor exception handling for vendor stock updates for better readability.
This commit is contained in:
parent
dbc135aea0
commit
75709a3aa1
2 changed files with 10 additions and 7 deletions
|
|
@ -13,7 +13,7 @@ from django.core.cache import cache
|
||||||
|
|
||||||
from core.models import Product, Promotion
|
from core.models import Product, Promotion
|
||||||
from core.utils.caching import set_default_cache
|
from core.utils.caching import set_default_cache
|
||||||
from core.vendors import delete_stale
|
from core.vendors import delete_stale, VendorInactiveError
|
||||||
from evibes.settings import MEDIA_ROOT
|
from evibes.settings import MEDIA_ROOT
|
||||||
|
|
||||||
logger = get_task_logger(__name__)
|
logger = get_task_logger(__name__)
|
||||||
|
|
@ -43,11 +43,9 @@ def update_products_task():
|
||||||
for vendor_class in vendors_classes:
|
for vendor_class in vendors_classes:
|
||||||
vendor = vendor_class()
|
vendor = vendor_class()
|
||||||
try:
|
try:
|
||||||
vendor_instance = vendor.get_vendor_instance()
|
vendor.update_stock()
|
||||||
if vendor_instance.is_active:
|
except VendorInactiveError as vie:
|
||||||
vendor.update_stock()
|
logger.warning(f"Skipping {vendor_class} due to error: {vie!s}")
|
||||||
else:
|
|
||||||
continue
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Skipping {vendor_class} due to error: {e!s}")
|
logger.warning(f"Skipping {vendor_class} due to error: {e!s}")
|
||||||
|
|
||||||
|
|
|
||||||
7
core/vendors/__init__.py
vendored
7
core/vendors/__init__.py
vendored
|
|
@ -59,6 +59,11 @@ class VendorError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class VendorInactiveError(VendorError):
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AbstractVendor:
|
class AbstractVendor:
|
||||||
"""
|
"""
|
||||||
Abstract class defining vendor-related operations and handling.
|
Abstract class defining vendor-related operations and handling.
|
||||||
|
|
@ -270,7 +275,7 @@ class AbstractVendor:
|
||||||
vendor = Vendor.objects.get(name=self.vendor_name)
|
vendor = Vendor.objects.get(name=self.vendor_name)
|
||||||
if vendor.is_active:
|
if vendor.is_active:
|
||||||
return vendor
|
return vendor
|
||||||
raise VendorError(f"Vendor {self.vendor_name!r} is inactive...")
|
raise VendorInactiveError(f"Vendor {self.vendor_name!r} is inactive...")
|
||||||
except Vendor.DoesNotExist as dne:
|
except Vendor.DoesNotExist as dne:
|
||||||
raise Exception(f"No matching vendor found with name {self.vendor_name!r}...") from dne
|
raise Exception(f"No matching vendor found with name {self.vendor_name!r}...") from dne
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue