Sha256: f6b16bb162488d3a03630e1611d817469977b42f98955bde6a551bd9e640f38b

Contents?: true

Size: 886 Bytes

Versions: 10

Compression:

Stored size: 886 Bytes

Contents

class Dorsale::BillingMachine::Quotation::ToInvoice < ::Dorsale::Service
  attr_accessor :quotation, :invoice

  def initialize(quotation)
    super()
    @quotation = quotation
  end

  def call
    @invoice = Dorsale::BillingMachine::Invoice.new

    quotation.attributes.each do |k, v|
      next if ignored_key?(k)

      if invoice.respond_to?("#{k}=")
        invoice.public_send("#{k}=", v)
      end
    end

    quotation.lines.each do |quotation_line|
      invoice_line = invoice.lines.new

      quotation_line.attributes.each do |k, v|
        next if ignored_key?(k)

        if invoice_line.respond_to?("#{k}=")
          invoice_line.public_send("#{k}=", v)
        end
      end
    end

    invoice.date = Date.current

    invoice
  end

  private

  def ignored_key?(k)
    k = k.to_s
    k == "id" || k.match(/index|tracking|state/) || k.end_with?("_at")
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dorsale-4.0.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.20.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.19.1 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.19.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.18.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.17.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.16.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.15.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.14.11 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.14.10 app/services/dorsale/billing_machine/quotation/to_invoice.rb