Sha256: 5b34c87bc02d7d653bb89691087db962aacfb10caae92621b6d3cd104144c6bb

Contents?: true

Size: 768 Bytes

Versions: 10

Compression:

Stored size: 768 Bytes

Contents

class Dorsale::BillingMachine::Quotation::Copy < ::Dorsale::Service
  attr_accessor :quotation, :copy

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

  def call
    @copy = quotation.dup

    @quotation.lines.each do |line|
      @copy.lines << line.dup
    end

    @copy.unique_index = nil
    @copy.created_at   = nil
    @copy.updated_at   = nil
    @copy.date         = Date.current
    @copy.state        = ::Dorsale::BillingMachine::Quotation::STATES.first

    @copy.save!

    @quotation.attachments.each do |attachment|
      new_attachment            = attachment.dup
      new_attachment.attachable = @copy
      new_attachment.file       = File.open(attachment.file.path)
      new_attachment.save!
    end

    @copy
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

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