From db5f2731bed233f0719294aa2259d76f0723ea37 Mon Sep 17 00:00:00 2001 From: tanshu Date: Mon, 28 Jun 2021 08:41:32 +0530 Subject: [PATCH] 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. --- .../versions/e5e8acfc6495_print_customer.py | 29 +++++++++++++++++++ barker/barker/models/customer.py | 7 +++-- barker/barker/printing/bill.py | 4 +-- barker/barker/routers/customer.py | 7 +++-- barker/barker/routers/guest_book.py | 1 + barker/barker/routers/table.py | 3 +- barker/barker/schemas/customer.py | 1 + bookie/src/app/core/customer.ts | 2 ++ bookie/src/app/core/table.ts | 1 + .../customer-detail.component.html | 10 +++++++ .../customer-detail.component.ts | 3 ++ .../customer-list.component.html | 6 ++++ .../customer-list/customer-list.component.ts | 2 +- .../app/sales/discount/discount.component.ts | 1 - .../running-tables.component.css | 4 +++ .../running-tables.component.html | 8 +++-- import.sh | 2 ++ 17 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 barker/alembic/versions/e5e8acfc6495_print_customer.py diff --git a/barker/alembic/versions/e5e8acfc6495_print_customer.py b/barker/alembic/versions/e5e8acfc6495_print_customer.py new file mode 100644 index 0000000..3fd85f7 --- /dev/null +++ b/barker/alembic/versions/e5e8acfc6495_print_customer.py @@ -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") diff --git a/barker/barker/models/customer.py b/barker/barker/models/customer.py index 430102b..43cbe8b 100644 --- a/barker/barker/models/customer.py +++ b/barker/barker/models/customer.py @@ -1,9 +1,10 @@ import uuid 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.orm import relationship +from sqlalchemy.sql import expression class Customer(Base): @@ -15,6 +16,7 @@ class Customer(Base): name = Column("name", Unicode(255), nullable=False) phone = Column("phone", Unicode(255), nullable=False, unique=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") @@ -22,10 +24,11 @@ class Customer(Base): def __name__(self): 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.phone = phone self.address = address + self.print_in_bill = print_in_bill self.id = id_ @classmethod diff --git a/barker/barker/printing/bill.py b/barker/barker/printing/bill.py index fa06f5d..541ffd8 100644 --- a/barker/barker/printing/bill.py +++ b/barker/barker/printing/bill.py @@ -157,8 +157,8 @@ def design_bill( s += f"\n\r{voucher.narration: ^42}" s += "\n\r" + "-" * 42 - if voucher.customer: - s += f"\n\r{voucher.customer.name}\n\r{voucher.customer.phone}\n\r{voucher.customer.address}" + if voucher.customer and voucher.customer.print_in_bill: + 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" + "Cashier : " + voucher.user.name diff --git a/barker/barker/routers/customer.py b/barker/barker/routers/customer.py index 60af635..8275a01 100644 --- a/barker/barker/routers/customer.py +++ b/barker/barker/routers/customer.py @@ -27,7 +27,7 @@ def save( ) -> schemas.Customer: try: 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) add_discounts(item, data.discounts, db) db.commit() @@ -51,6 +51,7 @@ def update_route( item.name = data.name item.phone = data.phone item.address = data.address + item.print_in_bill = data.print_in_bill add_discounts(item, data.discounts, db) db.commit() return customer_info(item, db) @@ -130,6 +131,7 @@ def customer_info(item: Customer, db: Session) -> schemas.Customer: name=item.name, address=item.address, phone=item.phone, + printInBill=item.print_in_bill, discounts=[ { "id": sc.id, @@ -147,6 +149,7 @@ def customer_info_for_list(item: Customer) -> schemas.Customer: name=item.name, address=item.address, phone=item.phone, + printInBill=item.print_in_bill, discounts=[ { "id": d.sale_category_id, @@ -160,4 +163,4 @@ def customer_info_for_list(item: Customer) -> schemas.Customer: def blank_customer_info() -> schemas.CustomerBlank: - return schemas.CustomerBlank(name="", address="", phone="", discounts=[]) + return schemas.CustomerBlank(name="", address="", phone="", printInBill=False, discounts=[]) diff --git a/barker/barker/routers/guest_book.py b/barker/barker/routers/guest_book.py index df7065e..79e54af 100644 --- a/barker/barker/routers/guest_book.py +++ b/barker/barker/routers/guest_book.py @@ -35,6 +35,7 @@ def save( name=data.name, phone=data.phone, address=data.address, + print_in_bill=False, ) db.add(customer) else: diff --git a/barker/barker/routers/table.py b/barker/barker/routers/table.py index 646eed7..75ff29b 100644 --- a/barker/barker/routers/table.py +++ b/barker/barker/routers/table.py @@ -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( "%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: ft["guest"] = item.status.guest.customer.name + ft["bold"] = item.status.guest.customer.print_in_bill food_tables.append(ft) return food_tables diff --git a/barker/barker/schemas/customer.py b/barker/barker/schemas/customer.py index 7980980..61fb13f 100644 --- a/barker/barker/schemas/customer.py +++ b/barker/barker/schemas/customer.py @@ -24,6 +24,7 @@ class CustomerIn(BaseModel): # phone: str = Field(..., min_length=1) phone: str address: Optional[str] + print_in_bill: bool discounts: List[DiscountItem] diff --git a/bookie/src/app/core/customer.ts b/bookie/src/app/core/customer.ts index f445c13..b914035 100644 --- a/bookie/src/app/core/customer.ts +++ b/bookie/src/app/core/customer.ts @@ -5,6 +5,7 @@ export class Customer { name: string; phone: string; address: string; + printInBill: boolean; discounts: CustomerDiscount[]; public constructor(init?: Partial) { @@ -12,6 +13,7 @@ export class Customer { this.name = ''; this.phone = ''; this.address = ''; + this.printInBill = false; this.discounts = []; Object.assign(this, init); } diff --git a/bookie/src/app/core/table.ts b/bookie/src/app/core/table.ts index e730b6a..7a98566 100644 --- a/bookie/src/app/core/table.ts +++ b/bookie/src/app/core/table.ts @@ -10,6 +10,7 @@ export class Table { status?: string; pax?: number; guest?: string; + bold?: boolean; date?: string; amount?: number; diff --git a/bookie/src/app/customers/customer-detail/customer-detail.component.html b/bookie/src/app/customers/customer-detail/customer-detail.component.html index bdf50ca..0f0b63c 100644 --- a/bookie/src/app/customers/customer-detail/customer-detail.component.html +++ b/bookie/src/app/customers/customer-detail/customer-detail.component.html @@ -41,6 +41,16 @@ +
+ Print in Bill? +
+
{ item.discount = Math.max( diff --git a/bookie/src/app/customers/customer-list/customer-list.component.html b/bookie/src/app/customers/customer-list/customer-list.component.html index 6e96d65..c511a9a 100644 --- a/bookie/src/app/customers/customer-list/customer-list.component.html +++ b/bookie/src/app/customers/customer-list/customer-list.component.html @@ -28,6 +28,12 @@ {{ row.address }} + + + Print in Bill + {{ row.printInBill }} + + Discounts diff --git a/bookie/src/app/customers/customer-list/customer-list.component.ts b/bookie/src/app/customers/customer-list/customer-list.component.ts index 4312e9f..4c53523 100644 --- a/bookie/src/app/customers/customer-list/customer-list.component.ts +++ b/bookie/src/app/customers/customer-list/customer-list.component.ts @@ -14,7 +14,7 @@ export class CustomerListComponent implements OnInit { dataSource: CustomerListDatasource = new CustomerListDatasource([]); list: Customer[] = []; /** 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) {} diff --git a/bookie/src/app/sales/discount/discount.component.ts b/bookie/src/app/sales/discount/discount.component.ts index 723299a..daab2db 100644 --- a/bookie/src/app/sales/discount/discount.component.ts +++ b/bookie/src/app/sales/discount/discount.component.ts @@ -53,7 +53,6 @@ export class DiscountComponent { for (let i = this.list.length - 1; i >= 0; i--) { const item = this.list[i]; const control = (array.controls[i] as FormGroup).controls.discount as FormControl; - console.log(item.name, control.value, typeof control.value); if ( control.value === null || control.value === '' || diff --git a/bookie/src/app/sales/running-tables/running-tables.component.css b/bookie/src/app/sales/running-tables/running-tables.component.css index f6825a1..d0d2fbd 100644 --- a/bookie/src/app/sales/running-tables/running-tables.component.css +++ b/bookie/src/app/sales/running-tables/running-tables.component.css @@ -13,6 +13,10 @@ color: #000000; } +.bold { + font-weight: bold; +} + .square-button { min-width: 150px; max-width: 150px; diff --git a/bookie/src/app/sales/running-tables/running-tables.component.html b/bookie/src/app/sales/running-tables/running-tables.component.html index bbf77ed..eb85ff8 100644 --- a/bookie/src/app/sales/running-tables/running-tables.component.html +++ b/bookie/src/app/sales/running-tables/running-tables.component.html @@ -14,8 +14,12 @@ [class.printed]="table.status === 'printed'" >

{{ table.name }}

- {{ table.guest }} - {{ table.pax || 0 }} / {{ table.seats }} Seats + {{ + table.guest + }} + {{ table.pax || '-' }} / {{ table.seats }} / {{ table.section?.name }} {{ table.date }} {{ table.amount | currency: 'INR' }} diff --git a/import.sh b/import.sh index bbc53b0..f4a307f 100755 --- a/import.sh +++ b/import.sh @@ -86,9 +86,11 @@ if [ $docker -eq 1 ] then docker start "$doname" || exit docker exec -it "$doname" alembic upgrade 48bc1c7c07ce || exit + docker exec -it "$doname" alembic upgrade e5e8acfc6495 || exit else cd "$parent_path"/barker || exit alembic upgrade 48bc1c7c07ce || exit + alembic upgrade e5e8acfc6495 || exit fi rm -f "$parent_path"/csv/*.csv "$parent_path"/csv/csv.tar.zip || exit