Sha256: 53131817b95962c98e54c2ee285a6df0707063d3d5b4c417bf3af8fc234bb948

Contents?: true

Size: 874 Bytes

Versions: 25

Compression:

Stored size: 874 Bytes

Contents

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

  def initialize(quotation)
    @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

25 entries across 25 versions & 1 rubygems

Version Path
dorsale-3.14.9 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.14.8 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.14.7 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.14.6 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.14.5 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.14.4 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.14.3 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.14.2 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.14.1 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.14.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.13.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.12.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.11.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.10.3 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.10.2 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.10.1 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.10.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.9.8 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.9.7 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.9.6 app/services/dorsale/billing_machine/quotation/to_invoice.rb