Class: Spree::Variant::VatPriceGenerator
- Inherits:
-
Object
- Object
- Spree::Variant::VatPriceGenerator
- Defined in:
- app/models/spree/variant/vat_price_generator.rb
Overview
This class generates gross prices for all countries that have VAT configured. The prices will include their respective VAT rates. It will also generate an export (net) price for any country that doesn’t have VAT.
Instance Attribute Summary collapse
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Instance Method Summary collapse
-
#initialize(variant) ⇒ VatPriceGenerator
constructor
A new instance of VatPriceGenerator.
- #run ⇒ Object
Constructor Details
#initialize(variant) ⇒ VatPriceGenerator
Returns a new instance of VatPriceGenerator.
21 22 23 |
# File 'app/models/spree/variant/vat_price_generator.rb', line 21 def initialize(variant) @variant = variant end |
Instance Attribute Details
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
19 20 21 |
# File 'app/models/spree/variant/vat_price_generator.rb', line 19 def variant @variant end |
Instance Method Details
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/spree/variant/vat_price_generator.rb', line 25 def run # Early return if there is no VAT rates in the current store. return if !variant.tax_category || variant_vat_rates.empty? country_isos_requiring_price.each do |country_iso| # Don't re-create the default price next if variant.default_price && variant.default_price.country_iso == country_iso foreign_price = find_or_initialize_price_by(country_iso, variant.default_price.currency) foreign_price.amount = variant.default_price.net_amount * (1 + vat_for_country_iso(country_iso)) end end |