From 14776e196d677db4c447e72770140085ecd7b1c8 Mon Sep 17 00:00:00 2001 From: Daniel O'Connell Date: Wed, 7 Oct 2020 17:21:09 +0200 Subject: [PATCH] add list worklogs --- README.md | 21 ++++++++++++++++++--- src/invoices/timesheets.clj | 8 +++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index aea260a..89fb434 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,9 @@ The buyer can have the following keys ### Items -The list of items should contain maps with a required :title, optional :vat (if not provided it is assumed that -item is VAT free), :to (the date from which this item is valid), :from (the date till which this item is valid), -:notes (a list of extra notes to be added at the bottom of the invoice) and a key providing the cost of the item. +The list of items should contain maps with a required `:title`, optional `:vat` (if not provided it is assumed that +item is VAT free), `:to` (the date from which this item is valid), `:from` (the date till which this item is valid), +`:notes` (a list of extra notes to be added at the bottom of the invoice) and a key providing the cost of the item. The price can be provided in one of the following ways: * :netto - is a set price and will be displayed as provided @@ -117,6 +117,19 @@ must contain a `:type` key that describes the provider, and a `:ids` list, which should contain all worklog ids that can be found in the given worklog. These ids are used to link worklog values with items via the `:worklog` key of items. +#### Simple lists + +This is the basic worklog, i.e. a list of months with the amount worked provided (hours by default). +The unit can be changed via the `unit` key and can be one of `:hour` or `:day`. Below is an example: + + :worklogs [{:type :list + :ids [:cows-R-us] + :worklogs {"2020-09" {:count 12 :unit :day} + "2020-10" {:count 12 :unit :day} + "2020-11" {:count 54 :unit :hour} + "2020-12" {:count 5 :unit :day} + "2021-02" {:count 20 :unit :day}}}] + #### Jira See [Jira's](https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-basic-authentication/) @@ -175,6 +188,8 @@ have an :email key set and a :smtp key with the :smtp settings for the email ser :pass "asd;l;kjsdfkljld" :ssl true}}] +The `:email` value can be a string (i.e. a single email address) or a list of strings. + ## Callbacks A list of additional commands can be added to each invoice. Each command will be called with diff --git a/src/invoices/timesheets.clj b/src/invoices/timesheets.clj index bdc22b2..5d27872 100644 --- a/src/invoices/timesheets.clj +++ b/src/invoices/timesheets.clj @@ -30,12 +30,18 @@ (clojure.core/when (:jira-user credentials) (jira-timesheet (me credentials) (prev-month when) credentials))) +(defn hours-from-list [date {:keys [ids worklogs]}] + (let [month (-> date (.toString) (subs 0 7)) + {:keys [count unit]} (get worklogs month) + worklog {:worked (and count (* count ({:hour 1 :day 8} unit 1)))}] + (map (partial assoc worklog :id) ids))) (defn get-timesheet [month {type :type offset :month-offset :as creds}] (let [month (-> month (.plusMonths (or offset 0)))] (condp = type :jira (jira-timesheet (me creds) month creds) - :imap (email/get-worklogs month creds)))) + :imap (email/get-worklogs month creds) + :list (hours-from-list month creds)))) (defn timesheets "Return timesheets for the given month from the given worklogs."