Class: WorkEffort
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- WorkEffort
- Includes:
- ErpTechSvcs::Utils::DefaultNestedSetMethods
- Defined in:
- app/models/work_effort.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(an_other) ⇒ Object
- #assigned_parties(role_type = 'worker') ⇒ Object
- #assigned_roles ⇒ Object
- #complete ⇒ Object
-
#completed? ⇒ Boolean
return true if this effort has been completed, false otherwise.
- #finish ⇒ Object
- #finished? ⇒ Boolean
-
#role_types ⇒ Object
(also: #role_type_assignments)
How is a work effort assigned, it can be assigned to party roles which allow for generic assignment.
-
#start(initial_status = '') ⇒ Object
start work effort with initial_status (string).
-
#started? ⇒ Boolean
return true if this effort has been started, false otherwise.
- #status ⇒ Object
-
#work_effort_fixed_asset_assignments ⇒ Object
What Fixed Assets (tools, equipment) are used in the execution of this Work Effort.
-
#work_effort_inventory_assignments ⇒ Object
What Inventory Items are used in the execution of this Work Effort.
-
#work_effort_party_assignments ⇒ Object
How is this Work Effort related to business parties, requestors, workers, approvers.
-
#work_effort_record ⇒ Object
Allow for polymorphic subtypes of this class.
-
#work_order_item_fulfillments ⇒ Object
How is this Work Effort related to Work Order Items (order_line_items).
Class Method Details
.work_efforts_for_party(party, status = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/work_effort.rb', line 41 def work_efforts_for_party(party, status=nil) role_types_tbl = RoleType.arel_table parties_tbl = Party.arel_table statement = self # apply status if passed statement = statement.with_status(status) if status statement.includes(:role_types) .includes(:parties) .where(role_types_tbl[:id].in(party.party_roles.collect(&:role_type_id)).or(parties_tbl[:id].eq(party.id))) end |
Instance Method Details
#<=>(an_other) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/work_effort.rb', line 56 def <=>(an_other) case an_other.current_status when 'pending' 1 when 'complete' 2 else 3 end end |
#assigned_parties(role_type = 'worker') ⇒ Object
67 68 69 70 71 |
# File 'app/models/work_effort.rb', line 67 def assigned_parties(role_type='worker') self.work_effort_party_assignments.where('role_type_id = ?', RoleType.iid(role_type)).collect do |item| item.party.description end.join(',') end |
#assigned_roles ⇒ Object
73 74 75 |
# File 'app/models/work_effort.rb', line 73 def assigned_roles self.role_types.collect(&:description).join(',') end |
#complete ⇒ Object
117 118 119 120 121 |
# File 'app/models/work_effort.rb', line 117 def complete self.finished_at = Time.now self.actual_completion_time = time_diff_in_minutes(self.finished_at.to_time, self.started_at.to_time) self.save end |
#completed? ⇒ Boolean
return true if this effort has been completed, false otherwise
88 89 90 |
# File 'app/models/work_effort.rb', line 88 def completed? finished_at.nil? ? false : true end |
#finish ⇒ Object
113 114 115 |
# File 'app/models/work_effort.rb', line 113 def finish complete end |
#finished? ⇒ Boolean
92 93 94 |
# File 'app/models/work_effort.rb', line 92 def finished? completed? end |
#role_types ⇒ Object Also known as: role_type_assignments
How is a work effort assigned, it can be assigned to party roles which allow for generic assignment.
18 |
# File 'app/models/work_effort.rb', line 18 has_and_belongs_to_many :role_types |
#start(initial_status = '') ⇒ Object
start work effort with initial_status (string)
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/models/work_effort.rb', line 97 def start(initial_status='') effort = self unless self.descendants.flatten!.nil? children = self.descendants.flatten effort = children.last end if current_status.nil? effort.current_status = initial_status effort.started_at = DateTime.now effort.save else raise 'Effort Already Started' end end |
#started? ⇒ Boolean
return true if this effort has been started, false otherwise
83 84 85 |
# File 'app/models/work_effort.rb', line 83 def started? current_status.nil? ? false : true end |
#status ⇒ Object
77 78 79 80 |
# File 'app/models/work_effort.rb', line 77 def status # get status via has_tracked_status current_status end |
#work_effort_fixed_asset_assignments ⇒ Object
What Fixed Assets (tools, equipment) are used in the execution of this Work Effort
30 |
# File 'app/models/work_effort.rb', line 30 has_many :work_effort_fixed_asset_assignments, :dependent => :destroy |
#work_effort_inventory_assignments ⇒ Object
What Inventory Items are used in the execution of this Work Effort
26 |
# File 'app/models/work_effort.rb', line 26 has_many :work_effort_inventory_assignments, :dependent => :destroy |
#work_effort_party_assignments ⇒ Object
How is this Work Effort related to business parties, requestors, workers, approvers
22 |
# File 'app/models/work_effort.rb', line 22 has_many :work_effort_party_assignments, :dependent => :destroy |
#work_effort_record ⇒ Object
Allow for polymorphic subtypes of this class
34 |
# File 'app/models/work_effort.rb', line 34 belongs_to :work_effort_record, :polymorphic => true |
#work_order_item_fulfillments ⇒ Object
How is this Work Effort related to Work Order Items (order_line_items)
14 |
# File 'app/models/work_effort.rb', line 14 has_many :work_order_item_fulfillments, :dependent => :destroy |