Class: Billing::Factory::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/billing/factory/base.rb

Direct Known Subclasses

LibraryCreation, Sequencing

Constant Summary collapse

NO_PROJECT_COST_CODE =
'S0755'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base


15
16
17
18
19
20
# File 'app/models/billing/factory/base.rb', line 15

def initialize(attributes = {})
  super

  self.passed_date = request
  self.billing_product = request
end

Instance Attribute Details

#billing_productObject

Returns the value of attribute billing_product


9
10
11
# File 'app/models/billing/factory/base.rb', line 9

def billing_product
  @billing_product
end

#requestObject

Returns the value of attribute request


8
9
10
# File 'app/models/billing/factory/base.rb', line 8

def request
  @request
end

Instance Method Details

#billing_product_codeObject

billing_product_code will be received from Agresso based on billing_product name


45
46
47
48
49
50
# File 'app/models/billing/factory/base.rb', line 45

def billing_product_code
  # this is been disabled because of Agresso performance issues
  # AgressoProduct.billing_product_code(billing_product.name)
rescue
  nil
end

#billing_product_descriptionObject


52
53
54
# File 'app/models/billing/factory/base.rb', line 52

def billing_product_description
  billing_product.name
end

#create!Object


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/billing/factory/base.rb', line 60

def create!
  return unless valid?

  Billing::Item.create!(
    request: request,
    project_cost_code: project_cost_code,
    units: units,
    billing_product_code: billing_product_code,
    billing_product_name: billing_product_name,
    billing_product_description: billing_product_description,
    request_passed_date: passed_date
  )
end

#passed_dateObject


28
29
30
31
32
# File 'app/models/billing/factory/base.rb', line 28

def passed_date
  return if @passed_date.nil?

  @passed_date.strftime('%Y%m%d')
end

#passed_date=(request) ⇒ Object


22
23
24
25
26
# File 'app/models/billing/factory/base.rb', line 22

def passed_date=(request)
  return unless request.present?

  @passed_date = request.date_for_state('passed')
end

#project_cost_code(cost_code = nil) ⇒ Object


40
41
42
# File 'app/models/billing/factory/base.rb', line 40

def project_cost_code(cost_code = nil)
  cost_code || NO_PROJECT_COST_CODE
end

#units(*_args) ⇒ Object


56
57
58
# File 'app/models/billing/factory/base.rb', line 56

def units(*_args)
  100
end