Bug fix in order cart line model. Need to create another _Base for order_line and order_cart_line

This commit is contained in:
Scott Idem
2021-08-07 20:27:45 -04:00
parent 5e02b424a8
commit 65b5e6ade6
7 changed files with 53 additions and 18 deletions

View File

@@ -121,6 +121,15 @@ class Order_Cart_Line_Base(BaseModel):
return redis_lookup_id_random(record_id_random=values['product_for_id_random'], table_name=values['product_for_type'])
return None
@validator('curr_product_id', always=True)
def curr_product_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values.get('curr_product_id_random', None):
return redis_lookup_id_random(record_id_random=values['curr_product_id_random'], table_name='product')
return None
@validator('curr_product_for_id', always=True)
def curr_product_for_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)

View File

@@ -4,14 +4,14 @@ 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 app.db_sql import redis_lookup_id_random
from app.lib_general import *
from app.db_sql import redis_lookup_id_random, lookup_id_random
from app.lib_general import log, logging
from .common_field_schema import base_fields, default_num_bytes
class Order_Line_Base(BaseModel):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
id_random: Optional[str] = Field(
@@ -28,12 +28,15 @@ class Order_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_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_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
@@ -41,12 +44,16 @@ class Order_Line_Base(BaseModel):
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
# NOTE: This is reversed with for_id_random
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_for_id_random: Optional[str] # Dynamic from v_order_line NOPE
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
@@ -121,16 +128,36 @@ class Order_Line_Base(BaseModel):
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)
# @validator('curr_product_for_id_random', always=True)
# def curr_product_for_id_random_lookup(cls, v, values, **kwargs):
# log.setLevel(logging.DEBUG)
# log.debug(locals())
# if values['curr_product_for_id'] and values['curr_product_for_type']:
# return redis_lookup_id(record_id=values['curr_product_for_id'], table_name=values['curr_product_for_type'])
# return None
@validator('curr_product_for_id_random', always=True)
def curr_product_for_id_random_lookup(cls, v, values, **kwargs):
log.setLevel(logging.DEBUG)
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'])
if values['curr_product_for_id'] and values['curr_product_for_type']:
return lookup_id_random(record_id=values['curr_product_for_id'], table_name=values['curr_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
Order_Line_Base.update_forward_refs()

View File

@@ -52,6 +52,7 @@ class Person_Base(BaseModel):
full_name: Optional[str]
informal_full_name: Optional[str]
last_first_name: Optional[str]
display_name: Optional[str]
title: Optional[str]