   (select-lots
     [_ criteria options]
     (validate-criteria criteria ::lot-criteria)
-    (query db-spec (-> (h/select :*)
-                       (h/from :lots)
-                       (h/where (map->where criteria))
-                       (append-limit options)
-                       (append-sort options))))
+    (let [entity-id (:entity-id criteria)
+          filtered-criteria (dissoc criteria :entity-id)]
+      (query db-spec (-> (h/select :*)
+                         (h/from :lots)
+                         (h/where (map->where filtered-criteria))
+                         (append-entity-id-to-lot-query entity-id)
+                         (append-limit options)
+                         (append-sort options)))))
 
   (delete-lot
     [_ id]

   (if (and criteria (seq criteria))
     (h/merge-where sql (map->where criteria options))
     sql)))

(defn- descending-sort?
  "Returns a boolean value indicating whether or not

(s/def ::transaction-id uuid?)
(s/def ::date (partial instance? LocalDate))
(s/def ::nilable-date #(or (instance? LocalDate %) (nil? %)))
(s/def ::lot-criteria
  (s/and (fn [model]
           (when-let [v (some #(get model %) #{:id :account-id :commodity-id :entity-id})]
             (integer? v)))
         (s/keys :opt-un [::id ::account-id ::commodity-id ::entity-id])))

(s/def ::lot-transaction-criteria
  (fn [c] (integer? (some #(% c) [:id :lot-id :transaction-id]))))
