feat(MySQL): Get Many stored procedures created for product variations with variation types and product prices with discounts and delivery options.
This commit is contained in:
Binary file not shown.
@@ -23,12 +23,12 @@ from sqlalchemy.ext.declarative import DeclarativeMeta
|
||||
|
||||
|
||||
class Get_Many_Parameters_Base(BaseModel, metaclass=ABCMeta):
|
||||
a_id_user: int
|
||||
def __init__(self, a_id_user, **kwargs):
|
||||
super().__init__(a_id_user=a_id_user, **kwargs)
|
||||
# a_id_user: int
|
||||
def __init__(self, **kwargs): # , a_id_user
|
||||
super().__init__(**kwargs) # a_id_user=a_id_user,
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def get_default(cls, id_user):
|
||||
def get_default(cls): # , id_user
|
||||
pass
|
||||
"""
|
||||
@abstractmethod
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -19,7 +19,7 @@ Business object for basket
|
||||
# internal
|
||||
import lib.argument_validation as av
|
||||
# from lib import data_types
|
||||
from business_objects.store.product import Product #, Filters_Product
|
||||
from business_objects.store.product import Product #, Parameters_Product
|
||||
from business_objects.store.discount import Discount
|
||||
from business_objects.store.delivery_option import Delivery_Option
|
||||
from business_objects.store.store_base import Store_Base
|
||||
|
||||
@@ -112,7 +112,7 @@ class Product_Image_Filters():
|
||||
|
||||
def __new__(cls, product_id, get_thumbnail, get_remaining_LQ):
|
||||
# Initialiser - validation
|
||||
_m = 'Filters_Product.__new__'
|
||||
_m = 'Parameters_Product.__new__'
|
||||
v_arg_type = 'class attribute'
|
||||
av.val_int(product_id, 'product_id', _m, v_arg_type=v_arg_type)
|
||||
av.val_bool(get_thumbnail, 'get_thumbnail', _m, v_arg_type=v_arg_type)
|
||||
|
||||
@@ -27,7 +27,7 @@ from business_objects.store.product_variation import Product_Variation
|
||||
from business_objects.store.product_variation_tree import Product_Variation_Tree
|
||||
from extensions import db
|
||||
from forms.base import Form_Base
|
||||
from forms.store.product import Form_Filters_Product
|
||||
from forms.store.product import Filters_Product
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar, List
|
||||
@@ -352,8 +352,7 @@ class Product(SQLAlchemy_ABC, Store_Base):
|
||||
"""
|
||||
|
||||
|
||||
@dataclass
|
||||
class Filters_Product():
|
||||
class Parameters_Product(Get_Many_Parameters_Base):
|
||||
# id_user: str
|
||||
get_all_product_category: bool
|
||||
get_inactive_product_category: bool
|
||||
@@ -388,7 +387,7 @@ class Filters_Product():
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'a_id_user': None,
|
||||
# 'a_id_user': None,
|
||||
'a_get_all_product_category': self.get_all_product_category,
|
||||
'a_get_inactive_product_category': self.get_inactive_product_category,
|
||||
# 'a_get_first_product_category_only': self.get_first_product_category_only,
|
||||
@@ -422,15 +421,15 @@ class Filters_Product():
|
||||
@staticmethod
|
||||
def from_form_filters_product(form):
|
||||
# if not (form is Filters_Product_Permutation): raise ValueError(f'Invalid form type: {type(form)}')
|
||||
av.val_instance(form, 'form', 'Filters_Product.from_form', Form_Filters_Product)
|
||||
av.val_instance(form, 'form', 'Parameters_Product.from_form', Filters_Product)
|
||||
has_filter_category = not (form.id_category.data == '0' or form.id_category.data == '')
|
||||
is_not_empty = av.input_bool(form.is_not_empty.data, "is_not_empty", "Filters_Product.from_form_filters_product")
|
||||
active = av.input_bool(form.active.data, "active", "Filters_Product.from_form_filters_product")
|
||||
return Filters_Product(
|
||||
is_not_empty = av.input_bool(form.is_not_empty.data, "is_not_empty", "Parameters_Product.from_form_filters_product")
|
||||
active = av.input_bool(form.active.data, "active", "Parameters_Product.from_form_filters_product")
|
||||
return Parameters_Product(
|
||||
get_all_product_category = not has_filter_category,
|
||||
get_inactive_product_category = not active,
|
||||
# get_first_product_category_only = False,
|
||||
ids_product_category = form.id_category.data,
|
||||
ids_product_category = form.id_category.data if form.id_category.data is not None else '',
|
||||
get_all_product = True,
|
||||
get_inactive_product = not active,
|
||||
# get_first_product_only = False,
|
||||
@@ -459,12 +458,12 @@ class Filters_Product():
|
||||
@staticmethod
|
||||
def from_form_filters_product_permutation(form):
|
||||
# if not (form is Filters_Product_Permutation): raise ValueError(f'Invalid form type: {type(form)}')
|
||||
av.val_instance(form, 'form', 'Filters_Product.from_form', Filters_Product_Permutation)
|
||||
av.val_instance(form, 'form', 'Parameters_Product.from_form', Filters_Product_Permutation)
|
||||
has_category_filter = not (form.id_category.data == '0' or form.id_category.data == '')
|
||||
has_product_filter = not (form.id_product.data == '0' or form.id_product.data == '')
|
||||
get_permutations_stock_below_min = av.input_bool(form.is_out_of_stock.data, "is_out_of_stock", "Filters_Product.from_form")
|
||||
get_permutations_stock_below_min = av.input_bool(form.is_out_of_stock.data, "is_out_of_stock", "Parameters_Product.from_form")
|
||||
print(f'form question: {type(form.is_out_of_stock)}\nbool interpretted: {get_permutations_stock_below_min}\type form: {type(form)}')
|
||||
return Filters_Product(
|
||||
return Parameters_Product(
|
||||
get_all_product_category = not has_category_filter,
|
||||
get_inactive_product_category = False,
|
||||
# get_first_product_category_only = False,
|
||||
@@ -497,7 +496,7 @@ class Filters_Product():
|
||||
|
||||
@staticmethod
|
||||
def get_default():
|
||||
return Filters_Product(
|
||||
return Parameters_Product(
|
||||
get_all_product_category = True,
|
||||
get_inactive_product_category = False,
|
||||
# get_first_product_category_only = False,
|
||||
@@ -579,8 +578,8 @@ class Filters_Product():
|
||||
get_products_quantity_stock_below_min = False
|
||||
)
|
||||
|
||||
|
||||
class Filters_Product(Get_Many_Parameters_Base):
|
||||
"""
|
||||
class Parameters_Product(Get_Many_Parameters_Base):
|
||||
# id_user: str
|
||||
get_all_product_category: bool
|
||||
get_inactive_product_category: bool
|
||||
@@ -598,7 +597,7 @@ class Filters_Product(Get_Many_Parameters_Base):
|
||||
get_inactive_image: bool
|
||||
# get_first_image_only: bool
|
||||
ids_image: str
|
||||
"""
|
||||
""
|
||||
get_all_region: bool
|
||||
get_inactive_region: bool
|
||||
get_first_region_only: bool
|
||||
@@ -610,15 +609,15 @@ class Filters_Product(Get_Many_Parameters_Base):
|
||||
get_all_discount: bool
|
||||
get_inactive_discount: bool
|
||||
ids_discount: str
|
||||
"""
|
||||
""
|
||||
get_products_quantity_stock_below_min: bool
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
def __init__(self, a_id_user, **kwargs):
|
||||
super().__init__(a_id_user, **kwargs)
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'a_id_user': None,
|
||||
'a_id_user': self.a_id_user,
|
||||
'a_get_all_product_category': self.get_all_product_category,
|
||||
'a_get_inactive_product_category': self.get_inactive_product_category,
|
||||
# 'a_get_first_product_category_only': self.get_first_product_category_only,
|
||||
@@ -650,13 +649,14 @@ class Filters_Product(Get_Many_Parameters_Base):
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def from_form_filters_product(form):
|
||||
def from_form_filters_product(form, id_user):
|
||||
# if not (form is Filters_Product_Permutation): raise ValueError(f'Invalid form type: {type(form)}')
|
||||
av.val_instance(form, 'form', 'Filters_Product.from_form', Form_Filters_Product)
|
||||
av.val_instance(form, 'form', 'Parameters_Product.from_form', Filters_Product)
|
||||
has_filter_category = not (form.id_category.data == '0' or form.id_category.data == '')
|
||||
is_not_empty = av.input_bool(form.is_not_empty.data, "is_not_empty", "Filters_Product.from_form_filters_product")
|
||||
active = av.input_bool(form.active.data, "active", "Filters_Product.from_form_filters_product")
|
||||
return Filters_Product(
|
||||
is_not_empty = av.input_bool(form.is_not_empty.data, "is_not_empty", "Parameters_Product.from_form_filters_product")
|
||||
active = av.input_bool(form.active.data, "active", "Parameters_Product.from_form_filters_product")
|
||||
return Parameters_Product(
|
||||
a_id_user = id_user,
|
||||
get_all_product_category = not has_filter_category,
|
||||
get_inactive_product_category = not active,
|
||||
# get_first_product_category_only = False,
|
||||
@@ -689,12 +689,12 @@ class Filters_Product(Get_Many_Parameters_Base):
|
||||
@staticmethod
|
||||
def from_form_filters_product_permutation(form):
|
||||
# if not (form is Filters_Product_Permutation): raise ValueError(f'Invalid form type: {type(form)}')
|
||||
# av.val_instance(form, 'form', 'Filters_Product.from_form', Form_Base)
|
||||
# av.val_instance(form, 'form', 'Parameters_Product.from_form', Form_Base)
|
||||
has_category_filter = not (form.id_category.data is None or form.id_category.data == '0' or form.id_category.data == '')
|
||||
has_product_filter = not (form.id_product.data is None or form.id_product.data == '0' or form.id_product.data == '')
|
||||
get_permutations_stock_below_min = av.input_bool(form.is_out_of_stock.data, "is_out_of_stock", "Filters_Product.from_form")
|
||||
get_permutations_stock_below_min = av.input_bool(form.is_out_of_stock.data, "is_out_of_stock", "Parameters_Product.from_form")
|
||||
print(f'form question: {type(form.is_out_of_stock)}\nbool interpretted: {get_permutations_stock_below_min}\type form: {type(form)}')
|
||||
return Filters_Product(
|
||||
return Parameters_Product(
|
||||
get_all_product_category = not has_category_filter,
|
||||
get_inactive_product_category = False,
|
||||
# get_first_product_category_only = False,
|
||||
@@ -725,9 +725,10 @@ class Filters_Product(Get_Many_Parameters_Base):
|
||||
get_products_quantity_stock_below_min = get_permutations_stock_below_min
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_default():
|
||||
return Filters_Product(
|
||||
@classmethod
|
||||
def get_default(cls, id_user):
|
||||
return cls(
|
||||
a_id_user = id_user,
|
||||
get_all_product_category = True,
|
||||
get_inactive_product_category = False,
|
||||
# get_first_product_category_only = False,
|
||||
@@ -810,4 +811,5 @@ class Filters_Product(Get_Many_Parameters_Base):
|
||||
)
|
||||
@classmethod
|
||||
def from_filters_stock_item(cls, filters_stock_item):
|
||||
return cls.from_form_filters_product_permutation(filters_stock_item)
|
||||
return cls.from_form_filters_product_permutation(filters_stock_item)
|
||||
"""
|
||||
@@ -241,13 +241,13 @@ class Filters_Product_Category(BaseModel, Store_Base):
|
||||
ids_product: str
|
||||
""
|
||||
def __new__(cls, product_ids, product_categories):
|
||||
_m = 'Filters_Product.__new__'
|
||||
_m = 'Parameters_Product.__new__'
|
||||
v_arg_type = 'class attribute'
|
||||
# av.val_list_instances(product_ids, 'product_ids', _m, str, v_arg_type=v_arg_type)
|
||||
# av.val_list_instances(product_categories, 'product_categories', _m, Product_Category_Enum, v_arg_type=v_arg_type)
|
||||
av.val_str(product_ids, 'product_ids', _m, v_arg_type=v_arg_type)
|
||||
av.val_str(product_categories, 'product_categories', _m, v_arg_type=v_arg_type)
|
||||
return super(Filters_Product_Category, cls).__new__(cls)
|
||||
return super(Parameters_Product_Category, cls).__new__(cls)
|
||||
""
|
||||
def __init__(self, ids_product, ids_product_category):
|
||||
super().__init__(ids_product=ids_product, ids_product_category=ids_product_category)
|
||||
|
||||
@@ -35,7 +35,7 @@ class Product_Price(db.Model, Store_Base):
|
||||
name_currency = db.Column(db.String(255))
|
||||
symbol_currency = db.Column(db.String(50))
|
||||
"""
|
||||
id_region = db.Column(db.Integer)
|
||||
# id_region = db.Column(db.Integer)
|
||||
value_local_VAT_incl = db.Column(db.Float)
|
||||
value_local_VAT_excl = db.Column(db.Float)
|
||||
display_order = db.Column(db.Float)
|
||||
@@ -60,7 +60,7 @@ class Product_Price(db.Model, Store_Base):
|
||||
price.name_currency = query_row[6]
|
||||
price.symbol_currency = query_row[7]
|
||||
"""
|
||||
price.id_region = query_row[8]
|
||||
# price.id_region = query_row[8]
|
||||
price.value_local_VAT_incl = query_row[9]
|
||||
price.value_local_VAT_excl = query_row[10]
|
||||
price.display_order = query_row[11]
|
||||
@@ -73,7 +73,6 @@ class Product_Price(db.Model, Store_Base):
|
||||
id_product: {self.id_product}
|
||||
id_category: {self.id_category}
|
||||
currency: {self.currency}
|
||||
id_region: {self.id_region}
|
||||
value_local (VAT incl): {self.value_local_VAT_incl}
|
||||
value_local (VAT excl): {self.value_local_VAT_excl}
|
||||
display_order (UID): {self.display_order}
|
||||
@@ -88,7 +87,7 @@ class Product_Price(db.Model, Store_Base):
|
||||
self.ATTR_ID_PRODUCT: self.id_product,
|
||||
self.ATTR_ID_PRODUCT_CATEGORY: self.id_category,
|
||||
self.FLAG_CURRENCY: self.currency.to_json(),
|
||||
Delivery_Region.ATTR_ID_DELIVERY_REGION: self.id_region,
|
||||
# Delivery_Region.ATTR_ID_DELIVERY_REGION: self.id_region,
|
||||
self.FLAG_VALUE_LOCAL_VAT_INCL: self.value_local_VAT_incl,
|
||||
self.FLAG_VALUE_LOCAL_VAT_EXCL: self.value_local_VAT_excl,
|
||||
self.FLAG_DISPLAY_ORDER: self.display_order
|
||||
@@ -102,7 +101,7 @@ class Product_Price(db.Model, Store_Base):
|
||||
price.id_product = json[cls.ATTR_ID_PRODUCT]
|
||||
price.id_category = json[cls.ATTR_ID_PRODUCT_CATEGORY]
|
||||
price.currency = Currency.from_json(json)
|
||||
price.id_region = json[Delivery_Region.ATTR_ID_DELIVERY_REGION]
|
||||
# price.id_region = json[Delivery_Region.ATTR_ID_DELIVERY_REGION]
|
||||
price.value_local_VAT_incl = json[cls.FLAG_VALUE_LOCAL_VAT_INCL]
|
||||
price.value_local_VAT_excl = json[cls.FLAG_VALUE_LOCAL_VAT_EXCL]
|
||||
price.display_order = json[cls.FLAG_DISPLAY_ORDER]
|
||||
|
||||
@@ -142,7 +142,7 @@ class Product_Variation_Filters():
|
||||
"""
|
||||
@staticmethod
|
||||
def from_form(form):
|
||||
av.val_instance(form, 'form', 'User_Filters.from_form', Form_Filters_Product_Variation)
|
||||
av.val_instance(form, 'form', 'User_Filters.from_form', Filters_Product_Variation)
|
||||
get_inactive = av.input_bool(form.active.data, "active", "User_Filters.from_form")
|
||||
id_user = form.id_user.data
|
||||
return User_Filters(
|
||||
|
||||
@@ -236,11 +236,14 @@ class Parameters_Stock_Item(Get_Many_Parameters_Base):
|
||||
a_get_nonexpired_stock_item_only: bool
|
||||
a_get_consumed_stock_item_only: bool
|
||||
a_get_nonconsumed_stock_item_only: bool
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
@classmethod
|
||||
def get_default(cls, id_user):
|
||||
def get_default(cls):
|
||||
return cls(
|
||||
a_id_user = id_user,
|
||||
# a_id_user = id_user,
|
||||
a_get_all_product_permutation = True,
|
||||
a_get_inactive_product_permutation = False,
|
||||
a_ids_product_permutation = '',
|
||||
@@ -266,5 +269,5 @@ class Parameters_Stock_Item(Get_Many_Parameters_Base):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_form_stock_item(cls, id_user, form):
|
||||
return cls.get_default(id_user)
|
||||
def from_form_stock_item(cls, form):
|
||||
return cls.get_default()
|
||||
@@ -84,6 +84,7 @@ class Store_Base(Base):
|
||||
FLAG_PRODUCT_VARIATION_TYPE: ClassVar[str] = 'product_variation_type'
|
||||
FLAG_QUANTITY_MIN: ClassVar[str] = 'quantity_min'
|
||||
FLAG_QUANTITY_MAX: ClassVar[str] = 'quantity_max'
|
||||
FLAG_STOCK_ITEM: ClassVar[str] = 'stock_item'
|
||||
FLAG_TEXT: ClassVar[str] = 'text'
|
||||
FLAG_VALUE_TEXT: ClassVar[str] = 'value_text'
|
||||
|
||||
Reference in New Issue
Block a user