From 94820f8e08ffd66c5b241329cc75962ccf6058fd Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 9 Aug 2023 15:26:05 +0200 Subject: [PATCH] Prevent hard-errors when VatPriceGenerator is invoked without a default price --- core/app/models/spree/price.rb | 2 ++ core/app/models/spree/variant/vat_price_generator.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/core/app/models/spree/price.rb b/core/app/models/spree/price.rb index 36a957468db..2e72da726e4 100644 --- a/core/app/models/spree/price.rb +++ b/core/app/models/spree/price.rb @@ -46,6 +46,8 @@ def price=(price) end def net_amount + return nil unless amount + amount / (1 + sum_of_vat_amounts) end diff --git a/core/app/models/spree/variant/vat_price_generator.rb b/core/app/models/spree/variant/vat_price_generator.rb index 1b7a0bd5b21..5a7be47fb3b 100644 --- a/core/app/models/spree/variant/vat_price_generator.rb +++ b/core/app/models/spree/variant/vat_price_generator.rb @@ -25,6 +25,7 @@ def initialize(variant) def run # Early return if there is no VAT rates in the current store. return if !variant.tax_category || variant_vat_rates.empty? + return unless variant.default_price.net_amount country_isos_requiring_price.each do |country_iso| # Don't re-create the default price