Feat: Active column changed to add / delete / undelete buttons column on all table pages. \n Fix(UI): Product Permutations page preview Variations now shows when appropriate.

This commit is contained in:
2024-11-11 10:49:55 +00:00
parent 0422059669
commit fe524d6cb8
37 changed files with 165 additions and 274 deletions

View File

@@ -272,11 +272,17 @@ class Product(SQLAlchemy_ABC, Store_Base):
return index_permutation
raise ValueError(f"{av.error_msg_str(id_permutation, 'id_permutation', 'Product.get_index_permutation_from_id', int)}\nPermutation ID not found.")
"""
"""
def add_product_variation(self, variation):
av.val_instance(variation, 'variation', 'Product.add_product_variation', Product_Variation)
# Helper_App.console_log(f'variation: {variation}')
index_permutation = self.permutation_index[variation.id_permutation] # self.get_index_permutation_from_id(variation.id_permutation)
self.permutations[index_permutation].add_product_variation(variation)
"""
def add_product_variation_type(self, variation_type):
variation = variation_type.variations[0]
index_permutation = self.permutation_index[variation.id_permutation]
self.permutations[index_permutation].add_product_variation_type(variation_type)
def add_product_price(self, price):
av.val_instance(price, 'price', 'Product.add_product_price', Product_Price)
index_permutation = self.permutation_index[price.id_permutation] # self.get_index_permutation_from_id(price.id_permutation)

View File

@@ -14,7 +14,8 @@ Business object for product category
import lib.argument_validation as av
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
from business_objects.store.product import Product, Product_Permutation, Product_Price
from business_objects.store.product_variation import Product_Variation
# from business_objects.store.product_variation import Product_Variation
from business_objects.store.product_variation_type import Product_Variation_Type
from business_objects.store.image import Image
from business_objects.store.delivery_option import Delivery_Option
from business_objects.store.discount import Discount
@@ -115,10 +116,17 @@ class Product_Category(SQLAlchemy_ABC, Store_Base):
index_product = self.get_index_product_from_id(permutation.id_product)
# index_product = self.product_index[permutation.id_product]
self.products[index_product].add_product_permutation(permutation)
"""
def add_product_variation(self, variation):
av.val_instance(variation, 'variation', 'Category.add_product_variation', Product_Variation)
index_product = self.get_index_product_from_id(variation.id_product)
self.products[index_product].add_product_variation(variation)
"""
def add_product_variation_type(self, variation_type):
av.val_instance(variation_type, 'variation_type', 'Category.add_product_variation_type', Product_Variation_Type)
variation = variation_type.variations[0]
index_product = self.get_index_product_from_id(variation.id_product)
self.products[index_product].add_product_variation_type(variation_type)
def add_product_price(self, price):
av.val_instance(price, 'price', 'Category.add_product_price', Product_Price)
index_product = self.get_index_product_from_id(price.id_product)
@@ -352,10 +360,17 @@ class Product_Category_Container(Store_Base):
av.val_instance(permutation, 'permutation', 'Container_Product_Categories.add_product_permutation', Product_Permutation)
index_category = self.get_index_category_from_id(permutation.id_category)
self.categories[index_category].add_product_permutation(permutation)
"""
def add_product_variation(self, variation):
av.val_instance(variation, 'variation', 'Container_Product_Categories.add_product_variation', Product_Variation)
index_category = self.get_index_category_from_id(variation.id_category)
self.categories[index_category].add_product_variation(variation)
"""
def add_product_variation_type(self, variation_type):
av.val_instance(variation_type, 'variation_type', 'Container_Product_Categories.add_product_variation_type', Product_Variation_Type)
variation = variation_type.variations[0]
index_category = self.get_index_category_from_id(variation.id_category)
self.categories[index_category].add_product_variation_type(variation_type)
def add_product_price(self, price):
av.val_instance(price, 'price', 'Container_Product_Categories.add_product_price', Product_Price)
index_category = self.get_index_category_from_id(price.id_category)

View File

@@ -302,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_VARIATIONS: [variation_type.to_json() for variation_type in self.variation_tree.get_product_variation_types()],
self.FLAG_PRODUCT_VARIATIONS: [] if self.variation_tree is None else [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],
@@ -395,10 +395,10 @@ class Product_Permutation(db.Model, Store_Base):
price_GBP_full: {self.price_GBP_full}
price_GBP_min: {self.price_GBP_min}
"""
"""
def add_product_variation(self, variation):
_m = 'Product_Permutation.add_product_variation'
"""
""
av.val_instance(variation, 'variation', _m, Product_Variation)
try:
self.variation_index[variation.id_variation]
@@ -406,11 +406,18 @@ class Product_Permutation(db.Model, Store_Base):
except KeyError:
self.variation_index[variation.id_variation] = len(self.variations)
self.variations.append(variation)
"""
""
if self.variation_tree is None:
self.variation_tree = Product_Variation_Tree.from_product_variation(variation)
else:
self.variation_tree.add_product_variation(variation)
"""
def add_product_variation_type(self, variation_type):
_m = 'Product_Permutation.add_product_variation_type'
if self.variation_tree is None:
self.variation_tree = Product_Variation_Tree.from_product_variation_type(variation_type)
else:
self.variation_tree.add_product_variation_type(variation_type)
def add_product_price(self, price):
_m = 'Product_Permutation.add_product_price'
av.val_instance(price, 'price', _m, Product_Price)

View File

@@ -11,6 +11,7 @@ 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
@@ -49,9 +50,9 @@ class Product_Variation_Tree():
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()
my_type_list = self.get_product_variation_types()
sz_me = len(my_type_list)
other_type_list = tree.get_product_variations()
other_type_list = tree.get_product_variation_types()
sz_other = len(other_type_list)
is_equal = (sz_me == sz_other)
if is_equal:
@@ -120,6 +121,7 @@ class Product_Variation_Tree():
types.append(node.variation_type)
node = node.nodes_child[0]
at_leaf_node = node.is_leaf()
types.append(node.variation_type)
return types
"""
def get_product_variations(self):
@@ -140,7 +142,7 @@ class Product_Variation_Tree():
preview_str = ''
for variation_type in variation_types:
is_first = (preview_str == '')
preview_str += f'{variation_type.name}: {variation_type.variations[0].name}'
preview_str += f'{variation_type.name_singular}: {variation_type.variations[0].name}'
if is_first:
preview_str += '\n'
Helper_App.console_log(f'preview_str: {preview_str}')

View File

@@ -30,7 +30,7 @@ from operator import attrgetter
class Product_Variation_Type(db.Model, Store_Base):
NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_PRODUCT_VARIATION_TYPE
NAME_ATTR_OPTION_TEXT = Store_Base.FLAG_NAME_SINGULAR
NAME_ATTR_OPTION_TEXT = Store_Base.FLAG_NAME
id_type = db.Column(db.Integer, primary_key=True)
code = db.Column(db.String(50))