dorsale 3.13.0 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6523b32ed6ded0a2c2973f262d1c4c653e5686b4e46092598b28f7361ac59490
4
- data.tar.gz: 2041d1694e962515f16ba41179fa7feb7059f4afae4c68064cecb0a24c85f9fc
3
+ metadata.gz: ebdaffde3d6482e50a41707f99a6e11672e92d70217bc78a53998597643c6f7a
4
+ data.tar.gz: 89a6e804ec650c078e4fc40fdd88c2261e625c889c6125daee6dc90870ed66b2
5
5
  SHA512:
6
- metadata.gz: c87828175a390e626c9d924b5f03f08ffd2c7499c15325469200674c632d5b2f5a12c53f54aef24007418b08e27ce8f9cd167bdd92314baa751d6342b32e46cd
7
- data.tar.gz: '09140a1d504656c7c02086c420ed0a1805a4f52f9b3176f7cbb48c141ac71121df2eb785f4e398e0b1e0294b45cddf9f6f9bc9c4eacfd96efe1370dfd9cdd7f1'
6
+ metadata.gz: 6c37a324dc797b8b2b0fabfe48c23a115d838b462fd54b7f6bde6548897a7e266983c0576c059cbf1694db245c0102de1725ef4b36c133b9d8ac98841b88c47d
7
+ data.tar.gz: 21fdf0df6905f79ba1b0acac5d044723e50e15507a39729eea45578f7daf672ab1f4ec024aea193696156470772f3e35da1e9c59349e93a64b0d8042e4609e7c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Next version
4
4
 
