From: Edward Delaporte Date: Fri, 5 Jun 2026 17:54:22 +0000 (-0500) Subject: WIP add ItemZone X-Git-Tag: 1.1.0~5 X-Git-Url: https://us-delaporte.pagekite.me/gitweb/matrix-shop-bot.git/commitdiff_plain/eded5d366f5bb00ed4b01d90f58a8856fb37a377?hp=487289b3008186422d6f93fffce0a5701bb11703 WIP add ItemZone --- diff --git a/matrix_shop_bot/db.py b/matrix_shop_bot/db.py index ce0d46e..464e8f1 100644 --- a/matrix_shop_bot/db.py +++ b/matrix_shop_bot/db.py @@ -24,6 +24,7 @@ class ItemStoreLink(SQLModel, table=True): class Item(SQLModel, table=True): + '''An item to shop for.''' id: int | None = Field(default=None, primary_key=True) name: str = Field(default=None, unique=True) price: Decimal | None = Field(decimal_places=2) @@ -32,10 +33,22 @@ class Item(SQLModel, table=True): def __str__(self): return f'{self.name} (#{self.id})' +class ItemZone(SQLModel, table=True): + '''Where an item is usually found. + + Matched only by loose text matching, since items come and go, over time. + ''' + id: int | None = Field(default=None, primary_key=True) + name: str = Field(default=None, unique=True) # milk + zone: str = Field(default=None, unique=False) # dairy section + + class PreferStore(SQLModel, table=True): + '''Tracks which store we are shopping at, at the moment.''' store_id: int | None = Field(default=None, foreign_key="store.id", primary_key=True) class Store(SQLModel, table=True): + '''A place to shop at.''' id: int | None = Field(default=None, primary_key=True) name: str = Field(default=None, unique=True) shopping_list: list["Item"] = Relationship(back_populates="stores", link_model=ItemStoreLink) @@ -58,8 +71,8 @@ class Store(SQLModel, table=True): return results -# May get used later... class PurchaseRecord(SQLModel, table=True): + '''Tracks when and where items were purchased.''' id: int | None = Field(default=None, primary_key=True) name: str = Field(default=None) price: Decimal | None = Field(decimal_places=2) @@ -135,6 +148,19 @@ class Data(): self.assign_store(item_id, store_id) return store_id + def assign_zone(self, item_name, zone_name): + item_id = -1 + with Session(self.engine) as session: + try: + new = ItemZone(name=item_name) + new.zone = zone_name + session.add(new) + session.commit() + item_id = new.id + except: + pass # Already assigned + return item_id + def assign_store(self, item_id, store_id): self._set_pref_store_id(store_id)