Working on redoing order to get rid of order_cart.

This commit is contained in:
Scott Idem
2021-08-09 20:16:07 -04:00
parent 1dba813d4b
commit 73466456ee
11 changed files with 272 additions and 27 deletions

View File

@@ -28,12 +28,16 @@ class Order_Cart_Line_Base(BaseModel):
product_id_random: str
product_id: Optional[int]
product_for_type: Optional[str] # Copied from product record
product_for_id_random: Optional[str] # Copied from product record
product_for_id: Optional[int] # Copied from product record
product_type_id: Optional[int] # Copied from product record
product_type: Optional[str] # Copied from product record; dup from look up? probably not use?
product_type_code: Optional[str] # Copied from product record; from look up
product_type_name: Optional[str] # Copied from product record; from look up
product_name: Optional[str] # Copied from product record
product_description: Optional[str] # Copied from product record
product_unit_price: Optional[int] # Copied from product record
@@ -41,12 +45,16 @@ class Order_Cart_Line_Base(BaseModel):
curr_product_id_random: Optional[str] # Should be the same as product_id_random above
curr_product_id: Optional[int] # Should be the same as product_id above
curr_product_for_type: Optional[str] # Dynamic from v_order_current_line
curr_product_for_id_random: Optional[str] # Dynamic from v_order_current_line
curr_product_for_id: Optional[int] # Dynamic from v_order_current_line
curr_product_type_id: Optional[int] # Dynamic from v_order_current_line
curr_product_type: Optional[str] # Dynamic from v_order_current_line
curr_product_type_code: Optional[str] # Dynamic from v_order_current_line
curr_product_type_name: Optional[str] # Dynamic from v_order_current_line
curr_product_name: Optional[str] # Dynamic from v_order_current_line
curr_product_description: Optional[str] # Dynamic from v_order_current_line
curr_product_unit_price: Optional[int] # Dynamic from v_order_current_line
@@ -143,3 +151,50 @@ class Order_Cart_Line_Base(BaseModel):
underscore_attrs_are_private = True
allow_population_by_field_name = True
fields = base_fields
class Order_Cart_Line_DB_Base(BaseModel):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
id_random: Optional[str] = Field(
alias = 'order_cart_line_id_random',
)
id: Optional[int] = Field(
alias = 'order_cart_line_id'
)
order_cart_id_random: Optional[str]
order_cart_id: Optional[int]
product_id_random: str
product_id: Optional[int]
product_for_type: Optional[str] # Copied from product record
product_for_id_random: Optional[str] # Copied from product record
product_for_id: Optional[int] # Copied from product record
product_type_id: Optional[int] # Copied from product record
product_name: Optional[str] # Copied from product record
product_unit_price: Optional[int] # Copied from product record
product_recurring: Optional[bool] # Copied from product record
for_person_id: Optional[int]
for_person_id_random: Optional[str]
name: Optional[str] # Should be the same as product_name above
quantity: int = Field(0, ge=0, lt=150)
amount: int = Field(0, ge=0, lt=1500000)
recurring: Optional[bool]
recurring_period: Optional[int]
message: Optional[str]
notes: Optional[str]
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
class Config:
underscore_attrs_are_private = True
allow_population_by_field_name = True

View File

@@ -35,6 +35,7 @@ class Order_Line_Base(BaseModel):
product_type_id: Optional[int] # Copied from product record
product_type: Optional[str] # WARNING: Copied from product record; dup from look up? probably not use?
product_type_code: Optional[str] # Copied from product record; from look up
product_type_name: Optional[str] # Copied from product record; from look up
product_name: Optional[str] # Copied from product record
@@ -52,6 +53,7 @@ class Order_Line_Base(BaseModel):
curr_product_type_id: Optional[int] # Dynamic from v_order_line
curr_product_type: Optional[str] # Dynamic from v_order_line
curr_product_type_code: Optional[str] # Dynamic from v_order_line
curr_product_type_name: Optional[str] # Dynamic from v_order_line
curr_product_name: Optional[str] # Dynamic from v_order_line
@@ -160,4 +162,51 @@ class Order_Line_Base(BaseModel):
allow_population_by_field_name = True
fields = base_fields
class Order_Line_DB_Base(BaseModel):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
id_random: Optional[str] = Field(
alias = 'order_line_id_random',
)
id: Optional[int] = Field(
alias = 'order_line_id'
)
order_id_random: Optional[str]
order_id: Optional[int]
product_id_random: str
product_id: Optional[int]
product_for_type: Optional[str] # Copied from product record
product_for_id_random: Optional[str] # Copied from product record NOPE
product_for_id: Optional[int] # Copied from product record
product_type_id: Optional[int] # Copied from product record
product_name: Optional[str] # Copied from product record
product_unit_price: Optional[int] # Copied from product record
product_recurring: Optional[bool] # Copied from product record
for_person_id: Optional[int]
for_person_id_random: Optional[str]
name: Optional[str] # Should be the same as product_name above
quantity: int = Field(0, ge=0, lt=150)
amount: int = Field(0, ge=0, lt=1500000)
recurring: Optional[bool] = False
recurring_period: Optional[int]
message: Optional[str]
notes: Optional[str]
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
class Config:
underscore_attrs_are_private = True
allow_population_by_field_name = True
Order_Line_Base.update_forward_refs()

