Commit ec2356d26880eb379e0fc941bcd6daf301e97fa1
1 parent
4984d61a
added parsing for sales order lines on the SorDetail business object
Showing
6 changed files
with
171 additions
and
12 deletions
 
Show diff stats
Gemfile.lock
| 1 | PATH | 1 | PATH | 
| 2 | remote: . | 2 | remote: . | 
| 3 | specs: | 3 | specs: | 
| 4 | - syspro-ruby (1.0.0.alpha.1) | 4 | + syspro-ruby (1.0.0.alpha.2) | 
| 5 | faraday (~> 0.10) | 5 | faraday (~> 0.10) | 
| 6 | nokogiri (~> 1.8.2) | 6 | nokogiri (~> 1.8.2) | 
| 7 | 7 | ||
| @@ -14,7 +14,7 @@ GEM | @@ -14,7 +14,7 @@ GEM | ||
| 14 | coderay (1.1.2) | 14 | coderay (1.1.2) | 
| 15 | crack (0.4.3) | 15 | crack (0.4.3) | 
| 16 | safe_yaml (~> 1.0.0) | 16 | safe_yaml (~> 1.0.0) | 
| 17 | - faraday (0.14.0) | 17 | + faraday (0.15.4) | 
| 18 | multipart-post (>= 1.2, < 3) | 18 | multipart-post (>= 1.2, < 3) | 
| 19 | hashdiff (0.3.7) | 19 | hashdiff (0.3.7) | 
| 20 | method_source (0.9.0) | 20 | method_source (0.9.0) | 
| @@ -27,7 +27,7 @@ GEM | @@ -27,7 +27,7 @@ GEM | ||
| 27 | minitest (>= 4.7.5) | 27 | minitest (>= 4.7.5) | 
| 28 | vcr (>= 2.9) | 28 | vcr (>= 2.9) | 
| 29 | multipart-post (2.0.0) | 29 | multipart-post (2.0.0) | 
| 30 | - nokogiri (1.8.2) | 30 | + nokogiri (1.8.5) | 
| 31 | mini_portile2 (~> 2.3.0) | 31 | mini_portile2 (~> 2.3.0) | 
| 32 | parallel (1.12.1) | 32 | parallel (1.12.1) | 
| 33 | parser (2.5.0.5) | 33 | parser (2.5.0.5) | 
| @@ -69,4 +69,4 @@ DEPENDENCIES | @@ -69,4 +69,4 @@ DEPENDENCIES | ||
| 69 | webmock (~> 3.3.0) | 69 | webmock (~> 3.3.0) | 
| 70 | 70 | ||
| 71 | BUNDLED WITH | 71 | BUNDLED WITH | 
| 72 | - 1.16.1 | 72 | + 1.16.4 | 
lib/syspro/business_objects/models/sor_detail.rb
| @@ -20,9 +20,8 @@ module Syspro | @@ -20,9 +20,8 @@ module Syspro | ||
| 20 | :jobs_exist_flag, :alternate_key, :hierarchy_flag, :deposit_flag, :edi_source, :mult_ship_code, | 20 | :jobs_exist_flag, :alternate_key, :hierarchy_flag, :deposit_flag, :edi_source, :mult_ship_code, | 
| 21 | :company_tax_no, :last_operator, :operator, :state, :county_zip, :extended_tax_code, :web_created, | 21 | :company_tax_no, :last_operator, :operator, :state, :county_zip, :extended_tax_code, :web_created, | 
| 22 | :quote, :dispatches_made, :live_disp_exist, :num_dispatches, :include_in_mrp, :header_text, | 22 | :quote, :dispatches_made, :live_disp_exist, :num_dispatches, :include_in_mrp, :header_text, | 
| 23 | - :header_notes, :commissions | 23 | + :header_notes, :commissions, :sales_order_lines | 
| 24 | end | 24 | end | 
| 25 | end | 25 | end | 
| 26 | end | 26 | end | 
| 27 | end | 27 | end | 
| 28 | - | 
lib/syspro/business_objects/parsers/sorqry_parser.rb
| @@ -121,20 +121,181 @@ module Syspro | @@ -121,20 +121,181 @@ module Syspro | ||
| 121 | sor.header_text = doc.first_element_child.xpath("HeaderText").text | 121 | sor.header_text = doc.first_element_child.xpath("HeaderText").text | 
| 122 | sor.header_notes = doc.first_element_child.xpath("HeaderNotes").text | 122 | sor.header_notes = doc.first_element_child.xpath("HeaderNotes").text | 
| 123 | 123 | ||
| 124 | + # Inner Nested Structure Parsing | ||
| 125 | + sor.commissions = parse_commissions(doc) | ||
| 126 | + sor.sales_order_lines = parse_sales_order_lines(doc) | ||
| 127 | + | ||
| 128 | + sor | ||
| 129 | + end | ||
| 130 | + | ||
| 131 | + def parse_commissions(doc) | ||
| 124 | commissions = doc.first_element_child.xpath("Commissions") | 132 | commissions = doc.first_element_child.xpath("Commissions") | 
| 125 | - commissions_obj = commissions.children.map do |el| | 133 | + commissions_obj = parse_children_elements(commissions) | 
| 134 | + | ||
| 135 | + commissions_obj | ||
| 136 | + end | ||
| 137 | + | ||
| 138 | + | ||
| 139 | + def parse_sales_order_lines(doc) | ||
| 140 | + sales_order_lines = doc.first_element_child.xpath("SalesOrderLine") | ||
| 141 | + sales_order_lines_obj = {} | ||
| 142 | + | ||
| 143 | + sales_order_lines.children.each do |el| | ||
| 144 | + next if el.name == "text" | ||
| 145 | + | ||
| 146 | + serial_obj = {} | ||
| 147 | + bin_obj = {} | ||
| 148 | + attached_items_obj = {} | ||
| 149 | + lot_obj = {} | ||
| 150 | + | ||
| 151 | + if el.name == "MiscCharge" | ||
| 152 | + unless sales_order_lines_obj[:misc_charge] | ||
| 153 | + sales_order_lines_obj[:misc_charge] = [] | ||
| 154 | + end | ||
| 155 | + | ||
| 156 | + misc_charge_arr = parse_children_elements(el) | ||
| 157 | + sales_order_lines_obj[:misc_charge].push(misc_charge_arr) | ||
| 158 | + end | ||
| 159 | + | ||
| 160 | + if el.name == "Freight" | ||
| 161 | + unless sales_order_lines_obj[:freight] | ||
| 162 | + sales_order_lines_obj[:freight] = [] | ||
| 163 | + end | ||
| 164 | + | ||
| 165 | + freight_arr = parse_children_elements(el) | ||
| 166 | + sales_order_lines_obj[:freight].push(freight_arr) | ||
| 167 | + end | ||
| 168 | + | ||
| 169 | + if el.name == "CommentLine" | ||
| 170 | + unless sales_order_lines_obj[:comment_line] | ||
| 171 | + sales_order_lines_obj[:comment_line] = [] | ||
| 172 | + end | ||
| 173 | + | ||
| 174 | + comment_line_arr = parse_children_elements(el) | ||
| 175 | + sales_order_lines_obj[:comment_line].push(comment_line_arr) | ||
| 176 | + end | ||
| 177 | + | ||
| 178 | + if el.name == "Merchandise" | ||
| 179 | + unless sales_order_lines_obj[:merchandise] | ||
| 180 | + sales_order_lines_obj[:merchandise] = [] | ||
| 181 | + end | ||
| 182 | + | ||
| 183 | + merchandise_arr = el.children.map do |el_child| | ||
| 184 | + next if el_child.name == "text" | ||
| 185 | + | ||
| 186 | + # NOTE: These first three in the following | ||
| 187 | + # conditionals are "Merchandise" elements with | ||
| 188 | + # thier own nested structure that need parsed | ||
| 189 | + if el_child.name == "Serial" | ||
| 190 | + unless serial_obj[:serial] | ||
| 191 | + serial_obj[:serial] = [] | ||
| 192 | + end | ||
| 193 | + | ||
| 194 | + serial_arr = parse_children_elements(el_child) | ||
| 195 | + serial_obj[:serial].push(serial_arr) | ||
| 196 | + serial_obj | ||
| 197 | + | ||
| 198 | + elsif el_child.name == "Bin" | ||
| 199 | + unless bin_obj[:bin] | ||
| 200 | + bin_obj[:bin] = [] | ||
| 201 | + end | ||
| 202 | + | ||
| 203 | + bin_arr = parse_children_elements(el_child) | ||
| 204 | + bin_obj[:bin].push(bin_arr) | ||
| 205 | + bin_obj | ||
| 206 | + | ||
| 207 | + elsif el_child.name == "Lot" | ||
| 208 | + unless lot_obj[:lot] | ||
| 209 | + lot_obj[:lot] = [] | ||
| 210 | + end | ||
| 211 | + | ||
| 212 | + lot_arr = parse_children_elements(el_child) | ||
| 213 | + lot_obj[:lot].push(lot_arr) | ||
| 214 | + lot_obj | ||
| 215 | + | ||
| 216 | + elsif el_child.name == "AttachedItems" | ||
| 217 | + # NOTE: Like "Merchandise", "AttachedItems" is | ||
| 218 | + # an element within "Merchandise" that contains | ||
| 219 | + # elements with thier own nested structure that | ||
| 220 | + # need parsed | ||
| 221 | + | ||
| 222 | + sct_item_obj = {} | ||
| 223 | + requisition_item_obj = {} | ||
| 224 | + purchase_order_obj = {} | ||
| 225 | + | ||
| 226 | + unless attached_items_obj[:attached_items] | ||
| 227 | + attached_items_obj[:attached_items] = [] | ||
| 228 | + end | ||
| 229 | + | ||
| 230 | + attached_items_arr = el_child.children.map do |attached_items_child| | ||
| 231 | + next if attached_items_child.name == "text" | ||
| 232 | + | ||
| 233 | + if attached_items_child.name == "SctItem" | ||
| 234 | + unless sct_item_obj[:sct_item] | ||
| 235 | + sct_item_obj[:sct_item] = [] | ||
| 236 | + end | ||
| 237 | + | ||
| 238 | + sct_item_arr = parse_children_elements(attached_items_child) | ||
| 239 | + sct_item_obj[:sct_item].push(sct_item_arr) | ||
| 240 | + sct_item_obj | ||
| 241 | + | ||
| 242 | + elsif attached_items_child.name == "RequisitionItem" | ||
| 243 | + unless requisition_item_obj[:requisition_item] | ||
| 244 | + requisition_item_obj[:requisition_item] = [] | ||
| 245 | + end | ||
| 246 | + | ||
| 247 | + requisition_item_arr = parse_children_elements(attached_items_child) | ||
| 248 | + requisition_item_obj[:requisition_item].push(requisition_item_arr) | ||
| 249 | + requisition_item_obj | ||
| 250 | + | ||
| 251 | + elsif attached_items_child.name == "PurchaseOrder" | ||
| 252 | + unless purchase_order_obj[:purchase_order] | ||
| 253 | + purchase_order_obj[:purchase_order] = [] | ||
| 254 | + end | ||
| 255 | + | ||
| 256 | + purchase_order_arr = parse_children_elements(attached_items_child) | ||
| 257 | + purchase_order_obj[:purchase_order].push(purchase_order_arr) | ||
| 258 | + purchase_order_obj | ||
| 259 | + | ||
| 260 | + else | ||
| 261 | + { | ||
| 262 | + name: attached_items_child.name, | ||
| 263 | + text: attached_items_child.text | ||
| 264 | + } | ||
| 265 | + end | ||
| 266 | + end.compact | ||
| 267 | + | ||
| 268 | + attached_items_obj[:attached_items].push(attached_items_arr) | ||
| 269 | + attached_items_obj | ||
| 270 | + | ||
| 271 | + else | ||
| 272 | + { | ||
| 273 | + name: el_child.name, | ||
| 274 | + text: el_child.text | ||
| 275 | + } | ||
| 276 | + end | ||
| 277 | + end.compact | ||
| 278 | + | ||
| 279 | + sales_order_lines_obj[:merchandise].push(merchandise_arr) | ||
| 280 | + end | ||
| 281 | + end | ||
| 282 | + | ||
| 283 | + sales_order_lines_obj | ||
| 284 | + end | ||
| 285 | + | ||
| 286 | + def parse_children_elements(el_child) | ||
| 287 | + obj_array = el_child.children.map do |el| | ||
| 126 | next if el.name == "text" | 288 | next if el.name == "text" | 
| 127 | { | 289 | { | 
| 128 | name: el.name, | 290 | name: el.name, | 
| 129 | text: el.text | 291 | text: el.text | 
| 130 | } | 292 | } | 
| 131 | end.compact | 293 | end.compact | 
| 132 | - sor.commissions = commissions_obj | ||
| 133 | 294 | ||
| 134 | - sor | 295 | + obj_array | 
| 135 | end | 296 | end | 
| 297 | + | ||
| 136 | end | 298 | end | 
| 137 | end | 299 | end | 
| 138 | end | 300 | end | 
| 139 | end | 301 | end | 
| 140 | - | 
lib/syspro/business_objects/sorqry.rb
lib/syspro/syspro_object.rb
| @@ -44,7 +44,7 @@ module Syspro | @@ -44,7 +44,7 @@ module Syspro | ||
| 44 | 44 | ||
| 45 | def to_hash # rubocop:disable Metrics/MethodLength | 45 | def to_hash # rubocop:disable Metrics/MethodLength | 
| 46 | maybe_to_hash = lambda do |value| | 46 | maybe_to_hash = lambda do |value| | 
| 47 | - value&.respond_to?(:to_hash) ? value.to_hash : value | 47 | + value.respond_to?(:to_hash) ? value.to_hash : value | 
| 48 | end | 48 | end | 
| 49 | 49 | ||
| 50 | @values.each_with_object({}) do |(key, value), acc| | 50 | @values.each_with_object({}) do |(key, value), acc| | 
No preview for this file type