5
+ ## 3.14.0
6
+ - Add `Dorsale::BillingMachine.vat_round_by_line` option
7
+ - Revert default `vat_round_by_line` value introduced in 3.10.0 (it's now false again)
8
+
5
9
  ## 3.13.0
6
10
  - Rails 5.2 compatible
7
11
 
@@ -1,5 +1,7 @@
1
1
  @BillingMachine = {}
2
2
 
3
+ BillingMachine.vat_round_by_line = <%= Dorsale::BillingMachine.vat_round_by_line %>
4
+
3
5
  BillingMachine.settings =
4
6
  precision : 2
5
7
  thousand : " " # nbsp
@@ -18,7 +20,7 @@ BillingMachine.num2str = (num) ->
18
20
  accounting.formatNumber(num, settings.precision, settings.thousand, settings.decimal)
19
21
 
20
22
  BillingMachine.round2 = (num) ->
21
- return +(Math.round(num + "e+2") + "e-2")
23
+ return +(Math.round(num + "e+2") + "e-2")
22
24
 
23
25
  BillingMachine.updateTotals = ->
24
26
  total_excluding_taxes = 0.0
@@ -42,7 +44,7 @@ BillingMachine.updateTotals = ->
42
44
  discount_rate = commercial_discount / raw_total_excluding_taxes
43
45
 
44
46
  # VAT amount based on each line total with discount rate
45
- vat_amount = 0.0
47
+ total_vat_amount = 0.0
46
48
  $("#billing_machine-form .line").map ->
47
49
  return if parseInt($(this).find("input[name*=destroy]").val()) == 1
48
50
 
@@ -55,11 +57,13 @@ BillingMachine.updateTotals = ->
55
57
 
56
58
  line_total = BillingMachine.str2num $(this).find(".line-total input").val()
57
59
  discounted_line_total = line_total - (line_total * discount_rate)
58
- line_vat_amount = BillingMachine.round2(discounted_line_total * vat_rate / 100)
59
- vat_amount += line_vat_amount
60
- $(".vat_amount input").val BillingMachine.num2str vat_amount
60
+ line_vat_amount = discounted_line_total * vat_rate / 100
61
+ line_vat_amount = BillingMachine.round2(line_vat_amount) if BillingMachine.vat_round_by_line
62
+ total_vat_amount += line_vat_amount
63
+ total_vat_amount = BillingMachine.round2(total_vat_amount)
64
+ $(".vat_amount input").val BillingMachine.num2str total_vat_amount
61
65
 
62
- total_including_taxes = total_excluding_taxes + vat_amount
66
+ total_including_taxes = total_excluding_taxes + total_vat_amount
63
67
  $(".total_including_taxes input").val BillingMachine.num2str total_including_taxes
64
68
 
65
69
  # Advances is for invoices only, not for quotations
@@ -13,6 +13,13 @@ module Dorsale::BillingMachine
13
13
  @vat_mode = new_mode
14
14
  end
15
15
 
16
+ def vat_round_by_line
17
+ @vat_round_by_line = false if @vat_round_by_line.nil?
18
+ @vat_round_by_line
19
+ end
20
+
21
+ attr_writer :vat_round_by_line
22
+
16
23
  def invoice_pdf_model
17
24
  "::Dorsale::BillingMachine::Invoice#{vat_mode.to_s.capitalize}VatPdf".constantize
18
25
  end
@@ -57,7 +57,7 @@ class Dorsale::BillingMachine::Invoice < ::Dorsale::ApplicationRecord
57
57
  lines.each(&:update_total)
58
58
  apply_vat_rate_to_lines
59
59
 
60
- lines_sum = lines.map(&:total).sum
60
+ lines_sum = lines.map(&:total).sum.round(2)
61
61
 
62
62
  self.total_excluding_taxes = lines_sum - commercial_discount
63
63
 
@@ -71,9 +71,13 @@ class Dorsale::BillingMachine::Invoice < ::Dorsale::ApplicationRecord
71
71
 
72
72
  lines.each do |line|
73
73
  line_total = line.total - (line.total * discount_rate)
74
- self.vat_amount += (line_total * line.vat_rate / 100.0).round(2)
74
+ line_vat = (line_total * line.vat_rate / 100.0)
75
+ line_vat = line_vat.round(2) if Dorsale::BillingMachine.vat_round_by_line
76
+ self.vat_amount += line_vat
75
77
  end
76
78
 
79
+ self.vat_amount = vat_amount.round(2)
80
+
77
81
  self.total_including_taxes = total_excluding_taxes + vat_amount
78
82
  self.balance = total_including_taxes - advance
79
83
  end
@@ -76,9 +76,13 @@ class Dorsale::BillingMachine::Quotation < ::Dorsale::ApplicationRecord
76
76
 
77
77
  lines.each do |line|
78
78
  line_total = line.total - (line.total * discount_rate)
79
- self.vat_amount += (line_total * line.vat_rate / 100.0).round(2)
79
+ line_vat = (line_total * line.vat_rate / 100.0)
80
+ line_vat = line_vat.round(2) if Dorsale::BillingMachine.vat_round_by_line
81
+ self.vat_amount += line_vat
80
82
  end
81
83
 
84
+ self.vat_amount = vat_amount.round(2)
85
+
82
86
  self.total_including_taxes = total_excluding_taxes + vat_amount
83
87
  end
84
88
 
@@ -1,3 +1,3 @@
1
1
  module Dorsale
2
- VERSION = "3.13.0"
2
+ VERSION = "3.14.0"
3
3
  end
@@ -42,11 +42,11 @@ describe Dorsale::BillingMachine::InvoiceLine, type: :model do
42
42
 
43
43
  it "should update the total upon save" do
44
44
  line = create(:billing_machine_invoice_line, quantity: 12.34, unit_price: 12.34, total: 0)
45
- expect(line.total).to eq(152.28)
45
+ expect(line.total.to_f).to eq 152.28
46
46
  end
47
47
 
48
48
  it "should update the total gracefully with invalid data" do
49
49
  line = create(:billing_machine_invoice_line, quantity: nil, unit_price: nil, total: 0)
50
- expect(line.total).to eq(0)
50
+ expect(line.total.to_f).to eq 0
51
51
  end
52
52
  end
@@ -202,30 +202,47 @@ describe Dorsale::BillingMachine::Invoice, type: :model do
202
202
  expect(invoice.balance).to eq(108)
203
203
  end
204
204
 
205
- it "should round numbers" do
206
- invoice = create(:billing_machine_invoice,
207
- :commercial_discount => 0,
208
- )
209
-
210
- create(:billing_machine_invoice_line,
211
- :quantity => 12.34,
212
- :unit_price => 12.34,
213
- :vat_rate => 20,
214
- :invoice => invoice,
215
- ) # total 152.28
216
-
217
- create(:billing_machine_invoice_line,
218
- :quantity => 12.34,
219
- :unit_price => 12.34,
220
- :vat_rate => 20,
221
- :invoice => invoice,
222
- ) # total 152.28
205
+ describe "VAT round" do
206
+ let(:invoice) {
207
+ invoice = create(:billing_machine_invoice,
208
+ :commercial_discount => 0,
209
+ )
210
+
211
+ create(:billing_machine_invoice_line,
212
+ :quantity => 12.34,
213
+ :unit_price => 12.34,
214
+ :vat_rate => 20,
215
+ :invoice => invoice,
216
+ ) # vat 30.45512 / total 152.2756
217
+
218
+ create(:billing_machine_invoice_line,
219
+ :quantity => 12.34,
220
+ :unit_price => 12.34,
221
+ :vat_rate => 20,
222
+ :invoice => invoice,
223
+ ) # vat 30.45512 / total 152.2756
224
+
225
+ invoice
226
+ }
227
+
228
+ after { Dorsale::BillingMachine.vat_round_by_line = nil }
229
+
230
+ it "should round VAT by line" do
231
+ Dorsale::BillingMachine.vat_round_by_line = true
232
+ expect(invoice.total_excluding_taxes.to_f).to eq(304.56)
233
+ expect(invoice.vat_amount.to_f).to eq(60.92)
234
+ expect(invoice.total_including_taxes.to_f).to eq(365.48)
235
+ expect(invoice.balance.to_f).to eq(365.48)
236
+ end
223
237
 
224
- expect(invoice.total_excluding_taxes).to eq(304.56)
225
- expect(invoice.vat_amount).to eq(60.92)
226
- expect(invoice.total_including_taxes).to eq(365.48)
227
- expect(invoice.balance).to eq(365.48)
228
- end
238
+ it "should round VAT globally" do
239
+ Dorsale::BillingMachine.vat_round_by_line = false
240
+ expect(invoice.total_excluding_taxes.to_f).to eq(304.56)
241
+ expect(invoice.vat_amount.to_f).to eq(60.91)
242
+ expect(invoice.total_including_taxes.to_f).to eq(365.47)
243
+ expect(invoice.balance.to_f).to eq(365.47)
244
+ end
245
+ end # describe "VAT round"
229
246
 
230
247
  it "should work fine even with empty lines" do
231
248
  invoice = create(:billing_machine_invoice)
@@ -41,11 +41,11 @@ describe Dorsale::BillingMachine::QuotationLine do
41
41
 
42
42
  it "should update the total upon save" do
43
43
  line = create(:billing_machine_quotation_line, quantity: 12.34, unit_price: 12.34, total: 0)
44
- expect(line.total).to eq(152.28)
44
+ expect(line.total.to_f).to eq 152.28
45
45
  end
46
46
 
47
47
  it "should update the total gracefully with invalid data" do
48
48
  line = create(:billing_machine_quotation_line, quantity: nil, unit_price: nil, total: 0)
49
- expect(line.total).to eq(0)
49
+ expect(line.total.to_f).to eq 0
50
50
  end
51
51
  end
@@ -152,30 +152,47 @@ describe Dorsale::BillingMachine::Quotation do
152
152
  Dorsale::BillingMachine.vat_mode = :single
153
153
  end
154
154
 
155
- it "should round numbers" do
156
- quotation = create(:billing_machine_quotation,
157
- :commercial_discount => 0,
158
- )
159
-
160
- create(:billing_machine_quotation_line,
161
- :quantity => 12.34,
162
- :unit_price => 12.34,
163
- :vat_rate => 20,
164
- :quotation => quotation,
165
- ) # total 152.28
166
-
167
- create(:billing_machine_quotation_line,
168
- :quantity => 12.34,
169
- :unit_price => 12.34,
170
- :vat_rate => 20,
171
- :quotation => quotation,
172
- ) # total 152.28
155
+ describe "VAT round" do
156
+ let(:quotation) {
157
+ quotation = create(:billing_machine_quotation,
158
+ :commercial_discount => 0,
159
+ )
160
+
161
+ create(:billing_machine_quotation_line,
162
+ :quantity => 12.34,
163
+ :unit_price => 12.34,
164
+ :vat_rate => 20,
165
+ :quotation => quotation,
166
+ ) # vat 30.45512 / total 152.2756
167
+
168
+ create(:billing_machine_quotation_line,
169
+ :quantity => 12.34,
170
+ :unit_price => 12.34,
171
+ :vat_rate => 20,
172
+ :quotation => quotation,
173
+ ) # vat 30.45512 / total 152.2756
174
+
175
+ quotation
176
+ }
177
+
178
+ after { Dorsale::BillingMachine.vat_round_by_line = nil }
179
+
180
+ it "should round VAT by line" do
181
+ Dorsale::BillingMachine.vat_round_by_line = true
182
+ expect(quotation.total_excluding_taxes.to_f).to eq(304.56)
183
+ expect(quotation.vat_amount.to_f).to eq(60.92)
184
+ expect(quotation.total_including_taxes.to_f).to eq(365.48)
185
+ expect(quotation.balance.to_f).to eq(365.48)
186
+ end
173
187
 
174
- expect(quotation.total_excluding_taxes).to eq(304.56)
175
- expect(quotation.vat_amount).to eq(60.92)
176
- expect(quotation.total_including_taxes).to eq(365.48)
177
- expect(quotation.balance).to eq(365.48)
178
- end
188
+ it "should round VAT globally" do
189
+ Dorsale::BillingMachine.vat_round_by_line = false
190
+ expect(quotation.total_excluding_taxes.to_f).to eq(304.56)
191
+ expect(quotation.vat_amount.to_f).to eq(60.91)
192
+ expect(quotation.total_including_taxes.to_f).to eq(365.47)
193
+ expect(quotation.balance.to_f).to eq(365.47)
194
+ end
195
+ end # describe "VAT round" do
179
196
 
180
197
  it "should work fine even with empty lines" do
181
198
  quotation = create(:billing_machine_quotation, commercial_discount: nil)
@@ -5,31 +5,53 @@ RSpec.describe Dorsale::BillingMachine do
5
5
  ::Dorsale::BillingMachine
6
6
  }
