Class: Spree::Invoice

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spree/invoice.rb

Instance Method Summary collapse

Instance Method Details

#generate_invoice_numberObject



25
26
27
28
29
# File 'app/models/spree/invoice.rb', line 25

def generate_invoice_number
  last_record = self.class.from_current_year.size
  new_record = "%04d" % (last_record + 1).to_s
  self.invoice_number = "#{new_record}/A" if self.invoice_number.blank?
end

#generate_pdfObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/spree/invoice.rb', line 12

def generate_pdf
  self.update_attribute(:counter, self.counter + 1)
  WickedPdf.new.pdf_from_string(
    StaticRender.render_erb(Spree::Config[:invoice_template_path], {
      :@order => self.order,
      :@address => self.order.bill_address,
      :@invoice_print => self
    }), {
      :margin => ActiveSupport::JSON.decode(Spree::Config[:invoice_wkhtmltopdf_margin])
    }
  )
end