2009-06-03 63 views
0

我想調用InvoicingAndDelivery.report_lines,然後給我一個這些結果的數組,但它不起作用。有任何想法嗎?如何在rails中初始化自己的類?

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 

回答

1

什麼是報告?

你有可能重寫了你不應該擁有的東西...需要在初始化時調用super,或者如前所述,使其成爲回調。

+0

我真的需要閱讀一些關於如何使用抽象類以及如何使用超級的書。 感謝您的回答。 – 2009-06-03 21:18:46

1

如果InvoicingAndDeliveryActiveRecord::Base下降,你shouldn't override initialize。而是把這個代碼放在after_initialize

+0

謝謝,我沒有使用這個類作爲ActiveRecord,但感謝提示無論如何。 – 2009-06-03 21:17:21