Working on orders and order carts

This commit is contained in:
Scott Idem
2021-08-06 18:53:24 -04:00
parent 5746d8d34b
commit 17cb6786f8
3 changed files with 23 additions and 22 deletions

View File

@@ -126,7 +126,7 @@ def update_order_cart_obj(
def load_order_cart_obj( def load_order_cart_obj(
order_cart_id: int|str, order_cart_id: int|str,
inc_order_cart_line_list: bool = False, inc_order_cart_line_list: bool = False,
inc_order_cart_cfg: bool = False, inc_order_cfg: bool = False,
) -> Order_Cart_Base|dict|bool: ) -> Order_Cart_Base|dict|bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -145,9 +145,9 @@ def load_order_cart_obj(
order_cart_rec['order_cart_line_list'] = order_cart_line_rec_li order_cart_rec['order_cart_line_list'] = order_cart_line_rec_li
else: order_cart_rec['order_cart_line_list'] = [] else: order_cart_rec['order_cart_line_list'] = []
if inc_order_cart_cfg: if inc_order_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)): if order_cfg_rec := sql_select(table_name='v_account_cfg_detail', field_name='account_id', field_value=order_cart_rec.get('account_id', None)):
order_cart_rec['cfg'] = order_cart_cfg_rec order_cart_rec['cfg'] = order_cfg_rec
else: order_cart_rec['cfg'] = None else: order_cart_rec['cfg'] = None
log.debug(order_cart_rec) log.debug(order_cart_rec)
@@ -273,7 +273,7 @@ def old_save_order_cart_obj(order_cart_obj_new=None):
# IS THIS STILL NEEDED? # IS THIS STILL NEEDED?
# ### BEGIN ### API Order Cart Model ### get_order_cart_obj() ### # ### BEGIN ### API Order Cart Model ### get_order_cart_obj() ###
def old_get_order_cart_obj(order_cart_id=None, inc_order_cart_line_list=None, inc_order_cart_cfg=None): def old_get_order_cart_obj(order_cart_id=None, inc_order_cart_line_list=None, inc_order_cfg=None):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -291,9 +291,9 @@ def old_get_order_cart_obj(order_cart_id=None, inc_order_cart_line_list=None, in
if order_cart_line_rec_li := sql_select(table_name='v_order_cart_line', data=order_cart_line_data, as_list=True): 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_list'] = order_cart_line_rec_li
if inc_order_cart_cfg: if inc_order_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)): if order_cfg_rec := sql_select(table_name='v_account_cfg_detail', field_name='account_id', field_value=order_cart_rec.get('account_id', None)):
order_cart_rec['cfg'] = order_cart_cfg_rec order_cart_rec['cfg'] = order_cfg_rec
log.debug(order_cart_rec) log.debug(order_cart_rec)
else: else:

View File

@@ -8,16 +8,17 @@ from app.db_sql import redis_lookup_id_random
from app.lib_general import * from app.lib_general import *
from .common_field_schema import base_fields, default_num_bytes from .common_field_schema import base_fields, default_num_bytes
from .order_models import Order_Cfg_Base
class Order_Cart_Cfg_Base(BaseModel): # class Order_Cfg_Base(BaseModel):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL # log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) # log.debug(locals())
account_name: Optional[str] # account_name: Optional[str]
show_cart: Optional[bool] # show_cart: Optional[bool]
cart_label: Optional[str] # cart_label: Optional[str]
class Order_Cart_Line_Base(BaseModel): class Order_Cart_Line_Base(BaseModel):
@@ -230,7 +231,7 @@ class Order_Cart_Base(BaseModel):
# Including other related objects # Including other related objects
order_cart_line_list: Optional[list[Order_Cart_Line_Base]] # Order_Line_Base() # List[Order_Cart_Line_Base] = [] order_cart_line_list: Optional[list[Order_Cart_Line_Base]] # Order_Line_Base() # List[Order_Cart_Line_Base] = []
cfg: Optional[Order_Cart_Cfg_Base] = Order_Cart_Cfg_Base() # Should this be renamed to order_cart_cfg? cfg: Optional[Order_Cfg_Base] = Order_Cfg_Base() # Should this be renamed to order_cfg?
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now) _processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)

View File

