effective_orders 4.4.2 → 4.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44adcf0828b7d2908e37632adf7188210fde69b5b31ecada6fd4e489dda14213
4
- data.tar.gz: ace9a901e39c54be2b848b6032c741d3ed5595b1d7d7f9007a1ed079d632acee
3
+ metadata.gz: 53a918aa7baad340d52b29cbee1606af5d82f823dc4f66ba94463e697f8beeb6
4
+ data.tar.gz: f27dd98180e0cc5d01ec02bbb9a693ec16b01c1874aae1f7f050b8aaf8631e0f
5
5
  SHA512:
6
- metadata.gz: 43344caae87fe3fdbe44213928cc8297b75fa5e7b437f4fe62be4270973fdbb6b984d29350ffb6c63de5d803f136b5bcbb8b1e313ad7fb9d76765139c3ad1ca4
7
- data.tar.gz: 88a9e598b60b201eb776c8ca8e0a7537f07c4352af733c5d6673ef92c88abe238a6ef495fca01fe274235d8d2f0967c3a85587916e54025725f6cb9167a0f852
6
+ metadata.gz: 79cc98eaa1bc9dc98d267e61f30045acaf2e7a4b70119706d93559b4afbf49018bb4d5161a6dc38a1fa9626815557589d57d8fb36b7710e3d02827de5be5c8ae
7
+ data.tar.gz: dc79e38e4cbfa81a1feb580dc18fbaf0dab4da8f212c659332be24acc19f08228541ea48fac35e2a2fd60e8fc2004bb589933b971af1ca98a568d277332d3839
@@ -79,6 +79,12 @@ module Effective
79
79
  }, unless: -> { (free? && EffectiveOrders.free?) || (refund? && EffectiveOrders.refund?) }
80
80
  end
81
81
 
82
+ validate(if: -> { tax_rate.present? }) do
83
+ if (tax_rate > 100.0 || (tax_rate < 0.25 && tax_rate > 0.0000))
84
+ errors.add(:tax_rate, "is invalid. expected a value between 100.0 (100%) and 0.25 (0.25%) or 0")
85
+ end
86
+ end
87
+
82
88
  # User validations -- An admin skips these when working in the admin/ namespace
83
89
  with_options unless: -> { pending? || skip_buyer_validations? } do
84
90
  validates :tax_rate, presence: { message: "can't be determined based on billing address" }
@@ -437,12 +443,13 @@ module Effective
437
443
  protected
438
444
 
439
445
  def get_tax_rate
440
- self.instance_exec(self, &EffectiveOrders.order_tax_rate_method).tap do |rate|
441
- rate = rate.to_f
442
- if (rate > 100.0 || (rate < 0.25 && rate > 0.0000))
443
- raise "expected EffectiveOrders.order_tax_rate_method to return a value between 100.0 (100%) and 0.25 (0.25%) or 0 or nil. Received #{rate}. Please return 5.25 for 5.25% tax."
444
- end
446
+ rate = instance_exec(self, &EffectiveOrders.order_tax_rate_method).to_f
447
+
448
+ if (rate > 100.0 || (rate < 0.25 && rate > 0.0000))
449
+ raise "expected EffectiveOrders.order_tax_rate_method to return a value between 100.0 (100%) and 0.25 (0.25%) or 0 or nil. Received #{rate}. Please return 5.25 for 5.25% tax."
445
450
  end
451
+
452
+ rate
446
453
  end
447
454
 
448
455
  def get_tax
@@ -454,7 +461,7 @@ module Effective
454
461
 
455
462
  def assign_order_totals
456
463
  self.subtotal = order_items.map { |oi| oi.subtotal }.sum
457
- self.tax_rate = get_tax_rate()
464
+ self.tax_rate = get_tax_rate() unless (tax_rate || 0) > 0
458
465
  self.tax = get_tax()
459
466
  self.total = subtotal + (tax || 0)
460
467
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '4.4.2'.freeze
2
+ VERSION = '4.4.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_orders
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.2
4
+ version: 4.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-16 00:00:00.000000000 Z
11
+ date: 2020-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails