Class: Auth::Workflow::Order
- Inherits:
-
Object
- Object
- Auth::Workflow::Order
- Includes:
- Concerns::WorkflowConcern
- Defined in:
- app/models/auth/workflow/order.rb
Constant Summary collapse
- FIELDS_LOCKED_AFTER_ORDER_ADDED =
["applicable"]
Instance Attribute Summary collapse
-
#assembly_doc_version ⇒ Object
Returns the value of attribute assembly_doc_version.
-
#assembly_id ⇒ Object
Returns the value of attribute assembly_id.
-
#order_index ⇒ Object
Returns the value of attribute order_index.
-
#sop_doc_version ⇒ Object
Returns the value of attribute sop_doc_version.
-
#sop_id ⇒ Object
Returns the value of attribute sop_id.
-
#sop_index ⇒ Object
Returns the value of attribute sop_index.
-
#stage_doc_version ⇒ Object
Returns the value of attribute stage_doc_version.
-
#stage_id ⇒ Object
Returns the value of attribute stage_id.
-
#stage_index ⇒ Object
Returns the value of attribute stage_index.
Class Method Summary collapse
-
.find_self(id, signed_in_resource, options = {}) ⇒ Object
@return an instance of the Assembly object that contains this order.
- .permitted_params ⇒ Object
Instance Method Summary collapse
-
#action ⇒ Object
“1 => add” “0 => remove”.
-
#create_order_into_all_applicable_sops(sops) ⇒ Object
@params sops : array of sop objects to which this order is applicable.
-
#create_with_conditions(params, permitted_params, model) ⇒ Object
CUSTOM DEFS .
Instance Attribute Details
#assembly_doc_version ⇒ Object
Returns the value of attribute assembly_doc_version.
21 22 23 |
# File 'app/models/auth/workflow/order.rb', line 21 def assembly_doc_version @assembly_doc_version end |
#assembly_id ⇒ Object
Returns the value of attribute assembly_id.
20 21 22 |
# File 'app/models/auth/workflow/order.rb', line 20 def assembly_id @assembly_id end |
#order_index ⇒ Object
Returns the value of attribute order_index.
28 29 30 |
# File 'app/models/auth/workflow/order.rb', line 28 def order_index @order_index end |
#sop_doc_version ⇒ Object
Returns the value of attribute sop_doc_version.
26 27 28 |
# File 'app/models/auth/workflow/order.rb', line 26 def sop_doc_version @sop_doc_version end |
#sop_id ⇒ Object
Returns the value of attribute sop_id.
27 28 29 |
# File 'app/models/auth/workflow/order.rb', line 27 def sop_id @sop_id end |
#sop_index ⇒ Object
Returns the value of attribute sop_index.
25 26 27 |
# File 'app/models/auth/workflow/order.rb', line 25 def sop_index @sop_index end |
#stage_doc_version ⇒ Object
Returns the value of attribute stage_doc_version.
23 24 25 |
# File 'app/models/auth/workflow/order.rb', line 23 def stage_doc_version @stage_doc_version end |
#stage_id ⇒ Object
Returns the value of attribute stage_id.
24 25 26 |
# File 'app/models/auth/workflow/order.rb', line 24 def stage_id @stage_id end |
#stage_index ⇒ Object
Returns the value of attribute stage_index.
22 23 24 |
# File 'app/models/auth/workflow/order.rb', line 22 def stage_index @stage_index end |
Class Method Details
.find_self(id, signed_in_resource, options = {}) ⇒ Object
@return an instance of the Assembly object that contains this order. this is used during update/show/delete
46 47 48 49 50 51 52 53 54 |
# File 'app/models/auth/workflow/order.rb', line 46 def self.find_self(id,signed_in_resource,={}) return nil unless collection = Auth.configuration.assembly_class.constantize.where("stages.sops.orders._id" => BSON::ObjectId(id) ) collection.first end |
.permitted_params ⇒ Object
56 57 58 |
# File 'app/models/auth/workflow/order.rb', line 56 def self.permitted_params [{:order => [:action,:assembly_id,:assembly_doc_version,:stage_id, :stage_doc_version, :stage_index, :sop_id, :sop_doc_version, :sop_index, :doc_version, :order_index, :name,{:cart_item_ids => []}]},:id] end |
Instance Method Details
#action ⇒ Object
“1 => add” “0 => remove”
14 |
# File 'app/models/auth/workflow/order.rb', line 14 field :action, type: Integer |
#create_order_into_all_applicable_sops(sops) ⇒ Object
@params sops : array of sop objects to which this order is applicable.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'app/models/auth/workflow/order.rb', line 158 def create_order_into_all_applicable_sops(sops) query = {"$and" => []} ## add the assembly specific clauses. query["$and"] << [ { "_id" => BSON::ObjectId(self.assembly_id.to_s) }, { "doc_version" => self.assembly_doc_version }, { "master" => false }, { "applicable" => true } ] sops.each do |sop| ## stage specific clauses query["$and"] << { "stages.#{sop.stage_index}._id" => BSON::ObjectId(sop.stage_id["$oid"]) } query["$and"] << { "stages.#{sop.stage_index}.doc_version" => sop.stage_doc_version } query["$and"] << { "stages.#{sop.stage_index}.applicable" => true } ## sop specific clauses. query["$and"] << { "stages.#{sop.stage_index}.sops.#{sop.sop_index}._id" => BSON::ObjectId(sop.id.to_s) } query["$and"] << { "stages.#{sop.stage_index}.sops.#{sop.sop_index}.doc_version" => sop.doc_version } query["$and"] << { "stages.#{sop.stage_index}.sops.#{sop.sop_index}.applicable" => true } query["$and"] << { "stages.#{sop.stage_index}.sops.#{sop.sop_index}.orders.cart_item_ids" => { "$nin" => self.cart_item_ids } } end query["$and"].flatten! update_clause = {"$push" => {}} sops.each do |sop| update_clause["$push"]["stages.#{sop.stage_index}.sops.#{sop.sop_index}.orders"] = self.attributes end assembly_updated = Auth.configuration.assembly_class.constantize.where(query) .find_one_and_update( update_clause, { :return_document => :after } ) return assembly_updated end |
#create_with_conditions(params, permitted_params, model) ⇒ Object
CUSTOM DEFS
the order is created inside the sop, only if the cart items of the order are not present in any prior order, inside the same sop. this will create the order inside only one sop.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'app/models/auth/workflow/order.rb', line 83 def create_with_conditions(params,permitted_params,model) ## in this case the model is an order model. return false unless model.valid? query = { "$and" => [ { "stages.#{model.stage_index}._id" => BSON::ObjectId(model.stage_id.to_s) }, { "stages.#{model.stage_index}.doc_version" => model.stage_doc_version }, { "stages.#{model.stage_index}.applicable" => true }, { "_id" => BSON::ObjectId(model.assembly_id.to_s) }, { "doc_version" => model.assembly_doc_version }, { "master" => false }, { "applicable" => true }, { "stages.#{model.stage_index}.sops.#{model.sop_index}._id" => BSON::ObjectId(model.sop_id.to_s) }, { "stages.#{model.stage_index}.sops.#{model.sop_index}.doc_version" => model.sop_doc_version }, { "stages.#{model.stage_index}.sops.#{model.sop_index}.applicable" => true }, { "stages.#{model.stage_index}.sops.#{model.sop_index}.orders.cart_item_ids" => { "$nin" => model.cart_item_ids } } ] } assembly_updated = Auth.configuration.assembly_class.constantize.where(query) .find_one_and_update( { "$push" => { "stages.#{stage_index}.sops.#{sop_index}.orders" => model.attributes } }, { :return_document => :after } ) return false unless assembly_updated return model end |