feat(MySQL): Tables, Triggers, and Get Many and Save Stored Procedures for Suppliers, Supplier Purchase Orders (+ items), and Manufacturing Purchase Orders (+ items)
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -35,6 +35,8 @@ class Base():
|
||||
FLAG_CURRENCY_COST: ClassVar[str] = 'currency_cost'
|
||||
FLAG_DESCRIPTION: ClassVar[str] = 'description'
|
||||
FLAG_DISPLAY_ORDER: ClassVar[str] = 'display_order'
|
||||
FLAG_EMAIL: ClassVar[str] = 'email'
|
||||
FLAG_FAX: ClassVar[str] = 'fax'
|
||||
FLAG_GUID: ClassVar[str] = 'guid'
|
||||
FLAG_IS_NOT_EMPTY: ClassVar[str] = 'is_not_empty'
|
||||
# FLAG_KEY_PRIMARY: ClassVar[str] = 'key_primary'
|
||||
@@ -43,14 +45,17 @@ class Base():
|
||||
FLAG_NAME_ATTR_OPTION_VALUE: ClassVar[str] = 'NAME_ATTR_OPTION_VALUE'
|
||||
FLAG_NAME_SINGULAR: ClassVar[str] = 'name_singular'
|
||||
FLAG_NAME_PLURAL: ClassVar[str] = 'name_plural'
|
||||
FLAG_PHONE_NUMBER: ClassVar[str] = 'phone_number'
|
||||
FLAG_POSTCODE: ClassVar[str] = 'postcode'
|
||||
FLAG_PRIORITY: ClassVar[str] = 'priority'
|
||||
FLAG_REGION: ClassVar[str] = 'region'
|
||||
FLAG_ROWS: ClassVar[str] = 'rows'
|
||||
FLAG_SYMBOL: ClassVar[str] = 'symbol'
|
||||
FLAG_URL: ClassVar[str] = 'url'
|
||||
FLAG_USER: ClassVar[str] = 'authorisedUser' # 'user' already used
|
||||
FLAG_VALUE_LOCAL_VAT_EXCL: ClassVar[str] = 'value_local_vat_excl'
|
||||
FLAG_VALUE_LOCAL_VAT_INCL: ClassVar[str] = 'value_local_vat_incl'
|
||||
FLAG_WEBSITE: ClassVar[str] = 'website'
|
||||
"""
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = 'name-attribute-option-text'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = 'name-attribute-option-value'
|
||||
|
||||
Binary file not shown.
@@ -58,9 +58,12 @@ class I_Store_Base():
|
||||
|
||||
class Store_Base(Base):
|
||||
# ATTR_ID_CURRENCY_COST: ClassVar[str] = 'id_currency_cost'
|
||||
ATTR_ID_CUSTOMER: ClassVar[str] = 'id_customer'
|
||||
ATTR_ID_CUSTOMER_SALES_ORDER: ClassVar[str] = 'id_customer_sales_order'
|
||||
ATTR_ID_DELIVERY_OPTION: ClassVar[str] = 'id_delivery_option'
|
||||
ATTR_ID_DISCOUNT: ClassVar[str] = 'id_discount'
|
||||
ATTR_ID_IMAGE: ClassVar[str] = 'id_image'
|
||||
ATTR_ID_MANUFACTURING_PURCHASE_ORDER: ClassVar[str] = 'id_manufacturing_purchase_order'
|
||||
ATTR_ID_PLANT: ClassVar[str] = 'id_plant'
|
||||
ATTR_ID_PRODUCT: ClassVar[str] = 'id_product'
|
||||
ATTR_ID_PRODUCT_CATEGORY: ClassVar[str] = 'id_category'
|
||||
@@ -71,13 +74,18 @@ class Store_Base(Base):
|
||||
ATTR_ID_PRODUCT_VARIATION_TYPE: ClassVar[str] = 'id_type'
|
||||
ATTR_ID_STOCK_ITEM: ClassVar[str] = 'id_stock_item'
|
||||
ATTR_ID_STORAGE_LOCATION: ClassVar[str] = 'id_location'
|
||||
ATTR_ID_SUPPLIER: ClassVar[str] = 'id_supplier'
|
||||
ATTR_ID_SUPPLIER_PURCHASE_ORDER: ClassVar[str] = 'id_supplier_purchase_order'
|
||||
FLAG_COST_LOCAL: ClassVar[str] = 'cost_local'
|
||||
FLAG_COST_LOCAL_VAT_EXCL: ClassVar[str] = FLAG_COST_LOCAL + '_vat_excl'
|
||||
FLAG_COST_LOCAL_VAT_INCL: ClassVar[str] = FLAG_COST_LOCAL + '_vat_incl'
|
||||
FLAG_CUSTOMER: ClassVar[str] = 'customer'
|
||||
FLAG_CUSTOMER_SALES_ORDER: ClassVar[str] = 'customer_sales_order'
|
||||
FLAG_DELIVERY_OPTION: ClassVar[str] = 'delivery_option'
|
||||
FLAG_HAS_VARIATIONS: ClassVar[str] = 'has_variations'
|
||||
FLAG_IS_OUT_OF_STOCK: ClassVar[str] = 'is_out_of_stock'
|
||||
FLAG_DISCOUNT: ClassVar[str] = 'discount'
|
||||
FLAG_MANUFACTURING_PURCHASE_ORDER: ClassVar[str] = 'manufacturing_purchase_order'
|
||||
FLAG_PLANT: ClassVar[str] = 'plant'
|
||||
FLAG_PRODUCT: ClassVar[str] = 'product'
|
||||
FLAG_PRODUCT_CATEGORY: ClassVar[str] = 'product_category'
|
||||
@@ -91,6 +99,8 @@ class Store_Base(Base):
|
||||
FLAG_QUANTITY_MAX: ClassVar[str] = 'quantity_max'
|
||||
FLAG_STOCK_ITEM: ClassVar[str] = 'stock_item'
|
||||
FLAG_STORAGE_LOCATION: ClassVar[str] = 'storage_location'
|
||||
FLAG_SUPPLIER: ClassVar[str] = 'supplier'
|
||||
FLAG_SUPPLIER_PURCHASE_ORDER: ClassVar[str] = 'supplier_purchase_order'
|
||||
FLAG_TEXT: ClassVar[str] = 'text'
|
||||
FLAG_VALUE_TEXT: ClassVar[str] = 'value_text'
|
||||
|
||||
111
business_objects/store/supplier.py
Normal file
111
business_objects/store/supplier.py
Normal file
@@ -0,0 +1,111 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Supplier Business Object
|
||||
|
||||
Description:
|
||||
Business object for supplier
|
||||
"""
|
||||
|
||||
# internal
|
||||
import lib.argument_validation as av
|
||||
from business_objects.store.store_base import Store_Base
|
||||
from extensions import db
|
||||
# external
|
||||
from pydantic import BaseModel
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class Supplier(db.Model, Store_Base):
|
||||
FLAG_DEPARTMENT_CONTACT: ClassVar[str] = 'department_contact'
|
||||
FLAG_NAME_COMPANY: ClassVar[str] = 'name_company'
|
||||
FLAG_NAME_CONTACT: ClassVar[str] = 'name_contact'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_SUPPLIER
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_NAME
|
||||
__tablename__ = 'Shop_Supplier_Temp'
|
||||
id_supplier = db.Column(db.Integer, primary_key=True)
|
||||
id_address = db.Column(db.Integer)
|
||||
id_currency = db.Column(db.Integer)
|
||||
name_company = db.Column(db.String(255))
|
||||
name_contact = db.Column(db.String(255))
|
||||
department_contact = db.Column(db.String(255))
|
||||
# address
|
||||
phone_number = db.Column(db.String(50))
|
||||
fax = db.Column(db.String(50))
|
||||
email = db.Column(db.String(255))
|
||||
website = db.Column(db.String(255))
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
created_by = db.Column(db.Integer)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
Store_Base.__init__(self)
|
||||
@classmethod
|
||||
def from_DB_supplier(cls, query_row):
|
||||
supplier = cls()
|
||||
supplier.id_supplier = query_row[0]
|
||||
supplier.id_address = query_row[1]
|
||||
supplier.id_currency = query_row[2]
|
||||
supplier.name_company = query_row[3]
|
||||
supplier.name_contact = query_row[4]
|
||||
supplier.department_contact = query_row[5]
|
||||
supplier.phone_number = query_row[6]
|
||||
supplier.fax = query_row[7]
|
||||
supplier.email = query_row[8]
|
||||
supplier.website = query_row[9]
|
||||
supplier.active = query_row[10]
|
||||
return supplier
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
id: {self.id_supplier},
|
||||
id_address: {self.id_address},
|
||||
id_currency: {self.id_currency},
|
||||
name_company: {self.name_company},
|
||||
name_contact: {self.name_contact},
|
||||
department_contact: {self.department_contact},
|
||||
phone_number: {self.phone_number},
|
||||
fax: {self.fax},
|
||||
email: {self.email},
|
||||
website: {self.website},
|
||||
active: {self.active},
|
||||
'''
|
||||
def to_json(self):
|
||||
return {
|
||||
**self.get_shared_json_attributes(self),
|
||||
self.ATTR_ID_SUPPLIER: self.id_supplier,
|
||||
self.ATTR_ID_ADDRESS: self.id_address,
|
||||
self.ATTR_ID_CURRENCY: self.id_currency,
|
||||
self.FLAG_NAME_COMPANY: self.name_company,
|
||||
self.FLAG_NAME_CONTACT: self.name_contact,
|
||||
self.FLAG_DEPARTMENT_CONTACT: self.department_contact,
|
||||
self.FLAG_PHONE_NUMBER: self.phone_number,
|
||||
self.FLAG_FAX: self.fax,
|
||||
self.FLAG_EMAIL: self.email,
|
||||
self.FLAG_WEBSITE: self.website,
|
||||
self.FLAG_ACTIVE: av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json')
|
||||
}
|
||||
def to_json_option(self):
|
||||
return {
|
||||
'value': self.id_supplier,
|
||||
'text': self.name_company
|
||||
}
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
print(f'{cls.__name__}.from_json: {json}')
|
||||
supplier = cls()
|
||||
supplier.id_supplier = json[cls.ATTR_ID_SUPPLIER]
|
||||
supplier.id_address = json[cls.ATTR_ID_ADDRESS]
|
||||
supplier.id_currency = json[cls.ATTR_ID_CURRENCY]
|
||||
supplier.name_company = json[cls.FLAG_NAME_COMPANY]
|
||||
supplier.name_contact = json[cls.FLAG_NAME_CONTACT]
|
||||
supplier.department_contact = json[cls.FLAG_DEPARTMENT_CONTACT]
|
||||
supplier.phone_number = json[cls.FLAG_PHONE_NUMBER]
|
||||
supplier.fax = json[cls.FLAG_FAX]
|
||||
supplier.email = json[cls.FLAG_EMAIL]
|
||||
supplier.website = json[cls.FLAG_WEBSITE]
|
||||
supplier.active = json[cls.FLAG_ACTIVE]
|
||||
return supplier
|
||||
@@ -18,7 +18,6 @@ from typing import ClassVar
|
||||
|
||||
|
||||
class User(db.Model, Base):
|
||||
KEY_USER: ClassVar[str] = 'authorisedUser' # 'user' already used
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = Base.ATTR_ID_USER
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = 'email'
|
||||
|
||||
@@ -57,6 +56,7 @@ class User(db.Model, Base):
|
||||
user.is_super_user = av.input_bool(query_row[9], 'is_super_user', _m)
|
||||
user.can_admin_store = av.input_bool(query_row[10], 'can_admin_store', _m)
|
||||
user.can_admin_user = av.input_bool(query_row[11], 'can_admin_user', _m)
|
||||
user.is_logged_in = (user.id_user is not None and user.id_user > 0)
|
||||
return user
|
||||
|
||||
@staticmethod
|
||||
@@ -101,6 +101,7 @@ class User(db.Model, Base):
|
||||
user.is_included_VAT_default = None
|
||||
user.can_admin_store = None
|
||||
user.can_admin_user = None
|
||||
user.is_logged_in = (user.id_user_auth0 is not None and user.id_user_auth0 != '')
|
||||
print(f'user: {user}')
|
||||
return user
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -36,7 +36,6 @@ routes_core = Blueprint('routes_core', __name__)
|
||||
def home():
|
||||
try:
|
||||
model = Model_View_Home()
|
||||
print('nips')
|
||||
html_body = render_template('pages/core/_home.html', model = model)
|
||||
except Exception as e:
|
||||
return jsonify(error=str(e)), 403
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -61,12 +61,12 @@ def filter():
|
||||
# ToDo: manually validate category, product
|
||||
filters_form = Parameters_Product.from_form_filters_product(form_filters)
|
||||
model = Model_View_Store_Product(filters = filters_form)
|
||||
return jsonify({Model_View_Store_Product.FLAG_STATUS: Model_View_Store_Product.FLAG_SUCCESS, 'Success': True, Model_View_Store_Product.KEY_DATA: model.category_list.to_json()})
|
||||
return jsonify({Model_View_Store_Product.FLAG_STATUS: Model_View_Store_Product.FLAG_SUCCESS, 'Success': True, Model_View_Store_Product.FLAG_DATA: model.category_list.to_json()})
|
||||
except Exception as e:
|
||||
return jsonify({Model_View_Store_Product.FLAG_STATUS: Model_View_Store_Product.FLAG_FAILURE, Model_View_Store_Product.FLAG_MESSAGE: f'Bad data received by controller.\n{e}'})
|
||||
|
||||
def get_Filters_Product(data_request):
|
||||
data_form = data_request[Model_View_Store_Product.KEY_FORM]
|
||||
data_form = data_request[Model_View_Store_Product.FLAG_FORM]
|
||||
form_filters = Filters_Product(**data_form)
|
||||
form_filters.is_not_empty.data = av.input_bool(data_form['is_not_empty'], 'is_not_empty', 'filter')
|
||||
form_filters.active.data = av.input_bool(data_form['active'], 'active', 'filter')
|
||||
@@ -95,7 +95,7 @@ def save():
|
||||
|
||||
model_return = Model_View_Store_Product(filters=filters_form)
|
||||
print('nips')
|
||||
return jsonify({Model_View_Store_Product.FLAG_STATUS: Model_View_Store_Product.FLAG_SUCCESS, 'Success': True, Model_View_Store_Product.KEY_DATA: model_return.category_list.to_json()})
|
||||
return jsonify({Model_View_Store_Product.FLAG_STATUS: Model_View_Store_Product.FLAG_SUCCESS, 'Success': True, Model_View_Store_Product.FLAG_DATA: model_return.category_list.to_json()})
|
||||
except Exception as e:
|
||||
return jsonify({Model_View_Store_Product.FLAG_STATUS: Model_View_Store_Product.FLAG_FAILURE, Model_View_Store_Product.FLAG_MESSAGE: f'Bad data received by controller.\n{e}'})
|
||||
"""
|
||||
@@ -112,7 +112,7 @@ def products():
|
||||
print(f'form_filters={form_filters}')
|
||||
model = Model_View_Store_Product(form_filters)
|
||||
if not model.is_user_logged_in:
|
||||
# return redirect(url_for('routes_user.login', data = jsonify({ Model_View_Store_Product.KEY_CALLBACK: Model_View_Store_Product.HASH_PAGE_STORE_PRODUCTS })))
|
||||
# return redirect(url_for('routes_user.login', data = jsonify({ Model_View_Store_Product.FLAG_CALLBACK: Model_View_Store_Product.HASH_PAGE_STORE_PRODUCTS })))
|
||||
return redirect(url_for('routes_core.home'))
|
||||
return render_template('pages/store/_products.html', model = model)
|
||||
|
||||
@@ -131,7 +131,7 @@ def filter_product():
|
||||
raise Exception('User not logged in')
|
||||
return jsonify({
|
||||
Model_View_Store_Product.FLAG_STATUS: Model_View_Store_Product.FLAG_SUCCESS,
|
||||
Model_View_Store_Product.KEY_DATA: model.category_list.to_json()
|
||||
Model_View_Store_Product.FLAG_DATA: model.category_list.to_json()
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
@@ -171,7 +171,7 @@ def save_product():
|
||||
print('nips')
|
||||
return jsonify({
|
||||
Model_View_Store_Product.FLAG_STATUS: Model_View_Store_Product.FLAG_SUCCESS,
|
||||
Model_View_Store_Product.KEY_DATA: model_return.category_list.to_json()
|
||||
Model_View_Store_Product.FLAG_DATA: model_return.category_list.to_json()
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
|
||||
@@ -55,7 +55,7 @@ def categories():
|
||||
"""
|
||||
model = Model_View_Store_Product_Category(form_filters)
|
||||
if not model.is_user_logged_in:
|
||||
# return redirect(url_for('routes_user.login', data = jsonify({ Model_View_Store_Product_Category.KEY_CALLBACK: Model_View_Store_Product_Category.HASH_PAGE_STORE_PRODUCT_CATEGORIES })))
|
||||
# return redirect(url_for('routes_user.login', data = jsonify({ Model_View_Store_Product_Category.FLAG_CALLBACK: Model_View_Store_Product_Category.HASH_PAGE_STORE_PRODUCT_CATEGORIES })))
|
||||
return redirect(url_for('routes_core.home'))
|
||||
return render_template('pages/store/_product_categories.html', model = model)
|
||||
|
||||
@@ -77,7 +77,7 @@ def filter_category():
|
||||
raise Exception('User not logged in')
|
||||
return jsonify({
|
||||
Model_View_Store_Product_Category.FLAG_STATUS: Model_View_Store_Product_Category.FLAG_SUCCESS,
|
||||
Model_View_Store_Product_Category.KEY_DATA: model.category_list.to_json()
|
||||
Model_View_Store_Product_Category.FLAG_DATA: model.category_list.to_json()
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
@@ -115,7 +115,7 @@ def save_category():
|
||||
raise Exception('User not logged in')
|
||||
return jsonify({
|
||||
Model_View_Store_Product_Category.FLAG_STATUS: Model_View_Store_Product_Category.FLAG_SUCCESS,
|
||||
Model_View_Store_Product_Category.KEY_DATA: model_return.category_list.to_json()
|
||||
Model_View_Store_Product_Category.FLAG_DATA: model_return.category_list.to_json()
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
|
||||
@@ -48,12 +48,12 @@ def permutation_filter():
|
||||
# ToDo: manually validate category, product
|
||||
filters_form = Parameters_Product.from_form(form_filters)
|
||||
model = Model_View_Store_Product_Permutation(filters_product=filters_form)
|
||||
return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_SUCCESS, 'Success': True, Model_View_Base.KEY_DATA: model.category_list.to_permutation_row_list()})
|
||||
return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_SUCCESS, 'Success': True, Model_View_Base.FLAG_DATA: model.category_list.to_permutation_row_list()})
|
||||
except Exception as e:
|
||||
return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Bad data received by controller.\n{e}'})
|
||||
|
||||
def get_Form_Filters_Permutation(data_request):
|
||||
data_form = data_request[Model_View_Store_Product_Permutation.KEY_FORM]
|
||||
data_form = data_request[Model_View_Store_Product_Permutation.FLAG_FORM]
|
||||
form_filters = Filters_Product_Permutation(**data_form)
|
||||
form_filters.is_out_of_stock.data = av.input_bool(data_form['is_out_of_stock'], 'is_out_of_stock', 'permutations_post')
|
||||
return form_filters
|
||||
@@ -80,7 +80,7 @@ def permutation_save():
|
||||
model_save.save_permutations(data.comment, objsPermutation)
|
||||
|
||||
model_return = Model_View_Store_Product_Permutation(filters_product=filters_form)
|
||||
return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_SUCCESS, 'Success': True, Model_View_Base.KEY_DATA: model_return.category_list.to_permutation_row_list()})
|
||||
return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_SUCCESS, 'Success': True, Model_View_Base.FLAG_DATA: model_return.category_list.to_permutation_row_list()})
|
||||
except Exception as e:
|
||||
return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Bad data received by controller.\n{e}'})
|
||||
"""
|
||||
@@ -97,7 +97,7 @@ def permutations():
|
||||
print(f'form_filters={form_filters}')
|
||||
model = Model_View_Store_Product_Permutation(form_filters)
|
||||
if not model.is_user_logged_in:
|
||||
# return redirect(url_for('routes_user.login', data = jsonify({ Model_View_Store_Product_Permutation.KEY_CALLBACK: Model_View_Store_Product_Permutation.HASH_PAGE_STORE_PRODUCT_PERMUTATIONS })))
|
||||
# return redirect(url_for('routes_user.login', data = jsonify({ Model_View_Store_Product_Permutation.FLAG_CALLBACK: Model_View_Store_Product_Permutation.HASH_PAGE_STORE_PRODUCT_PERMUTATIONS })))
|
||||
return redirect(url_for('routes_core.home'))
|
||||
return render_template('pages/store/_product_permutations.html', model = model)
|
||||
|
||||
@@ -116,7 +116,7 @@ def filter_permutation():
|
||||
raise Exception('User not logged in')
|
||||
return jsonify({
|
||||
Model_View_Store_Product_Permutation.FLAG_STATUS: Model_View_Store_Product_Permutation.FLAG_SUCCESS,
|
||||
Model_View_Store_Product_Permutation.KEY_DATA: model.category_list.to_json()
|
||||
Model_View_Store_Product_Permutation.FLAG_DATA: model.category_list.to_json()
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
@@ -156,7 +156,7 @@ def save_permutation():
|
||||
print('nips')
|
||||
return jsonify({
|
||||
Model_View_Store_Product_Permutation.FLAG_STATUS: Model_View_Store_Product_Permutation.FLAG_SUCCESS,
|
||||
Model_View_Store_Product_Permutation.KEY_DATA: model_return.category_list.to_json()
|
||||
Model_View_Store_Product_Permutation.FLAG_DATA: model_return.category_list.to_json()
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
|
||||
@@ -39,8 +39,8 @@ def stock_items():
|
||||
print(f'form_filters={form_filters}')
|
||||
model = Model_View_Store_Stock_Item(form_filters)
|
||||
if not model.is_user_logged_in:
|
||||
# return redirect(url_for('routes_user.login', data = jsonify({ Model_View_Store_Stock_Item.KEY_CALLBACK: Model_View_Store_Stock_Item.HASH_PAGE_STORE_STOCK_ITEMS })))
|
||||
# return requests.post(f"{current_app.config['URL_HOST']}{url_for('routes_user.login')}", json={ Model_View_Store_Stock_Item.KEY_CALLBACK: Model_View_Store_Stock_Item.HASH_PAGE_STORE_STOCK_ITEMS })
|
||||
# return redirect(url_for('routes_user.login', data = jsonify({ Model_View_Store_Stock_Item.FLAG_CALLBACK: Model_View_Store_Stock_Item.HASH_PAGE_STORE_STOCK_ITEMS })))
|
||||
# return requests.post(f"{current_app.config['URL_HOST']}{url_for('routes_user.login')}", json={ Model_View_Store_Stock_Item.FLAG_CALLBACK: Model_View_Store_Stock_Item.HASH_PAGE_STORE_STOCK_ITEMS })
|
||||
return redirect(url_for('routes_core.home'))
|
||||
return render_template('pages/store/_stock_items.html', model = model, datetime = datetime)
|
||||
|
||||
@@ -73,7 +73,7 @@ def filter_stock_item():
|
||||
raise Exception('User not logged in.')
|
||||
return jsonify({
|
||||
Model_View_Store_Stock_Item.FLAG_STATUS: Model_View_Store_Stock_Item.FLAG_SUCCESS,
|
||||
Model_View_Store_Stock_Item.KEY_DATA: model.category_list.to_json()
|
||||
Model_View_Store_Stock_Item.FLAG_DATA: model.category_list.to_json()
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
@@ -133,7 +133,7 @@ def save_stock_item():
|
||||
raise Exception('User not logged in.')
|
||||
return jsonify({
|
||||
Model_View_Store_Stock_Item.FLAG_STATUS: Model_View_Store_Stock_Item.FLAG_SUCCESS,
|
||||
Model_View_Store_Stock_Item.KEY_DATA: model_return.category_list.to_json()
|
||||
Model_View_Store_Stock_Item.FLAG_DATA: model_return.category_list.to_json()
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
|
||||
@@ -54,7 +54,7 @@ def supplier():
|
||||
try:
|
||||
model = Model_View_Store_Supplier(form)
|
||||
if not model.is_user_logged_in:
|
||||
# return redirect(url_for('routes_user.login', data = jsonify({ Model_View_Store_Supplier.KEY_CALLBACK: Model_View_Store_Supplier.HASH_PAGE_STORE_SUPPLIERS })))
|
||||
# return redirect(url_for('routes_user.login', data = jsonify({ Model_View_Store_Supplier.FLAG_CALLBACK: Model_View_Store_Supplier.HASH_PAGE_STORE_SUPPLIERS })))
|
||||
return redirect(url_for('routes_core.home'))
|
||||
# print('importing basket')
|
||||
# model.import_JSON_basket(data)
|
||||
|
||||
@@ -36,14 +36,14 @@ def login():
|
||||
except:
|
||||
data = {}
|
||||
print(f'data={data}')
|
||||
# callback_login = F'{Model_View_Base.HASH_CALLBACK_LOGIN}{data.get(Model_View_Base.KEY_CALLBACK, Model_View_Base.HASH_PAGE_HOME)}'
|
||||
# callback_login = F'{Model_View_Base.HASH_CALLBACK_LOGIN}{data.get(Model_View_Base.FLAG_CALLBACK, Model_View_Base.HASH_PAGE_HOME)}'
|
||||
|
||||
# encoded_path = quote(data.get(Model_View_Base.KEY_CALLBACK, Model_View_Base.HASH_PAGE_HOME))
|
||||
# encoded_path = quote(data.get(Model_View_Base.FLAG_CALLBACK, Model_View_Base.HASH_PAGE_HOME))
|
||||
uri_redirect = url_for('routes_user.login_callback', _external=True) # , subpath=encoded_path
|
||||
|
||||
# uri_redirect = f'{current_app.URL_HOST}/login_callback?subpath={data.get(Model_View_Base.KEY_CALLBACK, Model_View_Base.HASH_PAGE_HOME)}'
|
||||
# uri_redirect = f'{current_app.URL_HOST}/login_callback?subpath={data.get(Model_View_Base.FLAG_CALLBACK, Model_View_Base.HASH_PAGE_HOME)}'
|
||||
print(f'redirect uri: {uri_redirect}')
|
||||
hash_callback = data.get(Model_View_Base.KEY_CALLBACK, Model_View_Base.HASH_PAGE_HOME)
|
||||
hash_callback = data.get(Model_View_Base.FLAG_CALLBACK, Model_View_Base.HASH_PAGE_HOME)
|
||||
print(f'hash_callback: {hash_callback}')
|
||||
|
||||
red = oauth.auth0.authorize_redirect(
|
||||
@@ -63,7 +63,7 @@ def login():
|
||||
|
||||
Query Parameters: {query_params}
|
||||
""")
|
||||
return jsonify({'Success': True, Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_SUCCESS, f'{Model_View_Base.KEY_CALLBACK}': headers})
|
||||
return jsonify({'Success': True, Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_SUCCESS, f'{Model_View_Base.FLAG_CALLBACK}': headers})
|
||||
|
||||
@routes_user.route("/login_callback") # <path:subpath>/<code>
|
||||
def login_callback():
|
||||
@@ -84,6 +84,7 @@ def login_callback():
|
||||
print(f"Error: {str(e)}")
|
||||
session[current_app.config['ID_TOKEN_USER']] = token
|
||||
# import user id
|
||||
"""
|
||||
print(f'str(type(token)) = {str(type(token))}')
|
||||
print(f'token = {token}')
|
||||
userinfo = token.get('userinfo')
|
||||
@@ -91,18 +92,18 @@ def login_callback():
|
||||
# id_user = token.get('sub')
|
||||
id_user = userinfo.get('sub')
|
||||
print(f'user ID: {id_user}')
|
||||
|
||||
datastore_user = DataStore_User()
|
||||
user = datastore_user.get_user_auth0()
|
||||
"""
|
||||
user = User.from_json_auth0(token) # datastore_user.get_user_auth0()
|
||||
user_filters = User_Filters.from_user(user)
|
||||
datastore_user = DataStore_User()
|
||||
users, errors = datastore_user.get_many_user(user_filters, user)
|
||||
try:
|
||||
user = users[0]
|
||||
print('User logged in')
|
||||
print(f'user ({str(type(user))}): {user}')
|
||||
print(f'user key: {Model_View_Base.KEY_USER}')
|
||||
print(f'user key: {Model_View_Base.FLAG_USER}')
|
||||
user_json = user.to_json()
|
||||
session[Model_View_Base.KEY_USER] = user_json
|
||||
session[Model_View_Base.FLAG_USER] = user_json
|
||||
print(f'user stored on session')
|
||||
except:
|
||||
print(f'User not found: {user_filters}\nDatabase query error: {errors}')
|
||||
@@ -121,7 +122,7 @@ def login_callback():
|
||||
# add user to database
|
||||
# DataStore_Store().add_new_user(id_user) # this is part of get basket - should occur on page load
|
||||
|
||||
print(f'user session: {session[Model_View_Base.KEY_USER]}')
|
||||
print(f'user session: {session[Model_View_Base.FLAG_USER]}')
|
||||
return redirect(f"{current_app.config['URL_HOST']}{hash_callback}")
|
||||
except Exception as e:
|
||||
return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Controller error.\n{e}'})
|
||||
@@ -160,7 +161,7 @@ def logout_callback():
|
||||
# add user to database
|
||||
# DataStore_Store().add_new_user(id_user) # this is part of get basket - should occur on page load
|
||||
|
||||
print(f'user session: {session[Model_View_Base.KEY_USER]}')
|
||||
print(f'user session: {session[Model_View_Base.FLAG_USER]}')
|
||||
return redirect(f'{current_app.URL_HOST}{hash_callback}')
|
||||
except Exception as e:
|
||||
return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_FAILURE, Model_View_Base.FLAG_MESSAGE: f'Controller error.\n{e}'})
|
||||
@@ -171,7 +172,7 @@ def user():
|
||||
try:
|
||||
model = Model_View_User(current_app, db)
|
||||
if not model.is_user_logged_in:
|
||||
# return redirect(url_for('routes_user.login', data = jsonify({ Model_View_User.KEY_CALLBACK: Model_View_User.HASH_PAGE_USER_ACCOUNT })))
|
||||
# return redirect(url_for('routes_user.login', data = jsonify({ Model_View_User.FLAG_CALLBACK: Model_View_User.HASH_PAGE_USER_ACCOUNT })))
|
||||
return redirect(url_for('routes_core.home'))
|
||||
html_body = render_template('pages/user/_user.html', model = model)
|
||||
except Exception as e:
|
||||
|
||||
Binary file not shown.
@@ -154,7 +154,8 @@ class DataStore_Base(BaseModel):
|
||||
return regions, currencies
|
||||
@staticmethod
|
||||
def get_user_session():
|
||||
return User.from_json(session.get(User.KEY_USER))
|
||||
print('DataStore_Base.get_user_session')
|
||||
return User.from_json(session.get(User.FLAG_USER))
|
||||
user = User.get_default()
|
||||
try:
|
||||
print(f'user session: {session[self.app.ID_TOKEN_USER]}')
|
||||
@@ -166,9 +167,11 @@ class DataStore_Base(BaseModel):
|
||||
except:
|
||||
print('get user login failed')
|
||||
return user
|
||||
"""
|
||||
@staticmethod
|
||||
def get_user_auth0():
|
||||
return User.from_json_auth0(session.get(current_app.config['ID_TOKEN_USER']))
|
||||
"""
|
||||
@staticmethod
|
||||
def upload_bulk(permanent_table_name, records, batch_size):
|
||||
_m = 'DataStore_Base.upload_bulk'
|
||||
|
||||
150
datastores/datastore_store_supplier.py
Normal file
150
datastores/datastore_store_supplier.py
Normal file
@@ -0,0 +1,150 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: DataStores
|
||||
Feature: Store Stock Item DataStore
|
||||
|
||||
Description:
|
||||
Datastore for Store Stock Items
|
||||
"""
|
||||
|
||||
# internal
|
||||
# from routes import bp_home
|
||||
import lib.argument_validation as av
|
||||
from business_objects.sql_error import SQL_Error
|
||||
from business_objects.store.supplier import Supplier, Parameters_Supplier, Supplier_Temp
|
||||
from datastores.datastore_store_base import DataStore_Store_Base
|
||||
from helpers.helper_db_mysql import Helper_DB_MySQL
|
||||
# from models.model_view_store_checkout import Model_View_Store_Checkout # circular!
|
||||
from extensions import db
|
||||
# external
|
||||
# from abc import ABC, abstractmethod, abstractproperty
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from sqlalchemy import text
|
||||
import stripe
|
||||
import os
|
||||
from flask import Flask, session, current_app
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from typing import ClassVar
|
||||
from datetime import datetime
|
||||
|
||||
# db = SQLAlchemy()
|
||||
|
||||
|
||||
class DataStore_Store_Supplier(DataStore_Store_Base):
|
||||
# Global constants
|
||||
# Attributes
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
# Stock Items
|
||||
def get_many_supplier(self, parameters_supplier, category_list):
|
||||
# redundant argument validation?
|
||||
_m = 'DataStore_Store_Supplier.get_many_supplier'
|
||||
av.val_instance(parameters_supplier, 'parameters_supplier', _m, Parameters_Supplier)
|
||||
argument_dict = parameters_supplier.to_json()
|
||||
user = self.get_user_session()
|
||||
"""
|
||||
argument_dict['a_id_user'] = user.id_user # 'auth0|6582b95c895d09a70ba10fef' # id_user
|
||||
argument_dict['a_debug'] = 0
|
||||
"""
|
||||
argument_dict = {
|
||||
'a_id_user': user.id_user
|
||||
, **argument_dict
|
||||
, 'a_debug': 0
|
||||
}
|
||||
ids_permutation = category_list.get_csv_ids_permutation()
|
||||
print(f'ids_permutation: {ids_permutation}')
|
||||
argument_dict['a_ids_product_permutation'] = ids_permutation
|
||||
print(f'argument_dict: {argument_dict}')
|
||||
print('executing p_shop_get_many_supplier')
|
||||
result = self.db_procedure_execute('p_shop_get_many_supplier', argument_dict)
|
||||
cursor = result.cursor
|
||||
print('data received')
|
||||
# categories, category_index = DataStore_Store_Supplier.input_many_product(cursor)
|
||||
category_list, errors = DataStore_Store_Supplier.input_many_supplier(cursor, category_list)
|
||||
DataStore_Store_Supplier.db_cursor_clear(cursor)
|
||||
|
||||
return category_list, errors # categories, category_index
|
||||
|
||||
|
||||
def input_many_supplier(cursor, category_list):
|
||||
_m = 'DataStore_Store_Supplier.input_many_supplier'
|
||||
result_set_1 = cursor.fetchall()
|
||||
print(f'raw categories: {result_set_1}')
|
||||
for row in result_set_1:
|
||||
new_supplier = Supplier.from_DB_supplier(row)
|
||||
category_list.add_supplier(new_supplier) # , row)
|
||||
|
||||
# Errors
|
||||
cursor.nextset()
|
||||
result_set_e = cursor.fetchall()
|
||||
print(f'raw errors: {result_set_e}')
|
||||
errors = []
|
||||
if len(result_set_e) > 0:
|
||||
errors = [SQL_Error.from_DB_record(row) for row in result_set_e] # (row[0], row[1])
|
||||
for error in errors:
|
||||
print(f"Error [{error.code}]: {error.msg}")
|
||||
"""
|
||||
if len(errors) > 0:
|
||||
for error in errors:
|
||||
if error.code == 'PRODUCT_AVAILABILITY':
|
||||
ids_permutation_unavailable = DataStore_Store_Supplier.get_ids_permutation_from_error_availability(error.msg)
|
||||
for id_permutation in ids_permutation_unavailable:
|
||||
index_category = category_list.get_index_category_from_id_permutation(id_permutation)
|
||||
category = category_list.categories[index_category]
|
||||
index_product = category.get_index_product_from_id_permutation(id_permutation)
|
||||
product = category.products[index_product]
|
||||
index_permutation = product.get_index_permutation_from_id(id_permutation)
|
||||
permutation = product.permutations[index_permutation]
|
||||
permutation.is_available = False
|
||||
if 'region' in error.msg or 'currency' in error.msg:
|
||||
permutation.is_unavailable_in_currency_or_region = True
|
||||
"""
|
||||
DataStore_Store_Supplier.db_cursor_clear(cursor)
|
||||
return category_list, errors # categories, category_index
|
||||
|
||||
@classmethod
|
||||
def save_suppliers(cls, comment, suppliers):
|
||||
_m = 'DataStore_Store_Supplier.save_suppliers'
|
||||
av.val_str(comment, 'comment', _m)
|
||||
|
||||
guid = Helper_DB_MySQL.create_guid_str()
|
||||
now = datetime.now()
|
||||
user = cls.get_user_session()
|
||||
rows = []
|
||||
for supplier in suppliers:
|
||||
# row = permutation.to_temporary_record()
|
||||
row = Supplier_Temp.from_supplier(supplier)
|
||||
row.guid = guid
|
||||
rows.append(row)
|
||||
|
||||
print(f'rows: {rows}')
|
||||
|
||||
DataStore_Store_Base.upload_bulk(Supplier_Temp.__tablename__, rows, 1000)
|
||||
print('bulk uploaded')
|
||||
|
||||
argument_dict_list = {
|
||||
'a_comment': comment,
|
||||
'a_guid': guid,
|
||||
'a_id_user': user.id_user,
|
||||
'a_debug': 0
|
||||
}
|
||||
result = cls.db_procedure_execute('p_shop_save_supplier', argument_dict_list)
|
||||
print('saved product permutations')
|
||||
|
||||
# Errors
|
||||
cursor = result.cursor
|
||||
cursor.nextset()
|
||||
result_set_e = cursor.fetchall()
|
||||
print(f'raw errors: {result_set_e}')
|
||||
errors = []
|
||||
if len(result_set_e) > 0:
|
||||
errors = [SQL_Error.from_DB_record(row) for row in result_set_e] # (row[0], row[1])
|
||||
for error in errors:
|
||||
print(f"Error [{error.code}]: {error.msg}")
|
||||
DataStore_Store_Supplier.db_cursor_clear(cursor)
|
||||
return errors
|
||||
@@ -1,6 +1,6 @@
|
||||
../../Scripts/pip.exe,sha256=klaXm9Us0xLs-F4HRXu23Q9DlGgpERohNDOIkxFyrus,108466
|
||||
../../Scripts/pip3.12.exe,sha256=klaXm9Us0xLs-F4HRXu23Q9DlGgpERohNDOIkxFyrus,108466
|
||||
../../Scripts/pip3.exe,sha256=klaXm9Us0xLs-F4HRXu23Q9DlGgpERohNDOIkxFyrus,108466
|
||||
../../Scripts/pip.exe,sha256=c7HuPbTodA03BZskKpysGLwtwFjgKiS0ReMoKwJgZMQ,108466
|
||||
../../Scripts/pip3.12.exe,sha256=c7HuPbTodA03BZskKpysGLwtwFjgKiS0ReMoKwJgZMQ,108466
|
||||
../../Scripts/pip3.exe,sha256=c7HuPbTodA03BZskKpysGLwtwFjgKiS0ReMoKwJgZMQ,108466
|
||||
pip-24.0.dist-info/AUTHORS.txt,sha256=SwXm4nkwRkmtnO1ZY-dLy7EPeoQNXMNLby5CN3GlNhY,10388
|
||||
pip-24.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
pip-24.0.dist-info/LICENSE.txt,sha256=Y0MApmnUmurmWxLGxIySTFGkzfPR_whtw0VtyLyqIQQ,1093
|
||||
|
||||
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.
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.
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.
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.
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.
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.
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.
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.
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user