Working on the cart and other related things
This commit is contained in:
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..lib_general import *
|
||||
from ..db_sql import sql_select
|
||||
from ..db_sql import redis_lookup_id_random, sql_select
|
||||
|
||||
from .membership_model import Membership_Cfg_Base
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..lib_general import *
|
||||
from ..db_sql import sql_select
|
||||
from ..db_sql import redis_lookup_id_random, sql_select
|
||||
|
||||
#from .address_model import Address_Base
|
||||
#from .contact_model import Contact_Base
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
from .address_model import Address_Base
|
||||
|
||||
@@ -5,11 +5,67 @@ from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..lib_general import *
|
||||
from ..db_sql import sql_select
|
||||
from ..db_sql import redis_lookup_id_random, sql_insert_or_update, sql_update, sql_select
|
||||
|
||||
from .order_cart_model import Order_Cart_Base
|
||||
|
||||
|
||||
def update_order_cart_obj(order_cart_obj:Order_Cart_Base, repl_order_cart_line_li:bool=False):
|
||||
if order_cart_obj.account_id_random and (order_cart_obj.person_id_random or order_cart_obj.user_id_random):
|
||||
log.info(f'An account.id_random {order_cart_obj.account_id_random} was passed. And either a person.id_random {order_cart_obj.person_id_random} or user.id_random {order_cart_obj.user_id_random} was passed. We can update the order cart.')
|
||||
else:
|
||||
log.error('An account ID along with a person ID or user ID is required to create an order.')
|
||||
return False
|
||||
|
||||
#if order_cart_id := redis_lookup_id_random(record_id_random=order_cart_id_random, table_name='order_cart'): pass
|
||||
#else: return False
|
||||
|
||||
order_cart_id_random = order_cart_obj.id_random # id_random because can't ref the alias
|
||||
|
||||
# Calculate totals
|
||||
order_cart_total_amount:int = 0
|
||||
order_cart_total_quantity:int = 0
|
||||
for order_cart_line_obj in order_cart_obj.order_cart_line_li:
|
||||
order_cart_total_amount += order_cart_line_obj.quantity * order_cart_line_obj.amount
|
||||
order_cart_total_quantity += order_cart_line_obj.quantity
|
||||
|
||||
order_cart_line_obj.order_cart_id_random = order_cart_id_random
|
||||
|
||||
order_cart_line_obj_data = order_cart_line_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'order_cart_line_id_random', 'product_type_id', 'product_type', 'created_on', 'updated_on'})
|
||||
|
||||
#order_cart_line_obj_data['order_id'] = order_cart_id
|
||||
|
||||
if order_cart_line_obj_resp := sql_insert_or_update(data=order_cart_line_obj_data, table_name='order_cart_line', rm_id_random=True, id_random_length=8): pass
|
||||
else:
|
||||
log.error('Something went wrong while trying to insert or update an order cart line record.')
|
||||
return False
|
||||
|
||||
#log.debug(order_cart_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'order_cart_line_li', 'cfg', 'created_on', 'updated_on'}))
|
||||
#order_cart_obj_data = order_cart_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'order_cart_line_li', 'cfg', 'created_on', 'updated_on'})
|
||||
|
||||
order_cart_obj_new = {}
|
||||
order_cart_obj_new['id_random'] = order_cart_id_random
|
||||
order_cart_obj_new['account_id_random'] = order_cart_obj.account_id_random
|
||||
order_cart_obj_new['person_id_random'] = order_cart_obj.person_id_random
|
||||
order_cart_obj_new['user_id_random'] = order_cart_obj.person_id_random
|
||||
|
||||
order_cart_obj_new['order_id_random'] = order_cart_obj.order_id_random
|
||||
|
||||
order_cart_obj_new['total_amount'] = order_cart_total_amount
|
||||
order_cart_obj_new['total_quantity'] = order_cart_total_quantity
|
||||
|
||||
order_cart_obj_new['notes'] = order_cart_obj.notes
|
||||
|
||||
if order_cart_obj_resp := sql_update(data=order_cart_obj_new, table_name='order_cart', rm_id_random=True): pass
|
||||
else:
|
||||
log.error('Something went wrong while trying to update an order cart record.')
|
||||
return False
|
||||
|
||||
|
||||
|
||||
return False
|
||||
|
||||
|
||||
# ### BEGIN ### API Order Cart Methods ### load_order_cart_obj() ###
|
||||
def load_order_cart_obj(order_cart_id:int|str, inc_order_cart_line_li:bool=False, inc_order_cart_cfg:bool=False) -> Order_Cart_Base:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
@@ -26,7 +82,7 @@ def load_order_cart_obj(order_cart_id:int|str, inc_order_cart_line_li:bool=False
|
||||
order_cart_line_data = {}
|
||||
order_cart_line_data['order_cart_id'] = order_cart_id
|
||||
if order_cart_line_rec_li := sql_select(table_name='v_order_cart_line', data=order_cart_line_data, as_list=True):
|
||||
order_cart_rec['order_cart_line_list'] = order_cart_line_rec_li
|
||||
order_cart_rec['order_cart_line_li'] = order_cart_line_rec_li
|
||||
|
||||
if inc_order_cart_cfg:
|
||||
if order_cart_cfg_rec := sql_select(table_name='v_account_cfg_detail', field_name='account_id', field_value=order_cart_rec.get('account_id', None)):
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
@@ -95,6 +95,92 @@ class Order_Cart_Line_Base(BaseModel):
|
||||
fields = base_fields
|
||||
|
||||
|
||||
class Order_Cart_DB_Base(BaseModel):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
id_random: Optional[str] = Field(
|
||||
**base_fields['order_cart_id_random'],
|
||||
alias='order_cart_id_random',
|
||||
default_factory=lambda:secrets.token_urlsafe(default_num_bytes),
|
||||
)
|
||||
id: Optional[int] = Field(
|
||||
#alias='order_cart_id'
|
||||
)
|
||||
|
||||
account_id_random: Optional[str]
|
||||
account_id: Optional[int] # NOTE: This is not really optional
|
||||
person_id_random: Optional[str]
|
||||
person_id: Optional[int]
|
||||
user_id_random: Optional[str]
|
||||
user_id: Optional[int]
|
||||
order_id_random: Optional[str]
|
||||
order_id: Optional[int]
|
||||
total_quantity: Optional[int] = Field(0, ge=0, lt=150)
|
||||
total_amount: Optional[int] = Field(0, ge=0, lt=1500000)
|
||||
notes: Optional[str]
|
||||
|
||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||
|
||||
#@validator('order_cart_id_random', always=True)
|
||||
def order_cart_id_random_copy(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if values['id_random']:
|
||||
return values['id_random']
|
||||
return None
|
||||
|
||||
@validator('id', always=True)
|
||||
def order_cart_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if values['id_random']:
|
||||
return redis_lookup_id_random(record_id_random=values['id_random'], table_name='order_cart')
|
||||
return None
|
||||
|
||||
@validator('account_id', always=True)
|
||||
def account_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if values['account_id_random']:
|
||||
return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account')
|
||||
return None
|
||||
|
||||
@validator('person_id', always=True)
|
||||
def person_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if values['person_id_random']:
|
||||
return redis_lookup_id_random(record_id_random=values['person_id_random'], table_name='person')
|
||||
return None
|
||||
|
||||
@validator('user_id', always=True)
|
||||
def user_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if values['user_id_random']:
|
||||
return redis_lookup_id_random(record_id_random=values['user_id_random'], table_name='user')
|
||||
return None
|
||||
|
||||
@validator('order_id', always=True)
|
||||
def order_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if 'order_id_random' in values and values['order_id_random']:
|
||||
return redis_lookup_id_random(record_id_random=values['order_id_random'], table_name='order')
|
||||
return None
|
||||
|
||||
class Config:
|
||||
underscore_attrs_are_private = True
|
||||
fields = base_fields
|
||||
|
||||
|
||||
class Order_Cart_Base(BaseModel):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
@@ -124,7 +210,7 @@ class Order_Cart_Base(BaseModel):
|
||||
created_on: Optional[datetime.datetime] = None
|
||||
updated_on: Optional[datetime.datetime] = None
|
||||
|
||||
order_cart_line_list: List[Order_Cart_Line_Base] = []
|
||||
order_cart_line_li: List[Order_Cart_Line_Base] = []
|
||||
|
||||
cfg: Optional[Order_Cart_Cfg_Base] = Order_Cart_Cfg_Base()
|
||||
|
||||
@@ -199,7 +285,7 @@ def save_order_cart_obj(order_cart_obj_new=None):
|
||||
|
||||
#log.debug(order_cart_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True))
|
||||
|
||||
# Get the current order_cart_line list to compare with what was sent
|
||||
# Get the current order_cart_line li to compare with what was sent
|
||||
data = {}
|
||||
data['order_cart_id_random'] = order_cart_obj_new.id_random
|
||||
if order_cart_line_rec_li_curr := sql_select(table_name='v_order_cart_line', data=data, rm_id_random=True, as_list=True):
|
||||
@@ -225,7 +311,7 @@ def save_order_cart_obj(order_cart_obj_new=None):
|
||||
# Loop through the line list that was sent and compare with what was pulled from the DB
|
||||
# Only insert if a product ID does not match
|
||||
# Only update if a product ID does match
|
||||
for order_cart_line_obj_new in order_cart_obj_new.order_cart_line_list:
|
||||
for order_cart_line_obj_new in order_cart_obj_new.order_cart_line_li:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
if not any(order_cart_line_obj_curr.product_id_random == order_cart_line_obj_new.product_id_random for order_cart_line_obj_curr in order_cart_line_obj_li_curr):
|
||||
# Need to append to current list
|
||||
@@ -244,7 +330,7 @@ def save_order_cart_obj(order_cart_obj_new=None):
|
||||
log.info(f'Not a match: {order_cart_line_obj_curr.product_id_random}')
|
||||
|
||||
# Save merged current and new list to the new order cart object
|
||||
order_cart_obj_new.order_cart_line_list = order_cart_line_obj_li_curr
|
||||
order_cart_obj_new.order_cart_line_li = order_cart_line_obj_li_curr
|
||||
log.debug(order_cart_obj_new)
|
||||
|
||||
# Final loop through to get the new order totals
|
||||
@@ -258,8 +344,8 @@ def save_order_cart_obj(order_cart_obj_new=None):
|
||||
order_cart_obj_new.total_amount = order_cart_total_amount
|
||||
order_cart_obj_new.total_quantity = order_cart_total_quantity
|
||||
|
||||
log.debug(order_cart_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'order_cart_id_random', 'order_cart_line_list', 'cfg', 'created_on', 'updated_on'}))
|
||||
order_cart_obj_data = order_cart_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'order_cart_id_random', 'order_cart_line_list', 'cfg', 'created_on', 'updated_on'})
|
||||
log.debug(order_cart_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'order_cart_id_random', 'order_cart_line_li', 'cfg', 'created_on', 'updated_on'}))
|
||||
order_cart_obj_data = order_cart_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'order_cart_id_random', 'order_cart_line_li', 'cfg', 'created_on', 'updated_on'})
|
||||
|
||||
# SQL INSERT or UPDATE the order_cart record
|
||||
log.info('SQL INSERT or UPDATE the order_cart record')
|
||||
@@ -278,7 +364,7 @@ def save_order_cart_obj(order_cart_obj_new=None):
|
||||
|
||||
# Loop through the order_cart_line list to SQL INSERT or UPDATE the records
|
||||
log.info('Loop through the order_cart_line list to SQL INSERT or UPDATE the records')
|
||||
for order_cart_line_obj in order_cart_obj_new.order_cart_line_list:
|
||||
for order_cart_line_obj in order_cart_obj_new.order_cart_line_li:
|
||||
log.debug(f"--- {order_cart_line_obj}")
|
||||
log.debug(order_cart_line_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=False, exclude={}))
|
||||
|
||||
@@ -310,7 +396,7 @@ def get_order_cart_obj(order_cart_id=None, inc_order_cart_line_li=None, inc_orde
|
||||
order_cart_line_data = {}
|
||||
order_cart_line_data['order_cart_id'] = order_cart_id
|
||||
if order_cart_line_rec_li := sql_select(table_name='v_order_cart_line', data=order_cart_line_data, as_list=True):
|
||||
order_cart_rec['order_cart_line_list'] = order_cart_line_rec_li
|
||||
order_cart_rec['order_cart_line_li'] = order_cart_line_rec_li
|
||||
|
||||
if inc_order_cart_cfg:
|
||||
if order_cart_cfg_rec := sql_select(table_name='v_account_cfg_detail', field_name='account_id', field_value=order_cart_rec.get('account_id', None)):
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..lib_general import *
|
||||
from ..db_sql import sql_select
|
||||
from ..db_sql import redis_lookup_id_random, sql_select
|
||||
|
||||
from .order_model import Order_Base
|
||||
#from .person_model import Person_Base
|
||||
@@ -13,7 +13,7 @@ from .order_model import Order_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API Order Model ### save_order_obj() ###
|
||||
def save_order_obj(order_obj_new:Order_Base, repl_order_line_list:bool=False):
|
||||
def save_order_obj(order_obj_new:Order_Base, repl_order_line_li:bool=False):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
@@ -51,12 +51,12 @@ def save_order_obj(order_obj_new:Order_Base, repl_order_line_list:bool=False):
|
||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(order_line_obj_li_curr)
|
||||
|
||||
if repl_order_line_list: # This will remove any order line list items not sent with the new order information.
|
||||
if repl_order_line_li: # This will remove any order line list items not sent with the new order information.
|
||||
log.info('Removing any order line list items not sent with the new order information...')
|
||||
for index, order_line_obj_curr in enumerate(order_line_obj_li_curr):
|
||||
log.info(f'Current: order line ID={order_line_obj_curr.id_random} and product ID= {order_line_obj_curr.product_id_random}')
|
||||
matched_product_id = False
|
||||
for order_line_obj_new in order_obj_new.order_line_list:
|
||||
for order_line_obj_new in order_obj_new.order_line_li:
|
||||
log.debug(f'Checking new: product ID={order_line_obj_new.product_id_random}')
|
||||
|
||||
if order_line_obj_curr.product_id_random == order_line_obj_new.product_id_random:
|
||||
@@ -82,7 +82,7 @@ def save_order_obj(order_obj_new:Order_Base, repl_order_line_list:bool=False):
|
||||
# Loop through the new line list that was sent and compare with the current line list that was pulled from the DB
|
||||
# Only insert if a product ID does not match
|
||||
# Only update if a product ID does match
|
||||
for order_line_obj_new in order_obj_new.order_line_list:
|
||||
for order_line_obj_new in order_obj_new.order_line_li:
|
||||
log.info(f'New: order line ID={order_line_obj_new.id_random} and product ID= {order_line_obj_new.product_id_random}')
|
||||
matched_product_id = False
|
||||
for index, order_line_obj_curr in enumerate(order_line_obj_li_curr):
|
||||
@@ -105,14 +105,14 @@ def save_order_obj(order_obj_new:Order_Base, repl_order_line_list:bool=False):
|
||||
order_line_obj_li_curr.append(order_line_obj_new) # These will be inserted/updated below
|
||||
|
||||
# Save merged current and new list to the new order object
|
||||
order_obj_new.order_line_list = order_line_obj_li_curr
|
||||
order_obj_new.order_line_li = order_line_obj_li_curr
|
||||
log.debug(order_obj_new)
|
||||
|
||||
# Final loop through to get the new order totals
|
||||
# Calculate totals
|
||||
order_total_amount:int = 0
|
||||
order_total_quantity:int = 0
|
||||
for order_line_obj_new in order_obj_new.order_line_list:
|
||||
for order_line_obj_new in order_obj_new.order_line_li:
|
||||
order_total_amount += order_line_obj_new.quantity * order_line_obj_new.amount
|
||||
order_total_quantity += order_line_obj_new.quantity
|
||||
|
||||
@@ -120,8 +120,8 @@ def save_order_obj(order_obj_new:Order_Base, repl_order_line_list:bool=False):
|
||||
order_obj_new.total_quantity = order_total_quantity
|
||||
order_obj_new.balance = order_total_amount - order_obj_new.total_paid
|
||||
|
||||
log.debug(order_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'order_line_list', 'cfg', 'created_on', 'updated_on'}))
|
||||
order_obj_data = order_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'order_line_list', 'cfg', 'created_on', 'updated_on'})
|
||||
log.debug(order_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'order_line_li', 'cfg', 'created_on', 'updated_on'}))
|
||||
order_obj_data = order_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'order_line_li', 'cfg', 'created_on', 'updated_on'})
|
||||
|
||||
# SQL INSERT or UPDATE the order record
|
||||
log.info('SQL INSERT or UPDATE the order record')
|
||||
@@ -141,7 +141,7 @@ def save_order_obj(order_obj_new:Order_Base, repl_order_line_list:bool=False):
|
||||
|
||||
# Loop through the order_line list to SQL INSERT or UPDATE the records
|
||||
log.info('Loop through the order_line list to SQL INSERT or UPDATE the records')
|
||||
for order_line_obj_new in order_obj_new.order_line_list:
|
||||
for order_line_obj_new in order_obj_new.order_line_li:
|
||||
log.info(f"New order_line: order_line_id_random={order_line_obj_new.id_random}; product_id_random={order_line_obj_new.product_id_random}")
|
||||
log.debug(order_line_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=False, exclude={'order_line_id_random', 'product_type_id', 'product_type', 'created_on', 'updated_on'}))
|
||||
|
||||
@@ -174,7 +174,7 @@ def load_order_obj(order_id:int|str, inc_order_line_li:bool=False, inc_order_cfg
|
||||
order_line_data['order_id'] = order_id
|
||||
if order_line_rec_li := sql_select(table_name='v_order_line', data=order_line_data, as_list=True):#, field_name='order_id', field_value=order_id):
|
||||
log.debug(order_line_rec_li)
|
||||
order_rec['order_line_list'] = order_line_rec_li
|
||||
order_rec['order_line_li'] = order_line_rec_li
|
||||
|
||||
if inc_order_cfg:
|
||||
if order_cfg_rec := sql_select(table_name='v_account_cfg_detail', field_name='account_id', field_value=order_rec.get('account_id', None)):
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
#from .supporting_core_models import *
|
||||
@@ -138,7 +138,7 @@ class Order_Base(BaseModel):
|
||||
created_on: Optional[datetime.datetime] = None
|
||||
updated_on: Optional[datetime.datetime] = None
|
||||
|
||||
order_line_list: List[Order_Line_Base] = []
|
||||
order_line_li: List[Order_Line_Base] = []
|
||||
|
||||
cfg: Optional[Order_Cfg_Base] = Order_Cfg_Base()
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
#from .account_model import Account_Base
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..lib_general import *
|
||||
from ..db_sql import sql_select
|
||||
from ..db_sql import redis_lookup_id_random, sql_select
|
||||
|
||||
from .person_model import Person_Base
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
# from .account_model import Account_Base
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from app.config import settings
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
#from .site_model import Site_Base as Site_Base_2
|
||||
|
||||
@@ -4,8 +4,8 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
from .site_domain_model import Site_Domain_Base as Site_Domain_Base_2
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..lib_general import *
|
||||
from ..db_sql import sql_select
|
||||
from ..db_sql import redis_lookup_id_random, sql_select
|
||||
|
||||
from .user_model import User_Base, User_Out_Base, User_New_Base
|
||||
from .user_role_model import User_Role_Base
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||
|
||||
from ..db_sql import redis_lookup_id_random
|
||||
from ..lib_general import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
Reference in New Issue
Block a user