@@ -53,7 +53,7 @@ async def patch_order_cart_obj(
x_account_id: Optional[str] = Header(..., ), x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True, return_obj: Optional[bool] = True,
inc_order_cart_line_list: Optional[bool] = True, inc_order_cart_line_list: Optional[bool] = True,
inc_order_cart_cfg: Optional[bool] = True, inc_order_cfg: Optional[bool] = True,
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True, exclude_unset: Optional[bool] = True,
): ):
@@ -80,7 +80,7 @@ async def patch_order_cart_obj(
if order_cart_obj := load_order_cart_obj( if order_cart_obj := load_order_cart_obj(
order_cart_id = order_cart_id, order_cart_id = order_cart_id,
inc_order_cart_line_list = inc_order_cart_line_list, inc_order_cart_line_list = inc_order_cart_line_list,
inc_order_cart_cfg = inc_order_cart_cfg inc_order_cfg = inc_order_cfg
): ):
data = order_cart_obj.dict(by_alias=True, exclude_unset=False) data = order_cart_obj.dict(by_alias=True, exclude_unset=False)
return mk_resp(data=data) return mk_resp(data=data)
@@ -119,7 +119,7 @@ async def lookup_order_cart_obj(
for_obj_type: Optional[str] = Query(None, min_length=2, max_length=50), for_obj_type: Optional[str] = Query(None, min_length=2, max_length=50),
for_obj_id: Optional[Union[int,str]] = None, for_obj_id: Optional[Union[int,str]] = None,
inc_order_cart_line_list: Optional[bool] = True, inc_order_cart_line_list: Optional[bool] = True,
inc_order_cart_cfg: Optional[bool] = True, inc_order_cfg: Optional[bool] = True,
x_account_id: str = Header(...), x_account_id: str = Header(...),
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True, exclude_unset: Optional[bool] = True,
@@ -173,7 +173,7 @@ async def lookup_order_cart_obj(
if order_cart_obj := load_order_cart_obj( if order_cart_obj := load_order_cart_obj(
order_cart_id = order_cart_id, order_cart_id = order_cart_id,
inc_order_cart_line_list = inc_order_cart_line_list, inc_order_cart_line_list = inc_order_cart_line_list,
inc_order_cart_cfg = inc_order_cart_cfg, inc_order_cfg = inc_order_cfg,
): ):
data = order_cart_obj.dict(by_alias=True, exclude_unset=False) data = order_cart_obj.dict(by_alias=True, exclude_unset=False)
return mk_resp(data=data) return mk_resp(data=data)
@@ -187,7 +187,7 @@ async def lookup_order_cart_obj(
load_order_cart_obj( load_order_cart_obj(
order_cart_id = order_cart_id, order_cart_id = order_cart_id,
inc_order_cart_line_list = inc_order_cart_line_list, inc_order_cart_line_list = inc_order_cart_line_list,
inc_order_cart_cfg = inc_order_cart_cfg, inc_order_cfg = inc_order_cfg,
) )
) )
data = order_cart_obj_li data = order_cart_obj_li
@@ -202,7 +202,7 @@ async def lookup_order_cart_obj(
async def get_order_cart_obj( async def get_order_cart_obj(
order_cart_id: str = Query(..., min_length=1, max_length=22), order_cart_id: str = Query(..., min_length=1, max_length=22),
inc_order_cart_line_list: bool = False, inc_order_cart_line_list: bool = False,
inc_order_cart_cfg: bool = False, inc_order_cfg: bool = False,
x_account_id: str = Header(...), x_account_id: str = Header(...),
by_alias: bool = True, by_alias: bool = True,
exclude_unset: bool = True, exclude_unset: bool = True,
@@ -213,7 +213,7 @@ async def get_order_cart_obj(
if order_cart_obj := load_order_cart_obj( if order_cart_obj := load_order_cart_obj(
order_cart_id = order_cart_id, order_cart_id = order_cart_id,
inc_order_cart_line_list = inc_order_cart_line_list, inc_order_cart_line_list = inc_order_cart_line_list,
inc_order_cart_cfg = inc_order_cart_cfg, inc_order_cfg = inc_order_cfg,
): ):
data = order_cart_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) data = order_cart_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset)
return mk_resp(data=data) return mk_resp(data=data)