Class: Dorsale::BillingMachine::Quotation::Copy

Inherits:
Service
  • Object
show all
Defined in:
app/services/dorsale/billing_machine/quotation/copy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Service

call

Constructor Details

#initialize(quotation) ⇒ Copy

Returns a new instance of Copy.



4
5
6
# File 'app/services/dorsale/billing_machine/quotation/copy.rb', line 4

def initialize(quotation)
  @quotation = quotation
end

Instance Attribute Details

#copyObject

Returns the value of attribute copy.



2
3
4
# File 'app/services/dorsale/billing_machine/quotation/copy.rb', line 2

def copy
  @copy
end

#quotationObject

Returns the value of attribute quotation.



2
3
4
# File 'app/services/dorsale/billing_machine/quotation/copy.rb', line 2

def quotation
  @quotation
end

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/dorsale/billing_machine/quotation/copy.rb', line 8

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         = Time.zone.now.to_date
  @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