Feat: Product Variations page get, filter, and save. \n Fix: Active column changed to Add / Delete / Undelete column - this change has only been applied to Product Variations page
This commit is contained in:
Binary file not shown.
@@ -69,6 +69,9 @@ class Base():
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = 'name-attribute-option-text'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = 'name-attribute-option-value'
|
||||
"""
|
||||
def __repr__(self):
|
||||
attrs = '\n'.join(f'{k}={v!r}' for k, v in self.__dict__.items())
|
||||
return f'<{self.__class__.__name__}(\n{attrs}\n)>'
|
||||
|
||||
@classmethod
|
||||
def output_bool(cls, value):
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -119,8 +119,6 @@ class Product_Permutation(db.Model, Store_Base):
|
||||
# variation_tree
|
||||
|
||||
def __init__(self):
|
||||
self.variations = []
|
||||
self.variation_index = {}
|
||||
self.prices = []
|
||||
self.price_index = {}
|
||||
self.images = []
|
||||
@@ -139,6 +137,7 @@ class Product_Permutation(db.Model, Store_Base):
|
||||
self.is_unavailable_in_currency_or_region = False
|
||||
# self.is_available = False
|
||||
self.variation_tree = None
|
||||
# self.variations = []
|
||||
@classmethod
|
||||
def from_DB_get_many_product_catalogue(cls, query_row):
|
||||
_m = f'{cls.__name__}.from_DB_get_many_product_catalogue'
|
||||
@@ -303,7 +302,7 @@ class Product_Permutation(db.Model, Store_Base):
|
||||
self.FLAG_CAN_VIEW: self.can_view,
|
||||
self.FLAG_CAN_EDIT: self.can_edit,
|
||||
self.FLAG_CAN_ADMIN: self.can_admin,
|
||||
self.FLAG_PRODUCT_VARIATION: [variation.to_json() for variation in self.variations],
|
||||
self.FLAG_PRODUCT_VARIATIONS: [variation_type.to_json() for variation_type in self.variation_tree.get_product_variation_types()],
|
||||
self.FLAG_PRODUCT_IMAGE: [image.to_json() for image in self.images],
|
||||
self.FLAG_DELIVERY_OPTION: [option.to_json() for option in self.delivery_options],
|
||||
self.FLAG_PRODUCT_PRICE: [price.to_json() for price in self.prices],
|
||||
@@ -341,13 +340,13 @@ class Product_Permutation(db.Model, Store_Base):
|
||||
return f'{price.symbol_currency} {locale.format_string("%d", price.value_local_VAT_incl, grouping=True)}'
|
||||
else:
|
||||
return f'{price.symbol_currency} {locale.format_string("%d", price.value_local_VAT_excl, grouping=True)}'
|
||||
"""
|
||||
def output_variations(self):
|
||||
if not self.has_variations: return ''
|
||||
return '\n'.join([f'{variation.name_variation_type}: {variation.name_variation}' for variation in self.variations])
|
||||
def output_variations_jsonify(self):
|
||||
if not self.has_variations: return ''
|
||||
return ','.join([f'{variation.id_type}: {variation.id_variation}' for variation in self.variations])
|
||||
"""
|
||||
|
||||
def __repr__(self):
|
||||
return f'''Product_Permutation
|
||||
@@ -387,7 +386,7 @@ class Product_Permutation(db.Model, Store_Base):
|
||||
can_view: {self.can_view}
|
||||
can_edit: {self.can_edit}
|
||||
can_admin: {self.can_admin}
|
||||
variations: {self.variations}
|
||||
variation tree: {self.variation_tree}
|
||||
images: {self.images}
|
||||
delivery_options: {self.delivery_options}
|
||||
prices: {self.prices}
|
||||
|
||||
@@ -18,8 +18,9 @@ Business object for product variation
|
||||
# IMPORTS
|
||||
# internal
|
||||
import lib.argument_validation as av
|
||||
from business_objects.db_base import Get_Many_Parameters_Base
|
||||
from business_objects.store.store_base import Store_Base
|
||||
from business_objects.store.product_variation_type import Product_Variation_Type
|
||||
# from business_objects.store.product_variation_type import Product_Variation_Type
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
@@ -55,7 +56,7 @@ class Product_Variation(db.Model, Store_Base):
|
||||
variation.id_product = query_row[11]
|
||||
variation.id_permutation = query_row[12]
|
||||
variation.id_category = query_row[13]
|
||||
variation.variation_type = Product_Variation_Type.from_DB_get_many_product_catalogue(query_row)
|
||||
# variation.variation_type = Product_Variation_Type.from_DB_get_many_product_catalogue(query_row)
|
||||
return variation
|
||||
|
||||
@classmethod
|
||||
@@ -73,13 +74,14 @@ class Product_Variation(db.Model, Store_Base):
|
||||
def from_json(cls, json):
|
||||
variation = cls()
|
||||
variation.id_variation = json[cls.ATTR_ID_PRODUCT_VARIATION]
|
||||
variation.id_type = json[cls.ATTR_ID_PRODUCT_VARIATION_TYPE]
|
||||
variation.code = json[cls.FLAG_CODE]
|
||||
variation.name = json[cls.FLAG_NAME]
|
||||
variation.display_order = json[cls.FLAG_DISPLAY_ORDER]
|
||||
variation.active = json[cls.FLAG_ACTIVE]
|
||||
variation.id_permutation = json[cls.ATTR_ID_PRODUCT_PERMUTATION]
|
||||
variation.id_product = json[cls.ATTR_ID_PRODUCT]
|
||||
variation.id_category = json[cls.ATTR_ID_PRODUCT_CATEGORY]
|
||||
variation.active = 1 if av.input_bool(json[cls.FLAG_ACTIVE], cls.FLAG_ACTIVE, f'{cls.__name__}.from_json') else 0
|
||||
variation.id_permutation = json.get(cls.ATTR_ID_PRODUCT_PERMUTATION, None)
|
||||
variation.id_product = json.get(cls.ATTR_ID_PRODUCT, None)
|
||||
variation.id_category = json.get(cls.ATTR_ID_PRODUCT_CATEGORY, None)
|
||||
return variation
|
||||
|
||||
def __repr__(self):
|
||||
@@ -116,7 +118,7 @@ class Product_Variation(db.Model, Store_Base):
|
||||
'text': self.name
|
||||
}
|
||||
|
||||
|
||||
"""
|
||||
@dataclass
|
||||
class Product_Variation_Filters():
|
||||
get_all_variation_type: bool
|
||||
@@ -140,7 +142,7 @@ class Product_Variation_Filters():
|
||||
'a_ids_variation': self.ids_variation,
|
||||
|
||||
}
|
||||
"""
|
||||
""
|
||||
@staticmethod
|
||||
def from_form(form):
|
||||
av.val_instance(form, 'form', 'User_Filters.from_form', Filters_Product_Variation)
|
||||
@@ -164,7 +166,7 @@ class Product_Variation_Filters():
|
||||
ids_user = user.id_user,
|
||||
ids_user_auth0 = user.id_user_auth0,
|
||||
)
|
||||
"""
|
||||
""
|
||||
|
||||
@staticmethod
|
||||
def get_default():
|
||||
@@ -178,8 +180,35 @@ class Product_Variation_Filters():
|
||||
# get_first_variation = False,
|
||||
ids_variation = ''
|
||||
)
|
||||
"""
|
||||
class Parameters_Product_Variation(Get_Many_Parameters_Base):
|
||||
a_get_all_variation_type: bool
|
||||
a_get_inactive_variation_type: bool
|
||||
a_ids_variation_type: str
|
||||
a_get_all_variation: bool
|
||||
a_get_inactive_variation: bool
|
||||
a_ids_variation: str
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@classmethod
|
||||
def get_default(cls):
|
||||
return cls(
|
||||
a_get_all_variation_type = True,
|
||||
a_get_inactive_variation_type = False,
|
||||
a_ids_variation_type = '',
|
||||
a_get_all_variation = True,
|
||||
a_get_inactive_variation = False,
|
||||
a_ids_variation = ''
|
||||
)
|
||||
@classmethod
|
||||
def from_filters_product_variation(cls, form):
|
||||
parameters = cls.get_default()
|
||||
get_inactive = not form.active.data
|
||||
parameters.a_get_inactive_variation_type = get_inactive
|
||||
parameters.a_get_inactive_variation = get_inactive
|
||||
return parameters
|
||||
|
||||
|
||||
"""
|
||||
class Product_Variation_Container(BaseModel):
|
||||
variation_types: list = []
|
||||
variations: list = []
|
||||
@@ -209,4 +238,43 @@ class Product_Variation_Container(BaseModel):
|
||||
for variation_type in self.variation_types:
|
||||
list_variation_types.append(variation_type.to_json_option())
|
||||
return list_variation_types
|
||||
|
||||
"""
|
||||
|
||||
class Product_Variation_Temp(db.Model, Store_Base):
|
||||
__tablename__ = 'Shop_Variation_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp: int = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
id_variation: int = db.Column(db.Integer) # , primary_key=True)
|
||||
id_type: int = db.Column(db.Integer, nullable=False)
|
||||
code: str = db.Column(db.String(50))
|
||||
name: str = db.Column(db.String(255))
|
||||
active: bool = db.Column(db.Boolean)
|
||||
display_order: int = db.Column(db.Integer)
|
||||
guid: str = db.Column(db.String(36))
|
||||
|
||||
def __repr__(self):
|
||||
attrs = '\n'.join(f'{k}={v!r}' for k, v in self.__dict__.items())
|
||||
return f'<{self.__class__.__name__}(\n{attrs}\n)>'
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.id_temp = None
|
||||
@classmethod
|
||||
def from_product_variation(cls, product_variation):
|
||||
row = cls()
|
||||
row.id_variation = product_variation.id_variation
|
||||
row.id_type = product_variation.id_type
|
||||
row.code = product_variation.code
|
||||
row.name = product_variation.name
|
||||
row.active = 1 if av.input_bool(product_variation.active, cls.FLAG_ACTIVE, f'{cls.__name__}.to_json') else 0
|
||||
row.display_order = product_variation.display_order
|
||||
return row
|
||||
def to_json(self):
|
||||
return {
|
||||
'id_variation': self.id_variation,
|
||||
'id_type': self.id_type,
|
||||
'code': self.code,
|
||||
'name': self.name,
|
||||
'active': self.active,
|
||||
'display_order': self.display_order,
|
||||
'guid': self.guid,
|
||||
}
|
||||
@@ -11,21 +11,21 @@ Business object for product
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.store.product_variation import Product_Variation
|
||||
from business_objects.store.product_variation_type import Product_Variation_Type
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
|
||||
|
||||
class Product_Variation_Tree_Node():
|
||||
variation: Product_Variation
|
||||
variation_type: Product_Variation_Type
|
||||
node_parent: None
|
||||
nodes_child: list
|
||||
def __init__(self):
|
||||
self.nodes_child = []
|
||||
def from_variation_and_node_parent(variation, node_parent):
|
||||
def from_variation_type_and_node_parent(variation_type, node_parent):
|
||||
node = Product_Variation_Tree_Node()
|
||||
node.variation = variation
|
||||
node.variation_type = variation_type
|
||||
node.node_parent = node_parent
|
||||
return node
|
||||
def from_node_parent(node_parent):
|
||||
@@ -45,8 +45,8 @@ class Product_Variation_Tree():
|
||||
tree.node_root = node_root
|
||||
return tree
|
||||
@classmethod
|
||||
def from_variation_root(cls, variation_root):
|
||||
node_root = Product_Variation_Tree_Node.from_variation_and_node_parent(variation_root, None)
|
||||
def from_variation_type_root(cls, variation_type_root):
|
||||
node_root = Product_Variation_Tree_Node.from_variation_type_and_node_parent(variation_type_root, None)
|
||||
return cls.from_node_root(node_root)
|
||||
def is_equal(self, tree):
|
||||
my_type_list = self.get_product_variations()
|
||||
@@ -56,53 +56,51 @@ class Product_Variation_Tree():
|
||||
is_equal = (sz_me == sz_other)
|
||||
if is_equal:
|
||||
for index_type in range(sz_me):
|
||||
if my_type_list[index_type] != other_type_list[index_type]:
|
||||
my_variation_type = my_type_list[index_type]
|
||||
other_variation_type = other_type_list[index_type]
|
||||
if my_variation_type.id_type != other_variation_type.id_type:
|
||||
is_equal = False
|
||||
break
|
||||
my_variation = my_variation_type.variations[0]
|
||||
other_variation = other_variation_type.variations[0]
|
||||
if my_variation.id_variation != other_variation.id_variation:
|
||||
is_equal = False
|
||||
break
|
||||
return is_equal
|
||||
@classmethod
|
||||
def from_product_permutation(cls, product_permutation):
|
||||
depth_max = len(product_permutation.variations)
|
||||
node_root = Product_Variation_Tree_Node.from_variation_and_node_parent(product_permutation.variations[0], None)
|
||||
depth_max = len(product_permutation.variation_types)
|
||||
node_root = Product_Variation_Tree_Node.from_variation_type_and_node_parent(product_permutation.variation_types[0], None)
|
||||
node = node_root
|
||||
for depth in range(depth_max - 1):
|
||||
node = Product_Variation_Tree_Node.from_variation_and_node_parent(product_permutation.variations[depth + 1], node)
|
||||
node = Product_Variation_Tree_Node.from_variation_type_and_node_parent(product_permutation.variation_types[depth + 1], node)
|
||||
return cls.from_node_root(node_root)
|
||||
@classmethod
|
||||
def from_product_variation(cls, product_variation):
|
||||
node_root = Product_Variation_Tree_Node.from_variation_and_node_parent(product_variation, None)
|
||||
def from_product_variation_type(cls, product_variation_type):
|
||||
node_root = Product_Variation_Tree_Node.from_variation_type_and_node_parent(product_variation_type, None)
|
||||
return cls.from_node_root(node_root)
|
||||
@classmethod
|
||||
def from_product_variations(cls, product_variations):
|
||||
node_root = Product_Variation_Tree_Node.from_variation_and_node_parent(product_variations[0], None)
|
||||
def from_product_variation_types(cls, product_variation_types):
|
||||
node_root = Product_Variation_Tree_Node.from_variation_type_and_node_parent(product_variation_types[0], None)
|
||||
tree = cls.from_node_root(node_root)
|
||||
if len(product_variations) > 1:
|
||||
for variation in product_variations[1:]:
|
||||
tree.add_product_variation(variation)
|
||||
if len(product_variation_types) > 1:
|
||||
for variation_type in product_variation_types[1:]:
|
||||
tree.add_product_variation_type(variation_type)
|
||||
return tree
|
||||
@classmethod
|
||||
def from_json_str(cls, json_str):
|
||||
variations = []
|
||||
variation_types = []
|
||||
if json_str is None or json_str == '': return None
|
||||
for json_variation in json_str.split(','):
|
||||
parts = json_variation.split(':')
|
||||
for json_variation_type in json_str.split(','):
|
||||
parts = json_variation_type.split(':')
|
||||
if len(parts) != 2: continue
|
||||
variation_type = Product_Variation_Type()
|
||||
variation_type.id_type = parts[0]
|
||||
variation = Product_Variation()
|
||||
variation.id_type = parts[0]
|
||||
variation.id_variation = parts[1]
|
||||
variations.append(variation)
|
||||
return cls.from_product_variations(variations)
|
||||
"""
|
||||
def get_name_variations(self):
|
||||
node = self.node_root
|
||||
name = node.variation.name_variation_type
|
||||
at_leaf_node = node.is_leaf()
|
||||
while not at_leaf_node:
|
||||
node = node.nodes_child[0]
|
||||
name += f', {node.variation.name_variation_type}'
|
||||
at_leaf_node = node.is_leaf()
|
||||
return name
|
||||
"""
|
||||
variation_type.id_variation = parts[1]
|
||||
variation_type.variations = [variation]
|
||||
variation_types.append(variation_type)
|
||||
return cls.from_product_variation_types(variation_types)
|
||||
def get_node_leaf(self):
|
||||
node = self.node_root
|
||||
at_leaf_node = node.is_leaf()
|
||||
@@ -110,19 +108,20 @@ class Product_Variation_Tree():
|
||||
node = node.nodes_child[0]
|
||||
at_leaf_node = node.is_leaf()
|
||||
return node
|
||||
def add_product_variation(self, variation):
|
||||
def add_product_variation_type(self, variation_type):
|
||||
node_leaf = self.get_node_leaf()
|
||||
node_new = Product_Variation_Tree_Node.from_variation_and_node_parent(variation, node_leaf)
|
||||
node_new = Product_Variation_Tree_Node.from_variation_type_and_node_parent(variation_type, node_leaf)
|
||||
node_leaf.add_child(node_new)
|
||||
def get_product_variation_types(self):
|
||||
types = []
|
||||
node = self.node_root
|
||||
at_leaf_node = node.is_leaf()
|
||||
while not at_leaf_node:
|
||||
types.append(node.variation.name_variation_type)
|
||||
types.append(node.variation_type)
|
||||
node = node.nodes_child[0]
|
||||
at_leaf_node = node.is_leaf()
|
||||
return types
|
||||
"""
|
||||
def get_product_variations(self):
|
||||
variations = []
|
||||
node = self.node_root
|
||||
@@ -133,58 +132,28 @@ class Product_Variation_Tree():
|
||||
at_leaf_node = node.is_leaf()
|
||||
variations.append(node.variation)
|
||||
return variations
|
||||
"""
|
||||
def to_preview_str(self):
|
||||
Helper_App.console_log(f'Product_Variation_Tree.to_preview_str')
|
||||
variations = self.get_product_variations()
|
||||
Helper_App.console_log(f'variations: {variations}')
|
||||
variation_types = self.get_product_variation_types()
|
||||
Helper_App.console_log(f'variation_types: {variation_types}')
|
||||
preview_str = ''
|
||||
for variation in variations:
|
||||
for variation_type in variation_types:
|
||||
is_first = (preview_str == '')
|
||||
preview_str += f'{variation.variation_type.name_singular}: {variation.name}'
|
||||
preview_str += f'{variation_type.name}: {variation_type.variations[0].name}'
|
||||
if is_first:
|
||||
preview_str += '\n'
|
||||
Helper_App.console_log(f'preview_str: {preview_str}')
|
||||
return preview_str
|
||||
def to_json(self):
|
||||
variations = self.get_product_variations()
|
||||
json_variations = []
|
||||
for variation in variations:
|
||||
json_variations.append(variation.to_json())
|
||||
return json_variations
|
||||
variation_types = self.get_product_variation_types()
|
||||
json_variation_types = []
|
||||
for variation_type in variation_types:
|
||||
json_variation_types.append(variation_type.to_json())
|
||||
return json_variation_types
|
||||
def to_variation_id_pairs_str(self):
|
||||
variations = self.get_product_variations()
|
||||
variation_types = self.get_product_variation_types()
|
||||
pairs_str = ''
|
||||
for variation in variations:
|
||||
pairs_str += f'{variation.id_type}:{variation.id_variation},'
|
||||
return pairs_str
|
||||
"""
|
||||
class Product_Variation_Container(BaseModel):
|
||||
variation_types: list = []
|
||||
variations: list = []
|
||||
|
||||
def add_product_variation_type(self, variation_type):
|
||||
av.val_instance(variation_type, 'variation_type', 'Product_Variation_Container.add_product_variation_type', Product_Variation_Type)
|
||||
self.variations.append(variation_type)
|
||||
def add_product_variation(self, variation):
|
||||
av.val_instance(variation, 'variation', 'Product_Variation_Container.add_product_variation', Product_Variation)
|
||||
if variation.variation_type is None:
|
||||
variation_type = next(filterfalse(lambda x: x.id_type != variation.id_type, self.variation_types), None)
|
||||
if variation_type is not None:
|
||||
variation.variation_type = variation_type
|
||||
self.variations.append(variation)
|
||||
|
||||
def __repr__(self):
|
||||
return f'Product_Variation_Container:\nvariations_types: {self.variation_types}\nvariations: {self.variations}'
|
||||
|
||||
def to_list_variation_options(self):
|
||||
list_variations = []
|
||||
for variation in self.variations:
|
||||
list_variations.append(variation.to_json_option())
|
||||
Helper_App.console_log(f'list_variations: {list_variations}')
|
||||
return list_variations
|
||||
def to_list_variation_type_options(self):
|
||||
list_variation_types = []
|
||||
for variation_type in self.variation_types:
|
||||
list_variation_types.append(variation_type.to_json_option())
|
||||
return list_variation_types
|
||||
"""
|
||||
for variation_type in variation_types:
|
||||
pairs_str += f'{variation_type.id_type}:{variation_type.variations[0].id_variation},'
|
||||
return pairs_str
|
||||
@@ -18,6 +18,7 @@ Business object for product variation
|
||||
# IMPORTS
|
||||
# internal
|
||||
import lib.argument_validation as av
|
||||
from business_objects.store.product_variation import Product_Variation
|
||||
from business_objects.store.store_base import Store_Base
|
||||
from extensions import db
|
||||
# external
|
||||
@@ -40,7 +41,8 @@ class Product_Variation_Type(db.Model, Store_Base):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.variations = []
|
||||
|
||||
@classmethod
|
||||
def from_DB_get_many_product_catalogue(cls, query_row):
|
||||
variation_type = cls()
|
||||
@@ -50,6 +52,7 @@ class Product_Variation_Type(db.Model, Store_Base):
|
||||
variation_type.name_plural = query_row[8]
|
||||
variation_type.display_order = query_row[9]
|
||||
variation_type.active = av.input_bool(query_row[10], cls.FLAG_ACTIVE, f'{cls.__name__}.from_DB_get_many_product_catalogue')
|
||||
variation_type.variations = [Product_Variation.from_DB_get_many_product_catalogue(query_row)]
|
||||
return variation_type
|
||||
|
||||
@classmethod
|
||||
@@ -68,10 +71,13 @@ class Product_Variation_Type(db.Model, Store_Base):
|
||||
variation_type = cls()
|
||||
variation_type.id_type = json[cls.ATTR_ID_PRODUCT_VARIATION_TYPE]
|
||||
variation_type.code = json[cls.FLAG_CODE]
|
||||
variation_type.name_singular = json[cls.FLAG_NAME_SINGULAR]
|
||||
variation_type.name_singular = json.get(cls.FLAG_NAME_SINGULAR, json.get(cls.FLAG_NAME, ''))
|
||||
variation_type.name_plural = json[cls.FLAG_NAME_PLURAL]
|
||||
variation_type.display_order = json[cls.FLAG_DISPLAY_ORDER]
|
||||
variation_type.active = json[cls.FLAG_ACTIVE]
|
||||
variations = json.get(cls.FLAG_PRODUCT_VARIATIONS, [])
|
||||
if variations is not None and len(variations) > 0:
|
||||
variation_type.variations = [Product_Variation.from_json(variation) for variation in variations]
|
||||
return variation_type
|
||||
|
||||
def __repr__(self):
|
||||
@@ -90,14 +96,74 @@ class Product_Variation_Type(db.Model, Store_Base):
|
||||
**self.get_shared_json_attributes(self),
|
||||
self.ATTR_ID_PRODUCT_VARIATION_TYPE: self.id_type,
|
||||
self.FLAG_CODE: self.code,
|
||||
self.FLAG_NAME_SINGULAR: self.name_singular,
|
||||
self.FLAG_NAME: self.name_singular,
|
||||
self.FLAG_NAME_PLURAL: self.name_plural,
|
||||
self.FLAG_DISPLAY_ORDER: self.display_order,
|
||||
self.FLAG_ACTIVE: self.active,
|
||||
self.FLAG_PRODUCT_VARIATIONS: [variation.to_json() for variation in self.variations]
|
||||
}
|
||||
def to_json_option(self):
|
||||
return {
|
||||
'value': self.id_type,
|
||||
'text': self.name_singular
|
||||
}
|
||||
"""
|
||||
def get_preview_variations(self):
|
||||
preview = ''
|
||||
if len(self.variations) > 0:
|
||||
# preview = '\n'.join([variation.name for variation in self.variations])
|
||||
preview = '<p>' + '</p><p>'.join([variation.name for variation in self.variations]) + '</p>'
|
||||
return preview
|
||||
def get_str_list_ids_variation(self):
|
||||
if self.variations is None or len(self.variations) == 0:
|
||||
return ''
|
||||
return ','.join([str(variation.id_variation) for variation in self.variations])
|
||||
"""
|
||||
|
||||
class Product_Variation_Type_Temp(db.Model, Store_Base):
|
||||
__tablename__ = 'Shop_Variation_Type_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp: int = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
id_type: int = db.Column(db.Integer)
|
||||
code: str = db.Column(db.String(50))
|
||||
name: str = db.Column(db.String(255))
|
||||
name_plural: str = db.Column(db.String(256))
|
||||
active: bool = db.Column(db.Boolean)
|
||||
display_order: int = db.Column(db.Integer)
|
||||
guid: str = db.Column(db.String(36))
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.id_temp = None
|
||||
@classmethod
|
||||
def from_product_variation_type(cls, product_variation_type):
|
||||
row = cls()
|
||||
row.id_type = product_variation_type.id_type
|
||||
row.code = product_variation_type.code
|
||||
row.name = product_variation_type.name_singular
|
||||
row.name_plural = product_variation_type.name_plural
|
||||
row.active = 1 if av.input_bool(product_variation_type.active, cls.FLAG_ACTIVE, f'{cls.__name__}.from_product_variation_type') else 0
|
||||
row.display_order = product_variation_type.display_order
|
||||
return row
|
||||
def to_json(self):
|
||||
return {
|
||||
'id_type': self.id_type,
|
||||
'code': self.code,
|
||||
'name': self.name,
|
||||
'name_plural': self.name_plural,
|
||||
'active': self.active,
|
||||
'display_order': self.display_order,
|
||||
'guid': self.guid,
|
||||
}
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}
|
||||
id_temp: {self.id_temp}
|
||||
id_type: {self.id_type}
|
||||
code: {self.code}
|
||||
name: {self.name}
|
||||
name_plural: {self.name_plural}
|
||||
active: {self.active}
|
||||
display_order: {self.display_order}
|
||||
guid: {self.guid}
|
||||
'''
|
||||
Reference in New Issue
Block a user