Feature: Added product bundles. Have to wire it up to inventory and reports.
This commit is contained in:
1 parent
b79af6e1c6
commit
6e8843d3c4
48 files changed
+2139
-130
No files matched your search
@@ -0,0 +1,103 @@
|
||||
"""bundles
|
||||
|
||||
Revision ID: 367ecf7b898f
|
||||
Revises: 1e0daf6bc1ae
|
||||
Create Date: 2026-01-28 16:11:21.874409
|
||||
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "367ecf7b898f"
|
||||
down_revision = "1e0daf6bc1ae"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
"bundle_items",
|
||||
sa.Column("id", sa.Uuid(), server_default=sa.text("gen_random_uuid()"), nullable=False),
|
||||
sa.Column("bundle_id", sa.Uuid(), nullable=False),
|
||||
sa.Column("item_id", sa.Uuid(), nullable=False),
|
||||
sa.Column("quantity", sa.Numeric(precision=15, scale=2), nullable=False),
|
||||
sa.Column("sale_price", sa.Numeric(precision=15, scale=2), nullable=False),
|
||||
sa.Column("valid_from", sa.Date(), nullable=True),
|
||||
sa.Column("valid_till", sa.Date(), nullable=True),
|
||||
postgresql.ExcludeConstraint(
|
||||
(sa.column("bundle_id"), "="),
|
||||
(sa.column("item_id"), "="),
|
||||
(sa.text("daterange(valid_from, valid_till, '[]')"), "&&"),
|
||||
using="gist",
|
||||
name=op.f("uq_bundle_items_bundle_id_item_id"),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["bundle_id"], ["stock_keeping_units.id"], name=op.f("fk_bundle_items_bundle_id_stock_keeping_units")
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["item_id"], ["stock_keeping_units.id"], name=op.f("fk_bundle_items_item_id_stock_keeping_units")
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_bundle_items")),
|
||||
)
|
||||
|
||||
inventory_type = sa.Enum("regular", "bundle", "bundle_item", name="inventorytype")
|
||||
# inventory_type.create(op.get_bind())
|
||||
op.add_column("inventories", sa.Column("type", inventory_type, server_default=sa.text("'regular'"), nullable=False))
|
||||
op.add_column("inventories", sa.Column("parent_id", sa.Uuid(), nullable=True))
|
||||
op.drop_constraint(op.f("uq_inventories_kot_id"), "inventories", type_="unique")
|
||||
op.create_unique_constraint(
|
||||
op.f("uq_inventories_kot_id"),
|
||||
"inventories",
|
||||
["kot_id", "sku_id", "is_happy_hour", "price", "type", "parent_id"],
|
||||
postgresql_nulls_not_distinct=True,
|
||||
)
|
||||
op.create_foreign_key(
|
||||
op.f("fk_inventories_parent_id_inventories"), "inventories", "inventories", ["parent_id"], ["id"]
|
||||
)
|
||||
op.add_column(
|
||||
"stock_keeping_units", sa.Column("is_bundle", sa.Boolean(), server_default=sa.text("false"), nullable=False)
|
||||
)
|
||||
mc = sa.table(
|
||||
"menu_categories",
|
||||
sa.column("id", sa.Uuid()),
|
||||
sa.column("name", sa.Unicode(length=255)),
|
||||
sa.column("is_active", sa.Boolean()),
|
||||
sa.column("is_fixture", sa.Boolean()),
|
||||
sa.column("sort_order", sa.Integer()),
|
||||
)
|
||||
|
||||
op.execute(
|
||||
mc.insert().values(
|
||||
id="6752ed9d-6f1a-4941-940a-17759dcc6720",
|
||||
name="Bundles",
|
||||
is_active=True,
|
||||
is_fixture=True,
|
||||
sort_order=0,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table("bundle_items")
|
||||
op.drop_column("stock_keeping_units", "is_bundle")
|
||||
op.drop_constraint(op.f("fk_inventories_parent_id_inventories"), "inventories", type_="foreignkey")
|
||||
op.drop_constraint(op.f("uq_inventories_kot_id"), "inventories", type_="unique")
|
||||
op.create_unique_constraint(
|
||||
op.f("uq_inventories_kot_id"),
|
||||
"inventories",
|
||||
["kot_id", "sku_id", "is_happy_hour", "price"],
|
||||
postgresql_nulls_not_distinct=False,
|
||||
)
|
||||
op.drop_column("inventories", "parent_id")
|
||||
op.drop_column("inventories", "type")
|
||||
mc = sa.table(
|
||||
"menu_categories",
|
||||
sa.column("id", sa.Uuid()),
|
||||
)
|
||||
op.execute(mc.delete().where(mc.c.id == "6752ed9d-6f1a-4941-940a-17759dcc6720"))
|
||||
Reference in new issue
Block a user