Work on lots of methods and models.
This commit is contained in:
83
app/models/order_line_models.py
Normal file
83
app/models/order_line_models.py
Normal file
@@ -0,0 +1,83 @@
|
||||
from __future__ import annotations
|
||||
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 .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.debug(locals())
|
||||
|
||||
id_random: Optional[str] = Field(
|
||||
**base_fields['order_line_id_random'],
|
||||
alias='order_line_id_random',
|
||||
default_factory=lambda:secrets.token_urlsafe(default_num_bytes),
|
||||
)
|
||||
id: Optional[int] = Field(
|
||||
#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]
|
||||
name: Optional[str]
|
||||
description: Optional[str]
|
||||
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
|
||||
|
||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||
|
||||
#@validator('order_line_id_random', always=True)
|
||||
def order_line_id_random_copy(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if values['id_random']:
|
||||
return values['id_random']
|
||||
return None
|
||||
|
||||
@validator('id', always=True)
|
||||
def order_line_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if values['id_random']:
|
||||
log.debug(values['id_random'])
|
||||
return redis_lookup_id_random(record_id_random=values['id_random'], table_name='order_line')
|
||||
return None
|
||||
|
||||
@validator('order_id', always=True)
|
||||
def order_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if values['order_id_random']:
|
||||
return redis_lookup_id_random(record_id_random=values['order_id_random'], table_name='order')
|
||||
return None
|
||||
|
||||
@validator('product_id', always=True)
|
||||
def product_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if values['product_id_random']:
|
||||
return redis_lookup_id_random(record_id_random=values['product_id_random'], table_name='product')
|
||||
return None
|
||||
|
||||
class Config:
|
||||
underscore_attrs_are_private = True
|
||||
fields = base_fields
|
||||
Reference in New Issue
Block a user