create or replace view warehouse_stock as ( select it.upc as upc, l.name as warehouse, it.name as name, it.package as package, date(b.received) as received, date(b.best_until) as best_until, i.quantity as quantity from itemsonshelf i join batches b on i.batch = b.id join items it on it.sku = b.sku join locations l on l.id = i."location" join locationtypes l2 on l.loctype = l2.id where l2.name = 'warehouse' and it.current = true )