sk_calc 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/sk_calc/item.rb +5 -1
- data/lib/sk_calc/version.rb +1 -1
- data/spec/sk_calc/item_spec.rb +31 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Zjk4Y2ZlMmY2N2EwMTY2NmE4ZjM2MjhkYzc2ODA3YjdmNjIwMjljNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmU2OTgyZDQwNzA5YjRlZjNhMjhjMWNkMzAyMTc4NzE3Yzk2MzIyMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MThiZTg5ZTc4OGQ0NTg4MTllNjA3OTQ3ZGQ4ZTJlNjU2OTdhODgwNjI0MGNh
|
10
|
+
OGIyZmJjNDY2NzQ5NmE3ZDE1YTdlMDM2YWM3MDRkNTU0MmExM2M3ZDgzNTBi
|
11
|
+
N2YxZjJmZGI1MmE2YWJiYmUzM2UzYWFiNWNiNzQ2NThkNDFhNWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTU0OWQyNzFiYjFjZmE5Njg4ZWI4MTEwZjdhYjlmNmMyNTg2MTU5ZTE0ZTgy
|
14
|
+
N2Y1NGI1NWU2MTFmYmVlYmRmNDM2OTBkMGMyNWRhNDNmZTVmMTUxY2E0MTZh
|
15
|
+
N2MzMDMxMTEyZmY0OTY0ZTBkNDlhMTYyOWE4NGFkZDNmODg2YTQ=
|
data/lib/sk_calc/item.rb
CHANGED
@@ -79,7 +79,7 @@ module SK::Calc::Item
|
|
79
79
|
# Use it to do calculations!
|
80
80
|
# @return [Rational]
|
81
81
|
def total
|
82
|
-
conv_price_single *
|
82
|
+
conv_price_single * conv_quantity
|
83
83
|
end
|
84
84
|
|
85
85
|
############################################
|
@@ -149,4 +149,8 @@ module SK::Calc::Item
|
|
149
149
|
((self.respond_to?(:tax) && tax) || 0).to_r
|
150
150
|
end
|
151
151
|
|
152
|
+
def conv_quantity
|
153
|
+
(quantity || 0).to_r
|
154
|
+
end
|
155
|
+
|
152
156
|
end
|
data/lib/sk_calc/version.rb
CHANGED
data/spec/sk_calc/item_spec.rb
CHANGED
@@ -34,6 +34,12 @@ describe SK::Calc do
|
|
34
34
|
i = ItemWithoutFields.new
|
35
35
|
i.send(:conv_discount).should == 0
|
36
36
|
end
|
37
|
+
|
38
|
+
it 'conv_quantity' do
|
39
|
+
i = ItemWithoutFields.new
|
40
|
+
i.send(:conv_quantity).should == 0
|
41
|
+
i.send(:conv_quantity).should be_a Rational
|
42
|
+
end
|
37
43
|
end
|
38
44
|
|
39
45
|
describe 'item calculations' do
|
@@ -46,31 +52,31 @@ describe SK::Calc do
|
|
46
52
|
@i.tax = 19.0
|
47
53
|
end
|
48
54
|
|
49
|
-
it "
|
55
|
+
it "has net_single" do
|
50
56
|
@i.net_single.should == 10.00
|
51
57
|
end
|
52
58
|
|
53
|
-
it "
|
59
|
+
it "has gross_single" do
|
54
60
|
@i.gross_single.should == 11.90
|
55
61
|
end
|
56
62
|
|
57
|
-
it "
|
63
|
+
it "has total" do
|
58
64
|
@i.total.should == 10.0
|
59
65
|
end
|
60
66
|
|
61
|
-
it "
|
67
|
+
it "has net_total" do
|
62
68
|
@i.net_total.should == 10.0
|
63
69
|
end
|
64
70
|
|
65
|
-
it "
|
71
|
+
it "has gross_total" do
|
66
72
|
@i.gross_total.should == 11.90
|
67
73
|
end
|
68
74
|
|
69
|
-
it "
|
75
|
+
it "has net_total_base" do
|
70
76
|
@i.net_total_base.should == 10.00
|
71
77
|
end
|
72
78
|
|
73
|
-
it "
|
79
|
+
it "has tax_total" do
|
74
80
|
@i.tax_total.should == 1.90
|
75
81
|
end
|
76
82
|
end
|
@@ -85,32 +91,43 @@ describe SK::Calc do
|
|
85
91
|
@i.tax = 19.0
|
86
92
|
end
|
87
93
|
|
88
|
-
it "
|
94
|
+
it "has total" do
|
89
95
|
@i.total.should == 12.605
|
90
96
|
end
|
91
97
|
|
92
|
-
it "
|
98
|
+
it "has net_total" do
|
93
99
|
@i.net_total.to_f.should == 12.61
|
94
100
|
end
|
95
101
|
|
96
|
-
it "
|
102
|
+
it "has gross_total" do
|
97
103
|
@i.gross_total.should == 15.0
|
98
104
|
end
|
99
105
|
|
100
|
-
it "
|
106
|
+
it "has net_total_base" do
|
101
107
|
@i.net_total_base.should == 12.605
|
102
108
|
end
|
103
|
-
it "
|
109
|
+
it "has net_total" do
|
104
110
|
@i.net_total.should == 12.61
|
105
111
|
end
|
106
112
|
|
107
|
-
it "
|
113
|
+
it "has tax_total_base" do
|
108
114
|
@i.tax_total_base.should == 2.39495
|
109
115
|
end
|
110
116
|
|
111
|
-
it "
|
117
|
+
it "has tax_total" do
|
112
118
|
@i.tax_total.should == 2.39
|
113
119
|
end
|
120
|
+
end
|
114
121
|
|
122
|
+
describe 'calculates with mixed values' do
|
123
|
+
|
124
|
+
it 'converts quantity to rationale' do
|
125
|
+
i = LineItem.new
|
126
|
+
i.price_single = 12345.123456
|
127
|
+
i.quantity = BigDecimal.new("1.0")
|
128
|
+
i.total.should == 12345.123456
|
129
|
+
i.total.should be_a Rational
|
130
|
+
end
|
115
131
|
end
|
132
|
+
|
116
133
|
end
|