Module: Invoicing::Taxable::ActMethods

Defined in:
lib/invoicing/taxable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_taxable(*args) ⇒ Object

Declares that one or more attributes on this model object store monetary values to which tax may be applied. Takes one or more attribute names, followed by an options hash:

:tax_logic

Object with instance methods apply_tax, remove_tax, tax_info and tax_details as documented in the Taxable module. Required.

:currency

The name of the attribute/database column which stores the ISO 4217 currency code for the monetary amounts in this model object. Required if the column is not called currency.

acts_as_taxable implies acts_as_currency_value with the same options. See the Taxable for details.



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/invoicing/taxable.rb', line 221

def acts_as_taxable(*args)
  Invoicing::ClassInfo.acts_as(Invoicing::Taxable, self, args)

  attrs = taxable_class_info.new_args.map{|a| a.to_s }
  currency_attrs = attrs + attrs.map{|attr| "#{attr}_taxed"}
  currency_opts = taxable_class_info.all_options.update({:conversion_input => :convert_taxable_value})
  acts_as_currency_value(currency_attrs, currency_opts)

  attrs.each {|attr| generate_attr_taxable_methods(attr) }

  if tax_logic = taxable_class_info.all_options[:tax_logic]
    other_methods = (tax_logic.respond_to?(:mixin_methods) ? tax_logic.mixin_methods : []) || []
    other_methods.each {|method_name| generate_attr_taxable_other_method(method_name.to_s) }
  else
    raise ArgumentError, 'You must specify a :tax_logic option for acts_as_taxable'
  end
end