Restructure pages for permutations and basket with metadata for is_included_VAT, id_currency, id_region_delivery
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -108,9 +108,21 @@ class Basket_Item():
|
||||
'''
|
||||
|
||||
class Basket():
|
||||
KEY_BASKET: str = 'basket'
|
||||
KEY_ID_CURRENCY: str = 'id_currency'
|
||||
KEY_ID_REGION_DELIVERY: str = 'id_region_delivery'
|
||||
KEY_IS_INCLUDED_VAT: str = 'is_included_VAT'
|
||||
KEY_ITEMS: str = 'items'
|
||||
items: list
|
||||
def __init__(self):
|
||||
is_included_VAT: bool
|
||||
id_region_delivery: int
|
||||
id_currency: int
|
||||
|
||||
def __init__(self, is_included_VAT, id_currency, id_region_delivery):
|
||||
self.items = []
|
||||
self.is_included_VAT = is_included_VAT
|
||||
self.id_currency = id_currency
|
||||
self.id_region_delivery = id_region_delivery
|
||||
def add_item(self, item):
|
||||
av.val_instance(item, 'item', 'Basket.add_item', Basket_Item)
|
||||
self.items.append(item)
|
||||
@@ -134,7 +146,12 @@ class Basket():
|
||||
json_list.append(item.to_json())
|
||||
return json_list
|
||||
def to_json(self):
|
||||
return {'items': self.to_json_list()}
|
||||
return {
|
||||
Basket.KEY_ITEMS: self.to_json_list(),
|
||||
Basket.KEY_IS_INCLUDED_VAT: self.is_included_VAT,
|
||||
Basket.KEY_ID_CURRENCY: self.id_currency,
|
||||
Basket.KEY_ID_REGION_DELIVERY: self.id_region_delivery
|
||||
}
|
||||
def output_total(self):
|
||||
sum = 0
|
||||
for b_i in self.items:
|
||||
|
||||
@@ -184,6 +184,14 @@ class Category(db.Model):
|
||||
if not (len(self.products) == 0):
|
||||
print(f'getting first permutation from product')
|
||||
return None if len(self.products) == 0 else self.products[0].get_permutation_selected()
|
||||
|
||||
def is_available(self):
|
||||
if len(self.products) == 0:
|
||||
return False
|
||||
for product in self.products:
|
||||
if product.is_available():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class Product_Category_Filters():
|
||||
|
||||
@@ -317,6 +317,15 @@ class Product(db.Model):
|
||||
av.val_instance(discount, 'discount', 'Product.add_discount', Discount)
|
||||
index_permutation = self.permutation_index[discount.id_permutation] # self.get_index_permutation_from_id(discount.id_permutation)
|
||||
self.permutations[index_permutation].add_discount(discount)
|
||||
def has_permutations(self):
|
||||
return len(self.permutations) > 0
|
||||
def is_available(self):
|
||||
if len(self.permutations) == 0:
|
||||
return False
|
||||
for permutation in self.permutations:
|
||||
if permutation.is_available():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class Product_Permutation(db.Model):
|
||||
@@ -362,7 +371,7 @@ class Product_Permutation(db.Model):
|
||||
self.form_basket_add = Form_Basket_Add()
|
||||
self.form_basket_edit = Form_Basket_Edit()
|
||||
self.is_unavailable_in_currency_or_region = False
|
||||
self.is_available = True
|
||||
# self.is_available = False
|
||||
|
||||
def make_from_DB_product(query_row):
|
||||
_m = 'Product_Permutation.make_from_DB_product'
|
||||
@@ -422,6 +431,8 @@ class Product_Permutation(db.Model):
|
||||
permutation.id_permutation = json_basket_item[key_id_permutation]
|
||||
return permutation
|
||||
|
||||
def is_available(self):
|
||||
return len(self.prices) > 0
|
||||
def get_price(self):
|
||||
return self.prices[0]
|
||||
def get_price_local_VAT_incl(self):
|
||||
|
||||
Reference in New Issue
Block a user