Commit bd6cb80a authored by Alain M. Lafon's avatar Alain M. Lafon

Merge branch 'option-to-ignore-warnings'

parents e2482cd8 c94c7423
......@@ -31,8 +31,15 @@
:iso-string (s/and string? match-iso-date)))
(s/def ::property string?)
(s/def ::ignore-warnings (s/coll-of ::property))
(s/def ::event (s/keys :req-un [::type
::date]))
::date]
:opt-un [::ignore-warnings]))
(s/def ::events (s/coll-of ::event))
......@@ -51,6 +58,11 @@
event))
(defn ignore-warning? [evt key]
(->> (get evt :ignore-warnings [])
(util/include? (name key))))
(defn harmonize [event]
(->> event
(harmonize-date-field :date)
......
......@@ -274,9 +274,10 @@
(let [settlement-total (:net-total evt)
invoice-total (->> evt :invoice :net-total)
coverage (/ settlement-total invoice-total)]
(if (or (< coverage 0.98)
(> coverage 1.02))
(util/warn (str "Coverage " coverage " on settlement for " (:invoice-no evt))))
(if (and (not (common/ignore-warning? evt :coverage))
(or (< coverage 0.98)
(> coverage 1.02)))
(util/warn (str "Coverage " coverage " on settlement for " (:invoice-no evt) " " (-> evt :invoice :description))))
(assoc* evt :coverage coverage))
evt))
......
......@@ -81,14 +81,19 @@
(comp js/parseFloat (partial sprintf "%.2f")))
(defn include? [item collection]
(some #{item} collection))
(defn assoc*
"Like `assoc` but adds `key` only if hashmap does not already have
`key` (preset). Warns if preset and `value` differ. (Also takes only
one `key` and `value`.)"
[hashmap key value]
(if-let [preset (key hashmap)]
(do
(if (not= preset value)
(let [ignored (get hashmap :ignore-warnings [])]
(if (and (not= preset value)
(not (include? (name key) ignored)))
(warn (str "Overwriting " key " " value " with diffing preset " preset)))
hashmap)
(assoc hashmap key value)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment