Work on person related information, order, and order_cart
This commit is contained in:
@@ -253,6 +253,34 @@ def get_order_cart_rec_list(
|
||||
# ### END ### API Order Cart Methods ### get_order_cart_rec_list() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Order Cart Methods ### get_order_cart_id_for_person_id() ###
|
||||
# Updated 2021-11-16
|
||||
def get_order_cart_id_for_person_id(
|
||||
person_id: int|str,
|
||||
) -> bool|int|None:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
|
||||
else: return False
|
||||
|
||||
data = {}
|
||||
data['person_id'] = person_id
|
||||
|
||||
sql = f"""
|
||||
SELECT `order_cart`.id AS 'order_cart_id', `order_cart`.id_random AS 'order_cart_id_random', `order_cart`.person_id AS person_id
|
||||
FROM `order_cart` AS `order_cart`
|
||||
WHERE `order_cart`.person_id = :person_id
|
||||
LIMIT 1;
|
||||
"""
|
||||
|
||||
if order_cart_data_result := sql_select(data=data, sql=sql):
|
||||
log.debug(order_cart_data_result)
|
||||
if order_cart_id := order_cart_data_result.get('order_cart_id', None): return order_cart_id
|
||||
else: return False
|
||||
else: return None
|
||||
# ### END ### API Order Cart Methods ### get_order_cart_id_for_person_id() ###
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -283,7 +283,7 @@ def get_order_rec_list(
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
from_datetime: datetime.datetime = None,
|
||||
to_datetime: datetime.datetime = None,
|
||||
status: str = 'complete', # started, in progress, complete, all
|
||||
status: str = 'closed', # started, in progress, complete, all
|
||||
balance_gt: int = 0, # $0 to $99999
|
||||
) -> list|bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
@@ -296,14 +296,19 @@ def get_order_rec_list(
|
||||
# data['for_obj_type'] = for_obj_type
|
||||
sql_obj_type_id = f'`tbl`.{for_obj_type}_id = :{for_obj_type}_id'
|
||||
|
||||
allowed_status_li = ['started', 'in progress', 'complete', 'all']
|
||||
# allowed_status_li = ['started', 'in progress', 'complete', 'all'] # OLD list
|
||||
# allowed_status_li = ['open', 'locked', 'reopened', 'closed', 'canceled', 'other'] # NEW list
|
||||
allowed_status_li = ['open', 'locked', 'in progress', 'reopened', 'closed', 'complete', 'canceled', 'other'] # TEMPORARY list...
|
||||
sql_status = ''
|
||||
if status in allowed_status_li:
|
||||
if status == 'status':
|
||||
data['status'] = True
|
||||
sql_status = f'AND `tbl`.status = :status'
|
||||
elif status == 'disabled':
|
||||
data['status'] = False
|
||||
if status == 'closed' or status == 'complete':
|
||||
data['status'] = ['closed', 'complete']
|
||||
sql_status = f'AND `tbl`.status IN :status'
|
||||
elif status == 'locked' or status == 'in progress':
|
||||
data['status'] = ['locked', 'in progress']
|
||||
sql_status = f'AND `tbl`.status IN :status'
|
||||
else:
|
||||
data['status'] = status
|
||||
sql_status = f'AND `tbl`.status = :status'
|
||||
elif status == 'all':
|
||||
sql_status = ''
|
||||
|
||||
@@ -9,7 +9,8 @@ from app.lib_general import log, logging
|
||||
|
||||
# from app.methods.address_methods import load_address_obj
|
||||
from app.methods.contact_methods import create_contact_obj, create_update_contact_obj, create_update_contact_obj_v4, load_contact_obj, update_contact_obj
|
||||
from app.methods.order_methods import load_order_obj, get_order_rec_list
|
||||
from app.methods.order_cart_methods import get_order_cart_id_for_person_id, load_order_cart_obj
|
||||
from app.methods.order_methods import get_order_rec_list, load_order_obj
|
||||
from app.methods.organization_methods import create_update_organization_obj, load_organization_obj, update_organization_obj
|
||||
# from app.methods.user_methods import create_user_obj # , load_user_obj, update_user_obj
|
||||
|
||||
@@ -45,9 +46,10 @@ def load_person_obj(
|
||||
inc_membership_type_list: bool = False,
|
||||
inc_membership_type_person_list: bool = False,
|
||||
inc_order_cfg: bool = False,
|
||||
inc_order_closed_count: bool = False,
|
||||
inc_order_line_list: bool = False,
|
||||
inc_order_list: bool = False,
|
||||
inc_order_cart_list: bool = False,
|
||||
inc_order_cart: bool = False,
|
||||
inc_organization: bool = False,
|
||||
inc_post_list: bool = False,
|
||||
inc_post_comment_list: bool = False,
|
||||
@@ -180,6 +182,37 @@ def load_person_obj(
|
||||
# type_obj.membership_type_list = membership_type_result_list
|
||||
# else: type_obj.membership_type_list = []
|
||||
|
||||
# Updated 2021-11-16
|
||||
if inc_order_cart:
|
||||
log.info('Need to include order cart...')
|
||||
if order_cart_id := get_order_cart_id_for_person_id(
|
||||
person_id = person_id,
|
||||
):
|
||||
if order_cart_result := load_order_cart_obj(
|
||||
order_cart_id = order_cart_id,
|
||||
inc_order_cart_line_list = True,
|
||||
):
|
||||
person_obj.order_cart = order_cart_result
|
||||
else: person_obj.order_cart = None
|
||||
|
||||
# Updated 2021-11-16
|
||||
if inc_order_closed_count:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.info('Need to include order closed count...')
|
||||
log.debug(person_obj)
|
||||
if order_rec_list_result := get_order_rec_list(
|
||||
for_obj_type = 'person',
|
||||
for_obj_id = person_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
status = 'closed'
|
||||
):
|
||||
person_obj.orders_info = {}
|
||||
person_obj.orders_info['closed_count'] = len(order_rec_list_result)
|
||||
else:
|
||||
person_obj.orders_info = {}
|
||||
person_obj.orders_info['closed_count'] = None
|
||||
|
||||
# Updated 2021-06-18
|
||||
if inc_order_list:
|
||||
log.info('Need to include order list data...')
|
||||
|
||||
@@ -122,8 +122,9 @@ class Person_Base(BaseModel):
|
||||
membership_type_person_list: Optional[list] # Membership_Type_Person_Base() list of member type person records... for now this should be only one at most.
|
||||
membership_group_list: Optional[list] # Membership_Group_Base() list of member groups the person has
|
||||
membership_group_person_list: Optional[list] # Membership_Group_Person_Base() list of member group person records
|
||||
orders_info: Optional[dict] # closed_count, etc
|
||||
order_list: Optional[list] # Order_Base() # Priority l2
|
||||
order_cart_list: Optional[list] # Order_Base() # Priority l2
|
||||
order_cart: Optional[dict] # Order_Cart_Base() # Priority l2
|
||||
organization: Optional[Union[Organization_Base, None]]
|
||||
post_list: Optional[list] # Post_Base() # Priority l1
|
||||
user: Optional[dict] # Optional[Union[User_Base, None]]
|
||||
|
||||
@@ -397,9 +397,11 @@ async def get_person_obj(
|
||||
inc_membership_type_person: bool = False,
|
||||
# inc_membership_type_list: bool = False, # The list of all membership types a person is a part of
|
||||
# inc_membership_type_person_list: bool = False,
|
||||
inc_order_closed_count: bool = False, # NEW Priority l1
|
||||
inc_order_line_list: bool = False, # Priority l1
|
||||
inc_order_list: bool = False, # Priority l1
|
||||
inc_order_cart_list: bool = False, # Priority l1
|
||||
inc_order_cart: bool = False, # NEW Priority l1
|
||||
# inc_order_cart_list: bool = False, # Priority l1
|
||||
inc_organization: bool = False, # Priority l1
|
||||
# inc_organization_list: bool = False,
|
||||
inc_post_list: bool = False, # Priority l2
|
||||
@@ -435,9 +437,11 @@ async def get_person_obj(
|
||||
inc_membership_person_profile = inc_membership_person_profile,
|
||||
inc_membership_type = inc_membership_type,
|
||||
inc_membership_type_person = inc_membership_type_person,
|
||||
inc_order_closed_count = inc_order_closed_count,
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
inc_order_list = inc_order_list,
|
||||
inc_order_cart_list = inc_order_cart_list,
|
||||
inc_order_cart = inc_order_cart,
|
||||
# inc_order_cart_list = inc_order_cart_list,
|
||||
inc_organization = inc_organization,
|
||||
# inc_organization_list = inc_organization_list,
|
||||
inc_post_list = inc_post_list,
|
||||
|
||||
Reference in New Issue
Block a user