new tag v3.1.0
Fix: Company references left after the field was removed
This commit is contained in:
parent
969b774a25
commit
4108040cdd
|
@ -33,7 +33,7 @@ def save(
|
||||||
user: UserToken = Security(get_user, scopes=["customers"]),
|
user: UserToken = Security(get_user, scopes=["customers"]),
|
||||||
):
|
):
|
||||||
try:
|
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.add(item)
|
||||||
db.commit()
|
db.commit()
|
||||||
return customer_info(item)
|
return customer_info(item)
|
||||||
|
@ -57,7 +57,6 @@ def update(
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
item: Customer = db.query(Customer).filter(Customer.id == id_).first()
|
item: Customer = db.query(Customer).filter(Customer.id == id_).first()
|
||||||
item.company = data.company
|
|
||||||
item.name = data.name
|
item.name = data.name
|
||||||
item.phone = data.phone
|
item.phone = data.phone
|
||||||
item.address = data.address
|
item.address = data.address
|
||||||
|
@ -119,10 +118,9 @@ def show_id(
|
||||||
|
|
||||||
def customer_info(item: Optional[Customer]):
|
def customer_info(item: Optional[Customer]):
|
||||||
if item is None:
|
if item is None:
|
||||||
return {"name": "", "company": "", "address": "", "phone": ""}
|
return {"name": "", "address": "", "phone": ""}
|
||||||
return {
|
return {
|
||||||
"id": item.id,
|
"id": item.id,
|
||||||
"company": item.company,
|
|
||||||
"name": item.name,
|
"name": item.name,
|
||||||
"address": item.address,
|
"address": item.address,
|
||||||
"phone": item.phone,
|
"phone": item.phone,
|
||||||
|
|
|
@ -39,7 +39,6 @@ def save(
|
||||||
customer: Customer = db.query(Customer).filter(Customer.phone == data.phone).first()
|
customer: Customer = db.query(Customer).filter(Customer.phone == data.phone).first()
|
||||||
if customer is None:
|
if customer is None:
|
||||||
customer = Customer(
|
customer = Customer(
|
||||||
company=data.company,
|
|
||||||
name=data.name,
|
name=data.name,
|
||||||
phone=data.phone,
|
phone=data.phone,
|
||||||
address=data.address,
|
address=data.address,
|
||||||
|
@ -47,7 +46,6 @@ def save(
|
||||||
db.add(customer)
|
db.add(customer)
|
||||||
else:
|
else:
|
||||||
customer.name = data.name or customer.name
|
customer.name = data.name or customer.name
|
||||||
customer.company = data.company or customer.company
|
|
||||||
customer.address = data.address or customer.address
|
customer.address = data.address or customer.address
|
||||||
item = GuestBook(pax=data.pax, customer=customer)
|
item = GuestBook(pax=data.pax, customer=customer)
|
||||||
db.add(item)
|
db.add(item)
|
||||||
|
@ -73,7 +71,6 @@ def update(
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
item: GuestBook = db.query(GuestBook).filter(GuestBook.id == id_).first()
|
item: GuestBook = db.query(GuestBook).filter(GuestBook.id == id_).first()
|
||||||
item.customer.company = data.company
|
|
||||||
item.customer.name = data.name
|
item.customer.name = data.name
|
||||||
item.customer.phone = data.phone
|
item.customer.phone = data.phone
|
||||||
item.customer.address = data.address
|
item.customer.address = data.address
|
||||||
|
@ -155,7 +152,6 @@ def show_list(
|
||||||
{
|
{
|
||||||
"id": item.id,
|
"id": item.id,
|
||||||
"serial": i + 1,
|
"serial": i + 1,
|
||||||
"company": item.customer.company,
|
|
||||||
"name": item.customer.name,
|
"name": item.customer.name,
|
||||||
"phone": item.customer.phone,
|
"phone": item.customer.phone,
|
||||||
"pax": item.pax,
|
"pax": item.pax,
|
||||||
|
@ -180,7 +176,6 @@ def guest_book_info(item: Optional[GuestBook]):
|
||||||
if item is not None:
|
if item is not None:
|
||||||
return {
|
return {
|
||||||
"id": item.id,
|
"id": item.id,
|
||||||
"company": item.customer.company,
|
|
||||||
"name": item.customer.name,
|
"name": item.customer.name,
|
||||||
"phone": item.customer.phone,
|
"phone": item.customer.phone,
|
||||||
"pax": item.pax,
|
"pax": item.pax,
|
||||||
|
@ -188,4 +183,4 @@ def guest_book_info(item: Optional[GuestBook]):
|
||||||
"date": item.date.strftime("%d-%b-%Y %H:%M"),
|
"date": item.date.strftime("%d-%b-%Y %H:%M"),
|
||||||
}
|
}
|
||||||
else:
|
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):
|
class CustomerIn(BaseModel):
|
||||||
name: str = Field(..., min_length=1)
|
name: str = Field(..., min_length=1)
|
||||||
company: str
|
|
||||||
phone: str = Field(..., min_length=1)
|
phone: str = Field(..., min_length=1)
|
||||||
address: str
|
address: str
|
||||||
|
|
||||||
|
|
|
@ -44,18 +44,6 @@
|
||||||
<input matInput placeholder="Pax" type="number" formControlName="pax" />
|
<input matInput placeholder="Pax" type="number" formControlName="pax" />
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<div
|
|
||||||
fxLayout="row"
|
|
||||||
fxLayoutAlign="space-around start"
|
|
||||||
fxLayout.lt-md="column"
|
|
||||||
fxLayoutGap="20px"
|
|
||||||
fxLayoutGap.lt-md="0px"
|
|
||||||
>
|
|
||||||
<mat-form-field fxFlex>
|
|
||||||
<mat-label>Company</mat-label>
|
|
||||||
<input matInput placeholder="Company" formControlName="company" />
|
|
||||||
</mat-form-field>
|
|
||||||
</div>
|
|
||||||
<div
|
<div
|
||||||
fxLayout="row"
|
fxLayout="row"
|
||||||
fxLayoutAlign="space-around start"
|
fxLayoutAlign="space-around start"
|
||||||
|
|
|
@ -28,7 +28,6 @@ export class GuestBookDetailComponent implements OnInit, AfterViewInit {
|
||||||
|
|
||||||
createForm() {
|
createForm() {
|
||||||
this.form = this.fb.group({
|
this.form = this.fb.group({
|
||||||
company: null,
|
|
||||||
name: [null, Validators.required],
|
name: [null, Validators.required],
|
||||||
phone: [null, Validators.required],
|
phone: [null, Validators.required],
|
||||||
pax: ['0', Validators.required],
|
pax: ['0', Validators.required],
|
||||||
|
@ -51,7 +50,6 @@ export class GuestBookDetailComponent implements OnInit, AfterViewInit {
|
||||||
showItem(item: GuestBook) {
|
showItem(item: GuestBook) {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.form.setValue({
|
this.form.setValue({
|
||||||
company: item.company,
|
|
||||||
name: item.name,
|
name: item.name,
|
||||||
phone: item.phone,
|
phone: item.phone,
|
||||||
pax: `${item.pax}`,
|
pax: `${item.pax}`,
|
||||||
|
@ -73,7 +71,6 @@ export class GuestBookDetailComponent implements OnInit, AfterViewInit {
|
||||||
|
|
||||||
getItem(): GuestBook {
|
getItem(): GuestBook {
|
||||||
const formModel = this.form.value;
|
const formModel = this.form.value;
|
||||||
this.item.company = formModel.company;
|
|
||||||
this.item.name = formModel.name;
|
this.item.name = formModel.name;
|
||||||
this.item.phone = formModel.phone;
|
this.item.phone = formModel.phone;
|
||||||
this.item.pax = parseInt(formModel.pax, 10);
|
this.item.pax = parseInt(formModel.pax, 10);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
export class GuestBook {
|
export class GuestBook {
|
||||||
id: string;
|
id: string;
|
||||||
serial: number;
|
serial: number;
|
||||||
company: string;
|
|
||||||
name: string;
|
name: string;
|
||||||
phone: string;
|
phone: string;
|
||||||
pax: number;
|
pax: number;
|
||||||
|
|
Loading…
Reference in New Issue