File tree Expand file tree Collapse file tree 3 files changed +70
-7
lines changed Expand file tree Collapse file tree 3 files changed +70
-7
lines changed Original file line number Diff line number Diff line change 4
4
[bkell.domain.helper :as hlp]))
5
5
6
6
7
- (declare find-account-by-name )
7
+ (declare find-account-by-name
8
+ add-account )
8
9
9
10
(defn no-duplicate-account? [ds group-name account]
10
11
(let [a (find-account-by-name ds group-name (:name account))]
18
19
19
20
(every? true ? results)))
20
21
22
+ (def account-type-mappings {:expense :debit
23
+ :revenue :credit
24
+ :liability :credit
25
+ :asset :debit
26
+ :capital :credit })
27
+
28
+ (defn create-account [ds group-name aname atype]
29
+ {:pre [(some #{atype} (keys account-type-mappings))]}
30
+
31
+ (let [account {:name aname
32
+ :type atype
33
+ :counterWeight (atype account-type-mappings)}]
34
+ (add-account ds group-name account)))
35
+
21
36
(defn add-account [ds group-name account]
22
37
{:pre [(no-duplicate-account? ds group-name account)]}
23
38
67
82
:group/name gname}}}))
68
83
69
84
85
+ (defn update-account [ds id account]
86
+
87
+ ; ; can only update if no other entries point to it
88
+ ; ; can only update :name or :type (:counterWeight is automatically changed)
89
+
90
+ )
91
+
92
+
70
93
(comment
71
94
72
95
(acc/find-account-by-id ds " webkell" 123 )
Original file line number Diff line number Diff line change 3
3
[clojure.set :as set]
4
4
[slingshot.slingshot :refer [try+ throw+]]))
5
5
6
- (defn find-by-id [ds id]
7
- (adi/select ds id :first ))
6
+ (defn find-core [args]
7
+ (apply adi/select args))
8
+
9
+ (defn find-by-id
10
+ ([ds id] (find-by-id ds id [:first ]))
11
+ ([ds id opts]
12
+ (let [args [ds id]
13
+ argsF (set/union args opts)]
14
+
15
+ (find-core argsF))))
8
16
9
17
(defn find-country-by-code
10
18
([ds code]
14
22
(let [args [ds {:country {:id code}}]
15
23
argsF (set/union args opts)]
16
24
17
- (apply adi/select argsF))))
25
+ (find-core argsF))))
18
26
19
27
(defn find-currency-by-code
20
28
([ds code]
24
32
(let [args [ds {:currency {:id code}}]
25
33
argsF (set/union args opts)]
26
34
27
- (apply adi/select argsF))))
35
+ (find-core argsF))))
28
36
29
37
(defn generate-nominal-group [ds gname uname country currency]
30
38
Original file line number Diff line number Diff line change 19
19
20
20
(defn account-generator []
21
21
(gen/hash-map :name gen/string-ascii
22
- :type (gen/elements [:asset :liability :revenue :expense ])
22
+ :type (gen/elements [:asset :liability :revenue :expense :capital ])
23
23
:counterWeight (gen/elements [:debit :credit ])))
24
24
25
- (defspec test-add-an- account
25
+ (defspec test-add-account
26
26
10
27
27
(prop/for-all [account (account-generator )]
28
28
36
36
37
37
(-> result nil? not)))))
38
38
39
+ (defspec test-create-account
40
+ 5
41
+ (prop/for-all [_ gen/int]
42
+
43
+ (let [group-name " webkell"
44
+ ds (hlp/setup-db! )
45
+
46
+ aname " fubar"
47
+ atype :asset
48
+ result (acc/create-account ds group-name aname atype)]
49
+
50
+ (and (set/subset? #{:counterWeight :name :type }
51
+ (-> result first :book :accounts first keys set))
52
+
53
+ (-> result nil? not)))))
54
+
55
+ (defspec test-create-account-bad-type
56
+ 5
57
+ (prop/for-all [_ gen/int]
58
+
59
+ (let [group-name " webkell"
60
+ ds (hlp/setup-db! )
61
+
62
+ aname " fubar"
63
+ atype :fubar
64
+ result (try+ (acc/create-account ds group-name aname atype)
65
+ (catch AssertionError e &throw-context))]
66
+
67
+ (= '(:cause :message :object :stack-trace :throwable )
68
+ (sort (keys result))))))
69
+
70
+
39
71
(defspec test-restrict-duplicate-account
40
72
10
41
73
(prop/for-all [account (account-generator )]
You can’t perform that action at this time.
0 commit comments