Settle Options are now stored in the Database and can be updated
This commit is contained in:
147
barker/alembic/versions/48bc1c7c07ce_change_settle_options.py
Normal file
147
barker/alembic/versions/48bc1c7c07ce_change_settle_options.py
Normal file
@ -0,0 +1,147 @@
|
||||
"""Change Settle Options
|
||||
|
||||
Revision ID: 48bc1c7c07ce
|
||||
Revises: 34fe3d061c5f
|
||||
Create Date: 2020-12-10 08:29:39.175097
|
||||
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
from sqlalchemy import column, table
|
||||
from sqlalchemy.sql import expression
|
||||
|
||||
|
||||
revision = "48bc1c7c07ce"
|
||||
down_revision = "34fe3d061c5f"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
reporting_level = sa.Enum("Skip", "Aggregate", "Detailed", name="reporting_level")
|
||||
reporting_level.create(op.get_bind())
|
||||
voucher_type = sa.Enum("KOT", "REGULAR_BILL", "NO_CHARGE", "STAFF", "VOID", name="voucher_type")
|
||||
voucher_type.create(op.get_bind())
|
||||
op.add_column(
|
||||
"settle_options", sa.Column("has_reason", sa.Boolean(), nullable=False, server_default=expression.false())
|
||||
)
|
||||
op.add_column(
|
||||
"settle_options", sa.Column("is_fixture", sa.Boolean(), nullable=False, server_default=expression.false())
|
||||
)
|
||||
op.add_column(
|
||||
"settle_options",
|
||||
sa.Column(
|
||||
"reporting_level",
|
||||
reporting_level,
|
||||
nullable=False,
|
||||
server_default="Skip",
|
||||
),
|
||||
)
|
||||
op.add_column(
|
||||
"settle_options",
|
||||
sa.Column(
|
||||
"voucher_type",
|
||||
voucher_type,
|
||||
nullable=False,
|
||||
server_default="KOT",
|
||||
),
|
||||
)
|
||||
|
||||
so = table(
|
||||
"settle_options",
|
||||
column("id", sa.Integer()),
|
||||
column("is_fixture", sa.Boolean()),
|
||||
column("has_reason", sa.Boolean()),
|
||||
column("reporting_level", reporting_level),
|
||||
column("voucher_type", voucher_type),
|
||||
)
|
||||
|
||||
v = table(
|
||||
"vouchers",
|
||||
column("voucher_type_old", sa.Integer()),
|
||||
column("voucher_type", voucher_type),
|
||||
)
|
||||
|
||||
op.execute(
|
||||
so.update()
|
||||
.where(so.c.id == 1) # name = "Unsettled"
|
||||
.values(reporting_level="Detailed", voucher_type="KOT", is_fixture=True)
|
||||
)
|
||||
op.execute(
|
||||
so.update()
|
||||
.where(so.c.id == 2) # name = "Cash"
|
||||
.values(reporting_level="Aggregate", voucher_type="REGULAR_BILL", is_fixture=False)
|
||||
)
|
||||
op.execute(
|
||||
so.update()
|
||||
.where(so.c.id == 3) # name = "Credit Card"
|
||||
.values(reporting_level="Detailed", voucher_type="REGULAR_BILL", is_fixture=False)
|
||||
)
|
||||
op.execute(
|
||||
so.update()
|
||||
.where(so.c.id == 4) # name = "No Charge"
|
||||
.values(reporting_level="Detailed", voucher_type="NO_CHARGE", has_reason=True, is_fixture=True)
|
||||
)
|
||||
op.execute(
|
||||
so.update()
|
||||
.where(so.c.id == 5) # name = "Bill To Company"
|
||||
.values(reporting_level="Detailed", voucher_type="REGULAR_BILL", is_fixture=False)
|
||||
)
|
||||
op.execute(
|
||||
so.update()
|
||||
.where(so.c.id == 6) # name = "Tip"
|
||||
.values(reporting_level="Detailed", voucher_type="REGULAR_BILL", is_fixture=True)
|
||||
)
|
||||
op.execute(
|
||||
so.update()
|
||||
.where(so.c.id == 7) # name = "Round Off"
|
||||
.values(reporting_level="Skip", voucher_type="KOT", is_fixture=True)
|
||||
)
|
||||
op.execute(
|
||||
so.update()
|
||||
.where(so.c.id == 8) # name = "Amount"
|
||||
.values(reporting_level="Skip", voucher_type="KOT", is_fixture=True)
|
||||
)
|
||||
op.execute(
|
||||
so.update()
|
||||
.where(so.c.id == 9) # name = "Void"
|
||||
.values(reporting_level="Detailed", voucher_type="VOID", has_reason=True, is_fixture=True)
|
||||
)
|
||||
op.execute(
|
||||
so.update()
|
||||
.where(so.c.id == 10) # name = "Staff"
|
||||
.values(reporting_level="Detailed", voucher_type="STAFF", has_reason=True, is_fixture=True)
|
||||
)
|
||||
|
||||
op.drop_column("settle_options", "is_print")
|
||||
op.drop_column("settle_options", "show_in_choices")
|
||||
op.drop_column("settle_options", "display_group")
|
||||
op.alter_column("vouchers", "voucher_type", new_column_name="voucher_type_old")
|
||||
op.add_column(
|
||||
"vouchers",
|
||||
sa.Column(
|
||||
"voucher_type",
|
||||
voucher_type,
|
||||
nullable=False,
|
||||
server_default="KOT",
|
||||
),
|
||||
)
|
||||
op.execute(v.update().where(v.c.voucher_type_old == 0).values(voucher_type="KOT"))
|
||||
op.execute(v.update().where(v.c.voucher_type_old == 1).values(voucher_type="REGULAR_BILL"))
|
||||
op.execute(v.update().where(v.c.voucher_type_old == 2).values(voucher_type="NO_CHARGE"))
|
||||
op.execute(v.update().where(v.c.voucher_type_old == 4).values(voucher_type="STAFF"))
|
||||
op.execute(v.update().where(v.c.voucher_type_old == 5).values(voucher_type="VOID"))
|
||||
|
||||
op.drop_column("vouchers", "voucher_type_old")
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
@ -8,8 +8,9 @@ Create Date: 2020-06-04 08:14:34.132248
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
from barker.models import Customer, DbSetting, ModifierCategory, Section, SettleOption
|
||||
from barker.models.auth import Permission, User # noqa
|
||||
from barker.models.master import Customer, DbSetting, ModifierCategory, Section
|
||||
from sqlalchemy import column, table
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
|
||||
@ -20,6 +21,68 @@ branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def settle_options():
|
||||
so = table(
|
||||
"settle_options",
|
||||
column("id", sa.Integer()),
|
||||
column("name", sa.Unicode(length=255)),
|
||||
column("show_in_choices", sa.Boolean()),
|
||||
column("display_group", sa.Integer()),
|
||||
column("is_print", sa.Boolean()),
|
||||
)
|
||||
|
||||
op.execute(
|
||||
so.insert().values(
|
||||
id=1,
|
||||
name="Unsettled",
|
||||
show_in_choices=False,
|
||||
display_group=1,
|
||||
is_print=True,
|
||||
)
|
||||
)
|
||||
op.execute(so.insert().values(id=2, name="Cash", show_in_choices=True, display_group=2, is_print=False))
|
||||
op.execute(
|
||||
so.insert().values(
|
||||
id=3,
|
||||
name="Credit Card",
|
||||
show_in_choices=True,
|
||||
display_group=2,
|
||||
is_print=True,
|
||||
)
|
||||
)
|
||||
op.execute(so.insert().values(id=4, name="No Charge", show_in_choices=True, display_group=3, is_print=True))
|
||||
op.execute(
|
||||
so.insert().values(
|
||||
id=5,
|
||||
name="Bill To Company",
|
||||
show_in_choices=True,
|
||||
display_group=2,
|
||||
is_print=True,
|
||||
)
|
||||
)
|
||||
op.execute(so.insert().values(id=6, name="Tip", show_in_choices=True, display_group=2, is_print=True))
|
||||
op.execute(
|
||||
so.insert().values(
|
||||
id=7,
|
||||
name="Round Off",
|
||||
show_in_choices=False,
|
||||
display_group=1,
|
||||
is_print=False,
|
||||
)
|
||||
)
|
||||
op.execute(so.insert().values(id=8, name="Amount", show_in_choices=False, display_group=1, is_print=False))
|
||||
op.execute(so.insert().values(id=9, name="Void", show_in_choices=True, display_group=1, is_print=True))
|
||||
op.execute(so.insert().values(id=10, name="Staff", show_in_choices=True, display_group=4, is_print=True))
|
||||
op.execute(
|
||||
Customer.__table__.insert().values(
|
||||
id="2c716f4b-0736-429a-ad51-610d7c47cb5e",
|
||||
name="Cash",
|
||||
phone="",
|
||||
address="",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table(
|
||||
@ -536,74 +599,8 @@ def upgrade():
|
||||
)
|
||||
)
|
||||
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
id=1,
|
||||
name="Unsettled",
|
||||
show_in_choices=False,
|
||||
display_group=1,
|
||||
is_print=True,
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(id=2, name="Cash", show_in_choices=True, display_group=2, is_print=False)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
id=3,
|
||||
name="Credit Card",
|
||||
show_in_choices=True,
|
||||
display_group=2,
|
||||
is_print=True,
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
id=4, name="No Charge", show_in_choices=True, display_group=3, is_print=True
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
id=5,
|
||||
name="Bill To Company",
|
||||
show_in_choices=True,
|
||||
display_group=2,
|
||||
is_print=True,
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(id=6, name="Tip", show_in_choices=True, display_group=2, is_print=True)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
id=7,
|
||||
name="Round Off",
|
||||
show_in_choices=False,
|
||||
display_group=1,
|
||||
is_print=False,
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
id=8, name="Amount", show_in_choices=False, display_group=1, is_print=False
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(id=9, name="Void", show_in_choices=True, display_group=1, is_print=True)
|
||||
)
|
||||
op.execute(
|
||||
SettleOption.__table__.insert().values(
|
||||
id=10, name="Staff", show_in_choices=True, display_group=4, is_print=True
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
Customer.__table__.insert().values(
|
||||
id="2c716f4b-0736-429a-ad51-610d7c47cb5e",
|
||||
name="Cash",
|
||||
phone="",
|
||||
address="",
|
||||
)
|
||||
)
|
||||
settle_options()
|
||||
|
||||
op.execute(
|
||||
DbSetting.__table__.insert().values(
|
||||
id="fb738ba2-a3c9-40ed-891c-b930e6454974",
|
||||
|
||||
Reference in New Issue
Block a user