new tag v3.1.0
Fix: Company references left after the field was removed
This commit is contained in:
@ -33,7 +33,7 @@ def save(
|
||||
user: UserToken = Security(get_user, scopes=["customers"]),
|
||||
):
|
||||
try:
|
||||
item = Customer(company=data.company, name=data.name, phone=data.phone, address=data.address)
|
||||
item = Customer(name=data.name, phone=data.phone, address=data.address)
|
||||
db.add(item)
|
||||
db.commit()
|
||||
return customer_info(item)
|
||||
@ -57,7 +57,6 @@ def update(
|
||||
):
|
||||
try:
|
||||
item: Customer = db.query(Customer).filter(Customer.id == id_).first()
|
||||
item.company = data.company
|
||||
item.name = data.name
|
||||
item.phone = data.phone
|
||||
item.address = data.address
|
||||
@ -119,10 +118,9 @@ def show_id(
|
||||
|
||||
def customer_info(item: Optional[Customer]):
|
||||
if item is None:
|
||||
return {"name": "", "company": "", "address": "", "phone": ""}
|
||||
return {"name": "", "address": "", "phone": ""}
|
||||
return {
|
||||
"id": item.id,
|
||||
"company": item.company,
|
||||
"name": item.name,
|
||||
"address": item.address,
|
||||
"phone": item.phone,
|
||||
|
||||
@ -39,7 +39,6 @@ def save(
|
||||
customer: Customer = db.query(Customer).filter(Customer.phone == data.phone).first()
|
||||
if customer is None:
|
||||
customer = Customer(
|
||||
company=data.company,
|
||||
name=data.name,
|
||||
phone=data.phone,
|
||||
address=data.address,
|
||||
@ -47,7 +46,6 @@ def save(
|
||||
db.add(customer)
|
||||
else:
|
||||
customer.name = data.name or customer.name
|
||||
customer.company = data.company or customer.company
|
||||
customer.address = data.address or customer.address
|
||||
item = GuestBook(pax=data.pax, customer=customer)
|
||||
db.add(item)
|
||||
@ -73,7 +71,6 @@ def update(
|
||||
):
|
||||
try:
|
||||
item: GuestBook = db.query(GuestBook).filter(GuestBook.id == id_).first()
|
||||
item.customer.company = data.company
|
||||
item.customer.name = data.name
|
||||
item.customer.phone = data.phone
|
||||
item.customer.address = data.address
|
||||
@ -155,7 +152,6 @@ def show_list(
|
||||
{
|
||||
"id": item.id,
|
||||
"serial": i + 1,
|
||||
"company": item.customer.company,
|
||||
"name": item.customer.name,
|
||||
"phone": item.customer.phone,
|
||||
"pax": item.pax,
|
||||
@ -180,7 +176,6 @@ def guest_book_info(item: Optional[GuestBook]):
|
||||
if item is not None:
|
||||
return {
|
||||
"id": item.id,
|
||||
"company": item.customer.company,
|
||||
"name": item.customer.name,
|
||||
"phone": item.customer.phone,
|
||||
"pax": item.pax,
|
||||
@ -188,4 +183,4 @@ def guest_book_info(item: Optional[GuestBook]):
|
||||
"date": item.date.strftime("%d-%b-%Y %H:%M"),
|
||||
}
|
||||
else:
|
||||
return {"company": "", "name": "", "phone": "", "pax": 0, "address": ""}
|
||||
return {"name": "", "phone": "", "pax": 0, "address": ""}
|
||||
|
||||
@ -9,7 +9,6 @@ from . import to_camel
|
||||
|
||||
class CustomerIn(BaseModel):
|
||||
name: str = Field(..., min_length=1)
|
||||
company: str
|
||||
phone: str = Field(..., min_length=1)
|
||||
address: str
|
||||
|
||||
|
||||
Reference in New Issue
Block a user