7
7
 
8
- it "default vat_mode should be :single" do
9
- expect(bm.vat_mode).to eq :single
10
- expect(bm.invoice_pdf_model).to eq Dorsale::BillingMachine::InvoiceSingleVatPdf
11
- expect(bm.quotation_pdf_model).to eq Dorsale::BillingMachine::QuotationSingleVatPdf
12
- end
13
-
14
- it "vat_mode should accept :multiple value" do
15
- bm.vat_mode = :multiple
16
- expect(bm.vat_mode).to eq :multiple
17
- expect(bm.invoice_pdf_model).to eq Dorsale::BillingMachine::InvoiceMultipleVatPdf
18
- expect(bm.quotation_pdf_model).to eq Dorsale::BillingMachine::QuotationMultipleVatPdf
19
- end
20
-
21
- it "vat_mode should not accept :abc value" do
22
- expect {
23
- bm.vat_mode = :abc
24
- }.to raise_error(RuntimeError)
25
- end
26
-
27
- it "default currency should be €" do
28
- expect(bm.default_currency).to eq "€"
29
- end
30
-
31
- it "assign an other default currency" do
32
- bm.default_currency = "$"
33
- expect(bm.default_currency).to eq "$"
34
- end
8
+ describe "::vat_mode" do
9
+ it "default vat_mode should be :single" do
10
+ expect(bm.vat_mode).to eq :single
11
+ expect(bm.invoice_pdf_model).to eq Dorsale::BillingMachine::InvoiceSingleVatPdf
12
+ expect(bm.quotation_pdf_model).to eq Dorsale::BillingMachine::QuotationSingleVatPdf
13
+ end
14
+
15
+ it "vat_mode should accept :multiple value" do
16
+ bm.vat_mode = :multiple
17
+ expect(bm.vat_mode).to eq :multiple
18
+ expect(bm.invoice_pdf_model).to eq Dorsale::BillingMachine::InvoiceMultipleVatPdf
19
+ expect(bm.quotation_pdf_model).to eq Dorsale::BillingMachine::QuotationMultipleVatPdf
20
+ end
21
+
22
+ it "vat_mode should not accept :abc value" do
23
+ expect {
24
+ bm.vat_mode = :abc
25
+ }.to raise_error(RuntimeError)
26
+ end
27
+ end # describe "::vat_mode"
28
+
29
+ describe "::vat_round_by_line" do
30
+ after { Dorsale::BillingMachine.vat_round_by_line = nil }
31
+
32
+ it "should return default value" do
33
+ expect(Dorsale::BillingMachine.vat_round_by_line).to eq false
34
+ end
35
+
36
+ it "should assign false value" do
37
+ Dorsale::BillingMachine.vat_round_by_line = false
38
+ expect(Dorsale::BillingMachine.vat_round_by_line).to eq false
39
+ end
40
+
41
+ it "should assign true value" do
42
+ Dorsale::BillingMachine.vat_round_by_line = true
43
+ expect(Dorsale::BillingMachine.vat_round_by_line).to eq true
44
+ end
45
+ end # describe "::vat_round_by_line"
46
+
47
+ describe "::default_currency" do
48
+ it "default currency should be €" do
49
+ expect(bm.default_currency).to eq "€"
50
+ end
51
+
52
+ it "assign an other default currency" do
53
+ bm.default_currency = "$"
54
+ expect(bm.default_currency).to eq "$"
55
+ end
56
+ end # describe "::default_currency"
35
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorsale
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.0
4
+ version: 3.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - agilidée
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-16 00:00:00.000000000 Z
11
+ date: 2019-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -433,7 +433,7 @@ files:
433
433
  - app/assets/javascripts/dorsale/dependencies.coffee
434
434
  - app/assets/javascripts/dorsale/engines.coffee
435
435
  - app/assets/javascripts/dorsale/engines/alexandrie.coffee
436
- - app/assets/javascripts/dorsale/engines/billing_machine.coffee
436
+ - app/assets/javascripts/dorsale/engines/billing_machine.coffee.erb
437
437
  - app/assets/javascripts/dorsale/engines/customer_vault.coffee
438
438
  - app/assets/javascripts/dorsale/engines/flyboy.coffee
439
439
  - app/assets/javascripts/url.min.js