Module: Invoicing::LineItem::ActMethods

Defined in:
lib/invoicing/line_item.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_line_item(*args) ⇒ Object

Declares that the current class is a model for line items (i.e. individual items on invoices and credit notes).

The name of any attribute or method required by LineItem (as documented on the LineItem module) may be used as an option, with the value being the name under which that particular method or attribute can be found. This allows you to use names other than the defaults. For example, if your database column storing the line item value is called net_price instead of net_amount:

acts_as_line_item :net_amount => :net_price


148
149
150
151
152
153
154
155
156
157
158
# File 'lib/invoicing/line_item.rb', line 148

def acts_as_line_item(*args)
  Invoicing::ClassInfo.acts_as(Invoicing::LineItem, self, args)

  info = line_item_class_info
  if info.previous_info.nil? # Called for the first time?
    # Set the 'amount' columns to act as currency values
    acts_as_currency_value(info.method(:net_amount), info.method(:tax_amount))

    extend Invoicing::FindSubclasses
  end
end