+ if(self.purchase_date):
+ return f'- [x] {self.name} (#{self.id})'
+ else:
+ 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)
+
+def _get_item_zone(item_name, session) -> str:
+ zone = session.exec(select(ItemZone).where(func.lower(item_name).contains(func.lower(ItemZone.name)))).first()
+ if zone:
+ return zone.zone
+ return 'No Zone Assigned'
+
+def _get_pretty_shopping_list(store_id, session) -> List[str]:
+ store = session.exec(_get_with_id(Store, store_id)).first()
+ results = []
+ results.append(f' ## {store.name}')
+ items = store.shopping_list
+ if not items:
+ results.append(f'-- Nothing to shop for at {store.name} --')
+
+ zones = {}
+
+ for item in items:
+ zone = str(_get_item_zone(item.name, session)).title() # Title Case
+ if not zone in zones:
+ zones[zone] = []
+ zones[zone].append(str(item).title())
+ for zone in zones:
+ zones[zone].sort()
+ results.append(f' ### {zone}')
+ for item in zones[zone]:
+ results.append(item)
+ return results