Features: 1) Add method parameter to prepare_for_stock_update to support multiple actions (deactivate, delete, update description);
Fixes: None; Extra: 1) Add `QuerySet` import to support type hinting; 2) Improve error handling with descriptive `ValueError` for invalid method.
This commit is contained in:
parent
3020a40747
commit
61033a58d6
1 changed files with 12 additions and 2 deletions
14
core/vendors/__init__.py
vendored
14
core/vendors/__init__.py
vendored
|
|
@ -283,8 +283,18 @@ class AbstractVendor:
|
||||||
product__in=self.get_products_queryset(), product__orderproduct__isnull=True
|
product__in=self.get_products_queryset(), product__orderproduct__isnull=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def prepare_for_stock_update(self):
|
def prepare_for_stock_update(self, method: str = "deactivate") -> None:
|
||||||
self.get_products_queryset().update(is_active=False)
|
products = self.get_products_queryset()
|
||||||
|
|
||||||
|
match method:
|
||||||
|
case "deactivate":
|
||||||
|
products.update(is_active=False)
|
||||||
|
case "delete":
|
||||||
|
products.delete()
|
||||||
|
case "description":
|
||||||
|
products.update(description="EVIBES_DELETED_PRODUCT")
|
||||||
|
case _:
|
||||||
|
raise ValueError(f"Invalid method {method!r} for stock update...")
|
||||||
|
|
||||||
def delete_inactives(self):
|
def delete_inactives(self):
|
||||||
self.get_products_queryset().filter(is_active=False).delete()
|
self.get_products_queryset().filter(is_active=False).delete()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue