views:

133

answers:

2

I want to call InvoicingAndDelivery.report_lines, then give me an array of those results, but it isn't working. Any ideas?

class InvoicingAndDelivery < Report
  include DateExtentions
  attr_accessor :report_lines, :tba_line, :sum_line

  def initialize(part_or_service_ids, start_date, to_date)

    # @report_lines = []

    number_of_months(start_date,to_date).times do |i|
      start_date = start_date + i.months
      l = InvoicingAndDeliveryReport.new
      l.month = start_date.strftime("%m/%Y")
      l.work_profile = WorkProfileLine.delivery_amount_for_serivces_in(part_or_service_ids, start_date)
      l.forecast_delivery = LineItem.forecast_delivery_amount_for_services_in(part_or_service_ids, start_date)
      l.invoicing = InvoiceLine.invoices_total_for_services_in(part_or_service_ids, start_date)
      l.projected_invoices = InvoiceLine.projected_invoice_total_for_services_in(part_or_service_ids, start_date)
      l.costs =  LineItem.costs_total_for_services_in(part_or_service_ids, start_date)
      l.gross_profit = l.invoicing - l.costs
      l.opportunities = LineItem.oportunities_value_for_services_in(part_or_service_ids, start_date)
      #    @report_lines<< l
    end

    @tba_line = InvoiceLine.service_type(@part_or_service).tba_lines.sum("invoice_lines.sell_price * invoice_lines.quantity").to_f
    @sum_line = get_sum_line
  end
A: 

If InvoicingAndDelivery descends from ActiveRecord::Base, you shouldn't override initialize. Instead put this code in after_initialize.

Pesto
Thanks, I'm not using this class as ActiveRecord, but thanks for the tips anyway.
Shuoling Liu
+1  A: 

What is a Report?

Chances are you overwrote something you shouldn't have... Need to call super on initialize, or as previously mentioned, make it a callback.

phillc
I really need read some book on how to use the abstract class as well as how to use super.Thanks for your answer.
Shuoling Liu