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:
29
barker/alembic/versions/e5e8acfc6495_print_customer.py
Normal file
29
barker/alembic/versions/e5e8acfc6495_print_customer.py
Normal 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")
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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=[])
|
||||
|
||||
@ -35,6 +35,7 @@ def save(
|
||||
name=data.name,
|
||||
phone=data.phone,
|
||||
address=data.address,
|
||||
print_in_bill=False,
|
||||
)
|
||||
db.add(customer)
|
||||
else:
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user