View File

@@ -40,7 +40,19 @@ class Order_Base(BaseModel):
total_bill: Optional[int] = Field(0, ge=0, lt=1500000) # NOTE: This is total_amount in the order_cart
total_paid: Optional[int] = Field(0, ge=0, lt=1500000)
balance: Optional[int] = Field(0, ge=-1500000, lt=1500000) # Balance needs to be calculated
status: Optional[str]
status: Optional[str] # open, locked, reopened, closed, canceled, other
# open = building or creating cart, payment failed and no partial payment already processed
# locked = processing payment, partial payment processed, admin lock? (no changes allowed)
# closed = successful payment(s) with no balance, complete (no changes allowed)
# canceled = order canceled; something odd happened (no changes allowed)
# other = other reasons (no changes allowed)
checkout_status: Optional[str] # canceled, waiting, success, failed, unknown
# none = no checkout attempted
# canceled = checkout attempted but canceled for some reason
# waiting = the payment is processing or awaiting some type of authorization
# success = payment successful (their may still be a balance)
# failed = the payment failed for some reason
# unknown = unknown response...
notes: Optional[str]
@@ -51,7 +63,7 @@ class Order_Base(BaseModel):
cfg: Optional[Order_Cfg_Base]
order_line_list: Optional[list] # Order_Line_Base()
person: Optional[Person_Base]
user: Optional[User_Base]
# user: Optional[User_Base]
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
@@ -103,3 +115,71 @@ class Order_Base(BaseModel):
class Config:
underscore_attrs_are_private = True
fields = base_fields
class Order_DB_Base(BaseModel):
log.setLevel(logging.WARNING)
log.debug(locals())
account_id_random: Optional[str]
account_id: Optional[int] # NOTE: This is not really optional
person_id_random: Union[str, None] = None
person_id: Union[int, None] = None
user_id_random: Union[str, None] = None
user_id: Union[int, None] = None
total_quantity: Optional[int] = Field(0, ge=0, lt=150)
total_bill: Optional[int] = Field(0, ge=0, lt=1500000) # NOTE: This is total_amount in the order_cart
total_paid: Optional[int] = Field(0, ge=0, lt=1500000)
balance: Optional[int] = Field(0, ge=-1500000, lt=1500000) # Balance needs to be calculated
status: Optional[str] = 'open' # open, locked, reopened, closed, canceled, other
# open = building or creating cart, payment failed and no partial payment already processed
# locked = processing payment, partial payment processed, admin lock? (no changes allowed)
# closed = successful payment(s) with no balance, complete (no changes allowed)
# canceled = order canceled; something odd happened (no changes allowed)
# other = other reasons (no changes allowed)
checkout_status: Union[str, None] = None # canceled, waiting, success, failed, unknown
# none = no checkout attempted
# canceled = checkout attempted but canceled for some reason
# waiting = the payment is processing or awaiting some type of authorization
# success = payment successful (their may still be a balance)
# failed = the payment failed for some reason
# unknown = unknown response...
notes: Optional[str]
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
@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
class Config:
underscore_attrs_are_private = True
allow_population_by_field_name = True
fields = base_fields

View File

@@ -33,9 +33,8 @@ class Product_Base(BaseModel):
for_id: Optional[int]
type_id: Optional[int]
type_name: Optional[str] = Field(
# alias = 'type'
)
type_code: Optional[str]
type_name: Optional[str]
name: Optional[str]
description: Optional[str]