Sha256: 65ab6a2e408c71d823c95d3d77c6c8343dfbfb2dbc4333f2bf892070a6a75270
Contents?: true
Size: 1.58 KB
Versions: 2
Compression:
Stored size: 1.58 KB
Contents
class Calculator::Vat < Calculator def self.description I18n.t("vat") end def self.register super TaxRate.register_calculator(self) end def self.calculate_tax_on(product_or_variant) product = product_or_variant.try(:product) || product_or_variant (product_or_variant.price * product.effective_tax_rate).round(2, BigDecimal::ROUND_HALF_UP) end # computes vat for line_items associated with order, and tax rate and # now coupon discounts are taken into account in tax calcs # and tax is added to shipment if :shipment_inc_vat is set # coupons and shipment are applied if this object is the rate for the default category # (also items with no category get this rate applied) def compute(order) rate = self.calculable tax = 0 if rate.tax_category.is_default order.adjustments.each do | adjust | next if adjust.originator_type == "TaxRate" next if adjust.originator_type == "ShippingMethod" and not Spree::Config[:shipment_inc_vat] tax += (adjust.amount * rate.amount).round(2, BigDecimal::ROUND_HALF_UP) end end order.line_items.each do | line_item| if line_item.product.tax_category #only apply this calculator to products assigned this rates category next unless line_item.product.tax_category == rate.tax_category else next unless rate.tax_category.is_default # and apply to products with no category, if this is the default rate end tax += (line_item.price * rate.amount).round(2, BigDecimal::ROUND_HALF_UP) * line_item.quantity end tax end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
spree_core-0.70.0.rc2 | app/models/calculator/vat.rb |
spree_core-0.70.RC1 | app/models/calculator/vat.rb |