Skip to content

Instantly share code, notes, and snippets.

@onedanshow
Last active August 29, 2015 14:16
Show Gist options
  • Save onedanshow/5e08a0bb7ff337ef2fa3 to your computer and use it in GitHub Desktop.
Save onedanshow/5e08a0bb7ff337ef2fa3 to your computer and use it in GitHub Desktop.
Setup Canadian taxes in Spree
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
@BenMorganIO
Copy link

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?

@onedanshow
Copy link
Author

@BenMorganIO I've updated it find existing Spree::State records.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment