Feature: Added a column called print in bill to the table customer.

This will prevent printing all customer's names and phone numbers in the bill in case of simple walkins.
This is a breaking change as there is schema changes in the database.
It also bolds the customers who are to be printed in the bill in the running tables list.
This commit is contained in:
2021-06-28 08:41:32 +05:30
parent 143ddfb860
commit db5f2731be
17 changed files with 80 additions and 11 deletions

View File

@ -0,0 +1,29 @@
"""print customer
Revision ID: e5e8acfc6495
Revises: 48bc1c7c07ce
Create Date: 2021-06-27 09:57:43.034956
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
from sqlalchemy.sql import expression
revision = "e5e8acfc6495"
down_revision = "48bc1c7c07ce"
branch_labels = None
depends_on = None
def upgrade():
op.add_column(
"customers", sa.Column("print_in_bill", sa.Boolean(), nullable=False, server_default=expression.false())
)
def downgrade():
op.drop_column("customers", "print_in_bill")

View File

@ -1,9 +1,10 @@
import uuid import uuid
from barker.models.meta import Base from barker.models.meta import Base
from sqlalchemy import Column, Unicode, text from sqlalchemy import Boolean, Column, Unicode, text
from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.sql import expression
class Customer(Base): class Customer(Base):
@ -15,6 +16,7 @@ class Customer(Base):
name = Column("name", Unicode(255), nullable=False) name = Column("name", Unicode(255), nullable=False)
phone = Column("phone", Unicode(255), nullable=False, unique=True) phone = Column("phone", Unicode(255), nullable=False, unique=True)
address = Column("address", Unicode(255), nullable=True) address = Column("address", Unicode(255), nullable=True)
print_in_bill = Column("print_in_bill", Boolean, server_default=expression.false(), default=False, nullable=False)
discounts = relationship("CustomerDiscount", back_populates="customer") discounts = relationship("CustomerDiscount", back_populates="customer")
@ -22,10 +24,11 @@ class Customer(Base):
def __name__(self): def __name__(self):
return self.name return self.name
def __init__(self, name=None, phone=None, address=None, id_=None): def __init__(self, name=None, phone=None, address=None, print_in_bill=None, id_=None):
self.name = name self.name = name
self.phone = phone self.phone = phone
self.address = address self.address = address
self.print_in_bill = print_in_bill
self.id = id_ self.id = id_
@classmethod @classmethod

View File

@ -157,8 +157,8 @@ def design_bill(
s += f"\n\r{voucher.narration: ^42}" s += f"\n\r{voucher.narration: ^42}"
s += "\n\r" + "-" * 42 s += "\n\r" + "-" * 42
if voucher.customer: if voucher.customer and voucher.customer.print_in_bill:
s += f"\n\r{voucher.customer.name}\n\r{voucher.customer.phone}\n\r{voucher.customer.address}" s += f"\n\r{voucher.customer.name or ''}\n\r{voucher.customer.phone or ''}\n\r{voucher.customer.address or ''}"
s += "\n\r" + "-" * 42 s += "\n\r" + "-" * 42
s += "\n\r" + "Cashier : " + voucher.user.name s += "\n\r" + "Cashier : " + voucher.user.name

View File

@ -27,7 +27,7 @@ def save(
) -> schemas.Customer: ) -> schemas.Customer:
try: try:
with SessionFuture() as db: with SessionFuture() as db:
item = Customer(name=data.name, phone=data.phone, address=data.address) item = Customer(name=data.name, phone=data.phone, address=data.address, print_in_bill=data.print_in_bill)
db.add(item) db.add(item)
add_discounts(item, data.discounts, db) add_discounts(item, data.discounts, db)
db.commit() db.commit()
@ -51,6 +51,7 @@ def update_route(
item.name = data.name item.name = data.name
item.phone = data.phone item.phone = data.phone
item.address = data.address item.address = data.address
item.print_in_bill = data.print_in_bill
add_discounts(item, data.discounts, db) add_discounts(item, data.discounts, db)
db.commit() db.commit()
return customer_info(item, db) return customer_info(item, db)
@ -130,6 +131,7 @@ def customer_info(item: Customer, db: Session) -> schemas.Customer:
name=item.name, name=item.name,
address=item.address, address=item.address,
phone=item.phone, phone=item.phone,
printInBill=item.print_in_bill,
discounts=[ discounts=[
{ {
"id": sc.id, "id": sc.id,
@ -147,6 +149,7 @@ def customer_info_for_list(item: Customer) -> schemas.Customer:
name=item.name, name=item.name,
address=item.address, address=item.address,
phone=item.phone, phone=item.phone,
printInBill=item.print_in_bill,
discounts=[ discounts=[
{ {
"id": d.sale_category_id, "id": d.sale_category_id,
@ -160,4 +163,4 @@ def customer_info_for_list(item: Customer) -> schemas.Customer:
def blank_customer_info() -> schemas.CustomerBlank: def blank_customer_info() -> schemas.CustomerBlank:
return schemas.CustomerBlank(name="", address="", phone="", discounts=[]) return schemas.CustomerBlank(name="", address="", phone="", printInBill=False, discounts=[])

View File

@ -35,6 +35,7 @@ def save(
name=data.name, name=data.name,
phone=data.phone, phone=data.phone,
address=data.address, address=data.address,
print_in_bill=False,
) )
db.add(customer) db.add(customer)
else: else:

View File

@ -155,9 +155,10 @@ def show_running(user: UserToken = Depends(get_user)):
ft["date"] = (item.status.voucher.date + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)).strftime( ft["date"] = (item.status.voucher.date + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)).strftime(
"%d-%b-%Y %H:%M" "%d-%b-%Y %H:%M"
) )
ft["amount"] = item.status.voucher.amount ft["amount"] = round(item.status.voucher.amount, 0)
if item.status.guest is not None: if item.status.guest is not None:
ft["guest"] = item.status.guest.customer.name ft["guest"] = item.status.guest.customer.name
ft["bold"] = item.status.guest.customer.print_in_bill
food_tables.append(ft) food_tables.append(ft)
return food_tables return food_tables

View File

@ -24,6 +24,7 @@ class CustomerIn(BaseModel):
# phone: str = Field(..., min_length=1) # phone: str = Field(..., min_length=1)
phone: str phone: str
address: Optional[str] address: Optional[str]
print_in_bill: bool
discounts: List[DiscountItem] discounts: List[DiscountItem]

View File

@ -5,6 +5,7 @@ export class Customer {
name: string; name: string;
phone: string; phone: string;
address: string; address: string;
printInBill: boolean;
discounts: CustomerDiscount[]; discounts: CustomerDiscount[];
public constructor(init?: Partial<Customer>) { public constructor(init?: Partial<Customer>) {
@ -12,6 +13,7 @@ export class Customer {
this.name = ''; this.name = '';
this.phone = ''; this.phone = '';
this.address = ''; this.address = '';
this.printInBill = false;
this.discounts = []; this.discounts = [];
Object.assign(this, init); Object.assign(this, init);
} }

View File

@ -10,6 +10,7 @@ export class Table {
status?: string; status?: string;
pax?: number; pax?: number;
guest?: string; guest?: string;
bold?: boolean;
date?: string; date?: string;
amount?: number; amount?: number;

View File

@ -41,6 +41,16 @@
<textarea matInput placeholder="Address" formControlName="address"> </textarea> <textarea matInput placeholder="Address" formControlName="address"> </textarea>
</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-checkbox formControlName="printInBill">Print in Bill?</mat-checkbox>
</div>
<mat-divider></mat-divider> <mat-divider></mat-divider>
<div formArrayName="discounts"> <div formArrayName="discounts">
<div <div

View File

@ -34,6 +34,7 @@ export class CustomerDetailComponent implements OnInit, AfterViewInit {
name: '', name: '',
phone: '', phone: '',
address: '', address: '',
printInBill: false,
discounts: this.fb.array([]), discounts: this.fb.array([]),
}); });
} }
@ -50,6 +51,7 @@ export class CustomerDetailComponent implements OnInit, AfterViewInit {
(this.form.get('name') as AbstractControl).setValue(item.name); (this.form.get('name') as AbstractControl).setValue(item.name);
(this.form.get('phone') as AbstractControl).setValue(item.phone); (this.form.get('phone') as AbstractControl).setValue(item.phone);
(this.form.get('address') as AbstractControl).setValue(item.address); (this.form.get('address') as AbstractControl).setValue(item.address);
(this.form.get('printInBill') as AbstractControl).setValue(item.printInBill);
this.form.setControl( this.form.setControl(
'discounts', 'discounts',
this.fb.array( this.fb.array(
@ -112,6 +114,7 @@ export class CustomerDetailComponent implements OnInit, AfterViewInit {
this.item.name = formModel.name; this.item.name = formModel.name;
this.item.phone = formModel.phone; this.item.phone = formModel.phone;
this.item.address = formModel.address; this.item.address = formModel.address;
this.item.printInBill = formModel.printInBill;
const array = this.form.get('discounts') as FormArray; const array = this.form.get('discounts') as FormArray;
this.item.discounts.forEach((item, index) => { this.item.discounts.forEach((item, index) => {
item.discount = Math.max( item.discount = Math.max(

View File

@ -28,6 +28,12 @@
<mat-cell *matCellDef="let row">{{ row.address }}</mat-cell> <mat-cell *matCellDef="let row">{{ row.address }}</mat-cell>
</ng-container> </ng-container>
<!-- Print In Bill Column -->
<ng-container matColumnDef="printInBill">
<mat-header-cell *matHeaderCellDef>Print in Bill</mat-header-cell>
<mat-cell *matCellDef="let row">{{ row.printInBill }}</mat-cell>
</ng-container>
<!-- Discounts Column --> <!-- Discounts Column -->
<ng-container matColumnDef="discounts"> <ng-container matColumnDef="discounts">
<mat-header-cell *matHeaderCellDef>Discounts</mat-header-cell> <mat-header-cell *matHeaderCellDef>Discounts</mat-header-cell>

View File

@ -14,7 +14,7 @@ export class CustomerListComponent implements OnInit {
dataSource: CustomerListDatasource = new CustomerListDatasource([]); dataSource: CustomerListDatasource = new CustomerListDatasource([]);
list: Customer[] = []; list: Customer[] = [];
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */ /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['name', 'phone', 'address', 'discounts']; displayedColumns = ['name', 'phone', 'address', 'printInBill', 'discounts'];
constructor(private route: ActivatedRoute) {} constructor(private route: ActivatedRoute) {}

View File

@ -53,7 +53,6 @@ export class DiscountComponent {
for (let i = this.list.length - 1; i >= 0; i--) { for (let i = this.list.length - 1; i >= 0; i--) {
const item = this.list[i]; const item = this.list[i];
const control = (array.controls[i] as FormGroup).controls.discount as FormControl; const control = (array.controls[i] as FormGroup).controls.discount as FormControl;
console.log(item.name, control.value, typeof control.value);
if ( if (
control.value === null || control.value === null ||
control.value === '' || control.value === '' ||

View File

@ -13,6 +13,10 @@
color: #000000; color: #000000;
} }
.bold {
font-weight: bold;
}
.square-button { .square-button {
min-width: 150px; min-width: 150px;
max-width: 150px; max-width: 150px;

View File

@ -14,8 +14,12 @@
[class.printed]="table.status === 'printed'" [class.printed]="table.status === 'printed'"
> >
<h3 class="item-name">{{ table.name }}</h3> <h3 class="item-name">{{ table.name }}</h3>
<mat-card-subtitle class="center">{{ table.guest }}</mat-card-subtitle> <mat-card-subtitle class="center" [class.bold]="table.bold">{{
<span class="center">{{ table.pax || 0 }} / {{ table.seats }} Seats</span> table.guest
}}</mat-card-subtitle>
<span class="center"
>{{ table.pax || '-' }} / {{ table.seats }} / {{ table.section?.name }}</span
>
<span class="center" *ngIf="table.date">{{ table.date }}</span> <span class="center" *ngIf="table.date">{{ table.date }}</span>
<span class="center" *ngIf="table.amount">{{ table.amount | currency: 'INR' }}</span> <span class="center" *ngIf="table.amount">{{ table.amount | currency: 'INR' }}</span>
</mat-card> </mat-card>

View File

@ -86,9 +86,11 @@ if [ $docker -eq 1 ]
then then
docker start "$doname" || exit docker start "$doname" || exit
docker exec -it "$doname" alembic upgrade 48bc1c7c07ce || exit docker exec -it "$doname" alembic upgrade 48bc1c7c07ce || exit
docker exec -it "$doname" alembic upgrade e5e8acfc6495 || exit
else else
cd "$parent_path"/barker || exit cd "$parent_path"/barker || exit
alembic upgrade 48bc1c7c07ce || exit alembic upgrade 48bc1c7c07ce || exit
alembic upgrade e5e8acfc6495 || exit
fi fi
rm -f "$parent_path"/csv/*.csv "$parent_path"/csv/csv.tar.zip || exit rm -f "$parent_path"/csv/*.csv "$parent_path"/csv/csv.tar.zip || exit