A lot of unplanned clean up and created some new/missing methods and routes. Mainly working on order and order_cart related stuff.

This commit is contained in:
Scott Idem
2021-08-07 18:15:59 -04:00
parent 9915c7d9ed
commit 106a186ea6
12 changed files with 565 additions and 278 deletions

View File

@@ -20,35 +20,59 @@ class Order_Line_Base(BaseModel):
default_factory = lambda:secrets.token_urlsafe(default_num_bytes),
)
id: Optional[int] = Field(
#alias = 'order_line_id'
alias = 'order_line_id'
)
#order_line_id_random: Optional[str]
order_id_random: Optional[str]
order_id: Optional[int]
product_id_random: str
product_id: Optional[int]
product_type_id: Optional[int]
product_type: Optional[str]
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] # WARNING: Copied from product record; dup from look up? probably not use?
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
product_recurring: Optional[bool] # Copied from product record
curr_product_id_random: 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_line
curr_product_for_id_random: Optional[str] # Dynamic from v_order_line
curr_product_for_id: Optional[int] # Dynamic from v_order_line
curr_product_type_id: Optional[int] # Dynamic from v_order_line
curr_product_type: 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
curr_product_description: Optional[str] # Dynamic from v_order_line
curr_product_unit_price: Optional[int] # Dynamic from v_order_line
curr_product_max_quantity: Optional[int] # Dynamic from v_order_line
curr_product_recurring: Optional[bool] # Dynamic from v_order_line
# NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
# NOTE need to check @validator NOTE NOTE NOTE NOTE
for_type: Optional[str] # Copied from the current value in product.for_type
for_id_random: Optional[str] # Copied from the current value in product.for_id_random
for_id: Optional[int] # Copied from the current value in product.for_id
# NOTE!!! Need ot add similar to order_cart_line???
# NOTE!!! Need to add to the actual order_line (and order_cart_line???) tables!
for_person_id: Optional[int]
for_person_id_random: Optional[str]
for_person_given_name: Optional[str] # Dynamic from v_order_line
for_person_full_name: Optional[str] # Dynamic from v_order_line
name: Optional[str]
description: 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
message: Optional[str]
notes: Optional[str]
created_on: Optional[datetime.datetime] = None
updated_on: Optional[datetime.datetime] = None
# Including other related objects
# product: Optional[Union[Product_Base, None]] # Future use?
# for_person: Optional[Union[Person_Base, None]] # Future use?
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
#@validator('order_line_id_random', always=True)
@@ -84,19 +108,29 @@ class Order_Line_Base(BaseModel):
log.setLevel(logging.WARNING)
log.debug(locals())
if values['product_id_random']:
if values.get('product_id_random', None):
return redis_lookup_id_random(record_id_random=values['product_id_random'], table_name='product')
return None
@validator('for_id', always=True)
def for_id_lookup(cls, v, values, **kwargs):
@validator('product_for_id', always=True)
def product_for_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values['for_id_random'] and values['for_type']:
return redis_lookup_id_random(record_id_random=values['for_id_random'], table_name=values['for_type'])
if values['product_for_id_random'] and values['product_for_type']:
return redis_lookup_id_random(record_id_random=values['product_for_id_random'], table_name=values['product_for_type'])
return None
@validator('curr_product_for_id', always=True)
def curr_product_for_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values['curr_product_for_id_random'] and values['curr_product_for_type']:
return redis_lookup_id_random(record_id_random=values['curr_product_for_id_random'], table_name=values['curr_product_for_type'])
return None
class Config:
underscore_attrs_are_private = True
allow_population_by_field_name = True
fields = base_fields