-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds checkbox to reverse the vat on the admin product page
- Loading branch information
Torsten Rüger
committed
Aug 22, 2011
1 parent
8f599b7
commit ce0430f
Showing
3 changed files
with
30 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Admin::ProductsHelper.module_eval do | ||
# returns the price of the product to show for display purposes | ||
def product_price(product_or_variant, options={}) | ||
options.assert_valid_keys(:format_as_currency, :show_vat_text) | ||
options.reverse_merge! :format_as_currency => true, :show_vat_text => Spree::Config[:show_price_inc_vat] | ||
|
||
amount = product_or_variant.price | ||
amount += Calculator::Vat.calculate_tax_on(product_or_variant) if Spree::Config[:show_price_inc_vat] | ||
options.delete(:format_as_currency) ? format_price(amount, options) : amount | ||
end | ||
end | ||
|
||
Admin::ProductsController.class_eval do | ||
before_filter :vat_fix , :only => :update | ||
|
||
def vat_fix | ||
return unless params[:price_includes_vat] | ||
taxid = params[:product][:tax_category_id] | ||
rate = TaxRate.find( taxid ) if taxid | ||
rate = Calculator::Vat.default_rates.first unless rate | ||
rate = TaxRate.first unless rate | ||
price = params[:product][:price].to_f | ||
price = price / (1 + rate.amount) | ||
puts "Adjusted price by #{rate.amount} to #{price} (was #{params[:product][:price]})" | ||
params[:product][:price] = price | ||
end | ||
end |
This file contains 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
This file contains 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