From 9f48531b513be0f233eddbdfce8be2e071f3539a Mon Sep 17 00:00:00 2001 From: Juan Carlos Ruiz Date: Tue, 12 Mar 2019 14:11:49 -0600 Subject: Add incomplete_address? check method Solidus has deprecated the `empty?` method on https://github.com/solidusio/solidus/pull/1686 . This adds a private `incomplete_address?` method for avoid future problems and remove the deprecation warning in projects that uses this gem. --- lib/super_good/solidus_taxjar/tax_calculator.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/super_good') diff --git a/lib/super_good/solidus_taxjar/tax_calculator.rb b/lib/super_good/solidus_taxjar/tax_calculator.rb index 5052814..327e248 100644 --- a/lib/super_good/solidus_taxjar/tax_calculator.rb +++ b/lib/super_good/solidus_taxjar/tax_calculator.rb @@ -12,7 +12,7 @@ module SuperGood def calculate return no_tax if SuperGood::SolidusTaxJar.test_mode - return no_tax if order.tax_address.empty? || order.line_items.none? + return no_tax if incomplete_address?(order.tax_address) || order.line_items.none? return no_tax unless taxable_address? order.tax_address cache do @@ -150,6 +150,16 @@ module SuperGood def line_item_tax_label(taxjar_line_item, spree_line_item) SuperGood::SolidusTaxJar.line_item_tax_label_maker.(taxjar_line_item, spree_line_item) end + + def incomplete_address?(tax_address) + [ + tax_address.address1, + tax_address.city, + tax_address&.state&.abbr || tax_address.state_name, + tax_address.zipcode, + tax_address.country.iso + ].any?(&:blank?) + end end end end -- cgit v1.2.3