Last active
August 29, 2015 14:16
-
-
Save onedanshow/5e08a0bb7ff337ef2fa3 to your computer and use it in GitHub Desktop.
Setup Canadian taxes in Spree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if country = Spree::Country.find_by(name: 'Canada') | |
tax_cat = Spree::TaxCategory.create!( | |
name: "Canadian Tax", | |
description: "Products sold in Canada", | |
is_default: true) | |
gst_opts = { | |
name: 'GST', | |
amount: 0.05, | |
tax_category: tax_cat, | |
calculator_type:"Spree::Calculator::DefaultTax" | |
} | |
hst_opts = { | |
name: 'HST', | |
amount: 0.13, | |
tax_category: tax_cat, | |
calculator_type:"Spree::Calculator::DefaultTax" | |
} | |
states = Spree::State.where(country:country) | |
# Canadian territories | |
s = states.where("abbr = 'NT' OR abbr = 'YT' OR abbr = 'NU'") | |
z = Spree::Zone.create! name: 'Canadian Territories', description: 'Northwest Territories + Nunavut + Yukon', state_ids: s.ids | |
Spree::TaxRate.create! gst_opts.merge( zone: z ) | |
# Alberta | |
s = states.where("abbr = 'AB'") | |
z = Spree::Zone.create! name: 'Alberta', description: 'Alberta', state_ids: s.ids | |
Spree::TaxRate.create! gst_opts.merge( zone: z ) | |
# British Columbia | |
s = states.where("abbr = 'BC'") | |
z = Spree::Zone.create! name: 'British Columbia', description: 'British Columbia', state_ids: s.ids | |
Spree::TaxRate.create! gst_opts.merge( zone: z ) | |
# Manitoba | |
s = states.where("abbr = 'MB'") | |
z = Spree::Zone.create! name: 'Manitoba', description: 'Manitoba', state_ids: s.ids | |
Spree::TaxRate.create! gst_opts.merge( zone: z ) | |
# New Brunswick | |
s = states.where("abbr = 'NB'") | |
z = Spree::Zone.create! name: 'New Brunswick', description: 'New Brunswick', state_ids: s.ids | |
Spree::TaxRate.create! hst_opts.merge( zone: z ) | |
# Newfoundland & Labrador | |
s = states.where("abbr = 'NL'") | |
z = Spree::Zone.create! name: 'Newfoundland & Labrador', description: 'Newfoundland & Labrador', state_ids: s.ids | |
Spree::TaxRate.create! hst_opts.merge( zone: z ) | |
# Nova Scotia | |
s = states.where("abbr = 'NS'") | |
z = Spree::Zone.create! name: 'Nova Scotia', description: 'Nova Scotia', state_ids: s.ids | |
Spree::TaxRate.create! hst_opts.merge( zone: z, amount: 0.15 ) | |
# Ontario | |
s = states.where("abbr = 'ON'") | |
z = Spree::Zone.create! name: 'Ontario', description: 'Ontario', state_ids: s.ids | |
Spree::TaxRate.create! hst_opts.merge( zone: z ) | |
# Prince Edward Island | |
s = states.where("abbr = 'PE'") | |
z = Spree::Zone.create! name: 'Prince Edward Island', description: 'Prince Edward Island', state_ids: s.ids | |
Spree::TaxRate.create! hst_opts.merge( zone: z, amount: 0.14 ) | |
# Quebec | |
s = states.where("abbr = 'QC'") | |
z = Spree::Zone.create! name: 'Quebec', description: 'Quebec', state_ids: s.ids | |
Spree::TaxRate.create! gst_opts.merge( zone: z ) | |
# Saskatchewan | |
s = states.where("abbr = 'SK'") | |
z = Spree::Zone.create! name: 'Saskatchewan', description: 'Saskatchewan', state_ids: s.ids | |
Spree::TaxRate.create! gst_opts.merge( zone: z ) | |
puts "Added Canadian taxes to database" | |
else | |
puts "ERROR: Could not find country of 'Canada'" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The provinces and territories are created by Spree in the seeds since 2.3 I believe. Maybe update for
#find_by
?Maybe add
PST
as well?