55import typing
66from typing import Optional , Iterable , Generator , Any
77
8+ from ayon_api .exceptions import UnsupportedServerVersion
89from ayon_api .utils import (
910 prepare_list_filters ,
1011 create_entity_id ,
@@ -32,9 +33,10 @@ def get_products(
3233 self ,
3334 project_name : str ,
3435 product_ids : Optional [Iterable [str ]] = None ,
35- product_names : Optional [Iterable [str ]]= None ,
36- folder_ids : Optional [Iterable [str ]]= None ,
37- product_types : Optional [Iterable [str ]]= None ,
36+ product_names : Optional [Iterable [str ]] = None ,
37+ folder_ids : Optional [Iterable [str ]] = None ,
38+ product_types : Optional [Iterable [str ]] = None ,
39+ product_base_types : Optional [Iterable [str ]] = None ,
3840 product_name_regex : Optional [str ] = None ,
3941 product_path_regex : Optional [str ] = None ,
4042 names_by_folder_ids : Optional [dict [str , Iterable [str ]]] = None ,
@@ -59,6 +61,8 @@ def get_products(
5961 Use 'None' if folder is direct child of project.
6062 product_types (Optional[Iterable[str]]): Product types used for
6163 filtering.
64+ product_base_types (Optional[Iterable[str]]): Product base types
65+ used for filtering.
6266 product_name_regex (Optional[str]): Filter products by name regex.
6367 product_path_regex (Optional[str]): Filter products by path regex.
6468 Path starts with folder path and ends with product name.
@@ -83,6 +87,11 @@ def get_products(
8387 if not project_name :
8488 return
8589
90+ if product_base_types and not self .is_product_base_type_supported ():
91+ raise UnsupportedServerVersion (
92+ "Product base type is not supported for your server version."
93+ )
94+
8695 # Prepare these filters before 'name_by_filter_ids' filter
8796 filter_product_names = None
8897 if product_names is not None :
@@ -150,6 +159,7 @@ def get_products(
150159 filters ,
151160 ("productIds" , product_ids ),
152161 ("productTypes" , product_types ),
162+ ("productBaseTypes" , product_base_types ),
153163 ("productStatuses" , statuses ),
154164 ("productTags" , tags ),
155165 ):
@@ -378,6 +388,7 @@ def create_product(
378388 tags : Optional [Iterable [str ]] = None ,
379389 status : Optional [str ] = None ,
380390 active : Optional [bool ] = None ,
391+ product_base_type : Optional [str ] = None ,
381392 product_id : Optional [str ] = None ,
382393 ) -> str :
383394 """Create new product.
@@ -392,13 +403,22 @@ def create_product(
392403 tags (Optional[Iterable[str]]): Product tags.
393404 status (Optional[str]): Product status.
394405 active (Optional[bool]): Product active state.
406+ product_base_type (Optional[str]): Product base type.
395407 product_id (Optional[str]): Product id. If not passed new id is
396408 generated.
397409
398410 Returns:
399411 str: Product id.
400412
401413 """
414+ if (
415+ product_base_type is not None
416+ and not self .is_product_base_type_supported ()
417+ ):
418+ raise UnsupportedServerVersion (
419+ "Product base type is not supported for your server version."
420+ )
421+
402422 if not product_id :
403423 product_id = create_entity_id ()
404424 create_data = {
@@ -408,6 +428,7 @@ def create_product(
408428 "folderId" : folder_id ,
409429 }
410430 for key , value in (
431+ ("productBaseType" , product_base_type ),
411432 ("attrib" , attrib ),
412433 ("data" , data ),
413434 ("tags" , tags ),
@@ -431,6 +452,7 @@ def update_product(
431452 name : Optional [str ] = None ,
432453 folder_id : Optional [str ] = None ,
433454 product_type : Optional [str ] = None ,
455+ product_base_type : Optional [str ] = None ,
434456 attrib : Optional [dict [str , Any ]] = None ,
435457 data : Optional [dict [str , Any ]] = None ,
436458 tags : Optional [Iterable [str ]] = None ,
@@ -450,17 +472,27 @@ def update_product(
450472 name (Optional[str]): New product name.
451473 folder_id (Optional[str]): New product id.
452474 product_type (Optional[str]): New product type.
475+ product_base_type (Optional[str]): New product base type.
453476 attrib (Optional[dict[str, Any]]): New product attributes.
454477 data (Optional[dict[str, Any]]): New product data.
455478 tags (Optional[Iterable[str]]): New product tags.
456479 status (Optional[str]): New product status.
457480 active (Optional[bool]): New product active state.
458481
459482 """
483+ if (
484+ product_base_type is not None
485+ and not self .is_product_base_type_supported ()
486+ ):
487+ raise UnsupportedServerVersion (
488+ "Product base type is not supported for your server version."
489+ )
490+
460491 update_data = {}
461492 for key , value in (
462493 ("name" , name ),
463494 ("productType" , product_type ),
495+ ("productBaseType" , product_base_type ),
464496 ("folderId" , folder_id ),
465497 ("attrib" , attrib ),
466498 ("data" , data ),
0 commit comments