Commit 762ae45f21d8a603884ae8cd5b4a6150b852beb1
Committed by
GitHub
1 parent
fb410806
Added InvSws Business Object (#14)
Added InvSws to add warehouses to stock code
Showing
9 changed files
with
214 additions
and
2 deletions
Show diff stats
lib/syspro.rb
@@ -34,6 +34,7 @@ require 'syspro/business_objects/portor' | @@ -34,6 +34,7 @@ require 'syspro/business_objects/portor' | ||
34 | require 'syspro/business_objects/portoi' | 34 | require 'syspro/business_objects/portoi' |
35 | require 'syspro/business_objects/porqry' | 35 | require 'syspro/business_objects/porqry' |
36 | require 'syspro/business_objects/comsfm' | 36 | require 'syspro/business_objects/comsfm' |
37 | +require 'syspro/business_objects/invsws' | ||
37 | require 'syspro/business_objects/invqry' | 38 | require 'syspro/business_objects/invqry' |
38 | 39 | ||
39 | require 'syspro/business_objects/models/sor' | 40 | require 'syspro/business_objects/models/sor' |
@@ -48,6 +49,7 @@ require 'syspro/business_objects/models/purchase_orders/freight_line' | @@ -48,6 +49,7 @@ require 'syspro/business_objects/models/purchase_orders/freight_line' | ||
48 | require 'syspro/business_objects/models/purchase_orders/misc_charge_line' | 49 | require 'syspro/business_objects/models/purchase_orders/misc_charge_line' |
49 | require 'syspro/business_objects/models/purchase_orders/comment_line' | 50 | require 'syspro/business_objects/models/purchase_orders/comment_line' |
50 | require 'syspro/business_objects/models/comsfm_item' | 51 | require 'syspro/business_objects/models/comsfm_item' |
52 | +require 'syspro/business_objects/models/invsws_item' | ||
51 | require 'syspro/business_objects/models/inv' | 53 | require 'syspro/business_objects/models/inv' |
52 | 54 | ||
53 | require 'syspro/business_objects/parsers/combrw_parser' | 55 | require 'syspro/business_objects/parsers/combrw_parser' |
@@ -57,6 +59,7 @@ require 'syspro/business_objects/parsers/sorqry_parser' | @@ -57,6 +59,7 @@ require 'syspro/business_objects/parsers/sorqry_parser' | ||
57 | require 'syspro/business_objects/parsers/portor_parser' | 59 | require 'syspro/business_objects/parsers/portor_parser' |
58 | require 'syspro/business_objects/parsers/portoi_parser' | 60 | require 'syspro/business_objects/parsers/portoi_parser' |
59 | require 'syspro/business_objects/parsers/comsfm_parser' | 61 | require 'syspro/business_objects/parsers/comsfm_parser' |
62 | +require 'syspro/business_objects/parsers/invsws_parser' | ||
60 | require 'syspro/business_objects/parsers/invqry_parser' | 63 | require 'syspro/business_objects/parsers/invqry_parser' |
61 | 64 | ||
62 | # Main Module | 65 | # Main Module |
lib/syspro/business_objects/comsfm.rb
@@ -12,7 +12,7 @@ module Syspro | @@ -12,7 +12,7 @@ module Syspro | ||
12 | attr_accessor :validate_only, | 12 | attr_accessor :validate_only, |
13 | :items | 13 | :items |
14 | 14 | ||
15 | - def call(user_id) | 15 | + def add(user_id) |
16 | xml_parameters = params_template.result(binding) | 16 | xml_parameters = params_template.result(binding) |
17 | xml_in = template.result(binding) | 17 | xml_in = template.result(binding) |
18 | business_object = 'COMSFM' | 18 | business_object = 'COMSFM' |
1 | +# frozen_string_literal: true | ||
2 | + | ||
3 | +require 'syspro/business_objects/parsers/invsws_parser' | ||
4 | +require 'erb' | ||
5 | + | ||
6 | +module Syspro | ||
7 | + module BusinessObjects | ||
8 | + class InvSws < ApiResource | ||
9 | + include Syspro::ApiOperations::Setup | ||
10 | + include Syspro::BusinessObjects::Parsers | ||
11 | + | ||
12 | + attr_accessor :validate_only, | ||
13 | + :apply_product_class_default, | ||
14 | + :ignore_warnings, | ||
15 | + :apply_if_entire_document_valid, | ||
16 | + :item | ||
17 | + | ||
18 | + def add(user_id) | ||
19 | + xml_parameters = params_template.result(binding) | ||
20 | + xml_in = template.result(binding) | ||
21 | + business_object = 'INVSWS' | ||
22 | + params = { 'UserId' => user_id, | ||
23 | + 'BusinessObject' => business_object, | ||
24 | + 'XmlParameters' => xml_parameters, | ||
25 | + 'XmlIn' => xml_in } | ||
26 | + resp = InvSws.add(params) | ||
27 | + | ||
28 | + parse_response(resp) | ||
29 | + end | ||
30 | + | ||
31 | + def template | ||
32 | + ERB.new File.read(File.expand_path('schemas/invsws_doc.xml.erb', File.dirname(__FILE__))), nil, '%' | ||
33 | + end | ||
34 | + | ||
35 | + def params_template | ||
36 | + ERB.new File.read(File.expand_path('schemas/invsws.xml.erb', File.dirname(__FILE__))), nil, '%' | ||
37 | + end | ||
38 | + | ||
39 | + def parse_response(resp) | ||
40 | + handle_errors(resp) | ||
41 | + parser = InvSwsParser.new(resp[0].data) | ||
42 | + parser.parse | ||
43 | + end | ||
44 | + | ||
45 | + def render_xml(inner_text, dflt_value = "") | ||
46 | + inner_text ? inner_text.to_s : dflt_value | ||
47 | + end | ||
48 | + end | ||
49 | + end | ||
50 | +end |
1 | +module Syspro | ||
2 | + module BusinessObjects | ||
3 | + module Models | ||
4 | + class InvSwsItem | ||
5 | + attr_accessor :key_stock_code, | ||
6 | + :key_warehouse, | ||
7 | + :cost_multiplier, | ||
8 | + :minimum_qty, | ||
9 | + :maximum_qty, | ||
10 | + :unit_cost, | ||
11 | + :default_bin, | ||
12 | + :safety_stock_qty, | ||
13 | + :re_order_qty, | ||
14 | + :pallet_qty, | ||
15 | + :user_field1, | ||
16 | + :user_field2, | ||
17 | + :user_field3, | ||
18 | + :order_policy, | ||
19 | + :major_order_mult, | ||
20 | + :minor_order_mult, | ||
21 | + :order_minimum, | ||
22 | + :order_maximum, | ||
23 | + :order_fix_period, | ||
24 | + :trf_supplied_item, | ||
25 | + :default_source_wh, | ||
26 | + :trf_lead_time, | ||
27 | + :trf_cost_gl_code, | ||
28 | + :trf_cost_multiply, | ||
29 | + :trf_replenish_wh, | ||
30 | + :trf_buying_rule, | ||
31 | + :trf_dock_to_stock, | ||
32 | + :trf_fix_time_period, | ||
33 | + :labour_cost, | ||
34 | + :material_cost, | ||
35 | + :fixed_overhead, | ||
36 | + :variable_overhead, | ||
37 | + :sub_contract_cost, | ||
38 | + :manual_cost_flag, | ||
39 | + :e_signature | ||
40 | + end | ||
41 | + | ||
42 | + class InvSwsItemKey | ||
43 | + attr_accessor | ||
44 | + end | ||
45 | + end | ||
46 | + end | ||
47 | +end | ||
0 | \ No newline at end of file | 48 | \ No newline at end of file |
lib/syspro/business_objects/parsers/invsws_parser.rb
0 → 100644
1 | +# frozen_string_literal: true | ||
2 | + | ||
3 | +module Syspro | ||
4 | + module BusinessObjects | ||
5 | + module Parsers | ||
6 | + class InvSwsParser | ||
7 | + attr_reader :doc | ||
8 | + | ||
9 | + def initialize(doc) | ||
10 | + @doc = doc | ||
11 | + end | ||
12 | + | ||
13 | + def parse | ||
14 | + { | ||
15 | + "key": { | ||
16 | + "stock_code": doc.xpath("//item/key/stockcode").map{|e| e.text}.first, | ||
17 | + "warehouse": doc.xpath("//item/key/stockcode").map{|e| e.text}.first | ||
18 | + }, | ||
19 | + "reacords_read": doc.xpath("//StatusOfItems/RecordsRead").map{|e| e.text}.first, | ||
20 | + "reacords_invalid": doc.xpath("//StatusOfItems/RecordsInvalid").map{|e| e.text}.first, | ||
21 | + "error_numbers": doc.xpath("//ErrorNumber").map{|e| e.text} | ||
22 | + } | ||
23 | + end | ||
24 | + end | ||
25 | + end | ||
26 | + end | ||
27 | +end | ||
28 | + |
1 | +<SetupInvWarehouse xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="INVSWS.XSD"> | ||
2 | + <Parameters> | ||
3 | + <ApplyProductClassDefault><%= render_xml(@apply_product_class_default, "BA") %></ApplyProductClassDefault> | ||
4 | + <IgnoreWarnings><%= render_xml(@ignore_warnings, "N") %></IgnoreWarnings> | ||
5 | + <ApplyIfEntireDocumentValid><%= render_xml(@apply_if_entire_document_valid, "Y") %></ApplyIfEntireDocumentValid> | ||
6 | + <ValidateOnly><%= render_xml(@validate_only, "N") %></ValidateOnly> | ||
7 | + </Parameters> | ||
8 | +</SetupInvWarehouse> |
lib/syspro/business_objects/schemas/invsws_doc.xml.erb
0 → 100644
1 | +<SetupInvWarehouse xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="INVSWSDOC.XSD"> | ||
2 | + <Item> | ||
3 | + <Key> | ||
4 | + <StockCode><%= render_xml(@item.key_stock_code) %></StockCode> | ||
5 | + <Warehouse><%= render_xml(@item.key_warehouse) %></Warehouse> | ||
6 | + </Key> | ||
7 | + <CostMultiplier><%= render_xml(@item.cost_multiplier, "1.0") %></CostMultiplier> | ||
8 | + <MinimumQty><%= render_xml(@item.minimum_qty) %></MinimumQty> | ||
9 | + <MaximumQty><%= render_xml(@item.maximum_qty) %></MaximumQty> | ||
10 | + <UnitCost><%= render_xml(@item.unit_cost) %></UnitCost> | ||
11 | + <DefaultBin><%= render_xml(@item.default_bin, "FG") %></DefaultBin> | ||
12 | + <SafetyStockQty><%= render_xml(@item.safety_stock_qty) %></SafetyStockQty> | ||
13 | + <ReOrderQty><%= render_xml(@item.re_order_qty) %></ReOrderQty> | ||
14 | + <PalletQty><%= render_xml(@item.pallet_qty) %></PalletQty> | ||
15 | + <UserField1><%= render_xml(@item.user_field1) %></UserField1> | ||
16 | + <UserField2><%= render_xml(@item.user_field2) %></UserField2> | ||
17 | + <UserField3><%= render_xml(@item.user_field3) %></UserField3> | ||
18 | + <OrderPolicy><%= render_xml(@item.order_policy, "C") %></OrderPolicy> | ||
19 | + <MajorOrderMult><%= render_xml(@item.major_order_mult) %></MajorOrderMult> | ||
20 | + <MinorOrderMult><%= render_xml(@item.minor_order_mult) %></MinorOrderMult> | ||
21 | + <OrderMinimum><%= render_xml(@item.order_minimum) %></OrderMinimum> | ||
22 | + <OrderMaximum><%= render_xml(@item.order_maximum) %></OrderMaximum> | ||
23 | + <OrderFixPeriod><%= render_xml(@item.order_fix_period, "01") %></OrderFixPeriod> | ||
24 | + <TrfSuppliedItem><%= render_xml(@item.trf_supplied_item, "N") %></TrfSuppliedItem> | ||
25 | + <DefaultSourceWh><%= render_xml(@item.default_source_wh) %></DefaultSourceWh> | ||
26 | + <TrfLeadTime><%= render_xml(@item.trf_lead_time, "0") %></TrfLeadTime> | ||
27 | + <TrfCostGlCode><%= render_xml(@item.trf_cost_gl_code) %></TrfCostGlCode> | ||
28 | + <TrfCostMultiply><%= render_xml(@item.trf_cost_multiply) %></TrfCostMultiply> | ||
29 | + <TrfReplenishWh><%= render_xml(@item.trf_replenish_wh, "0") %></TrfReplenishWh> | ||
30 | + <TrfBuyingRule><%= render_xml(@item.trf_buying_rule, "A") %></TrfBuyingRule> | ||
31 | + <TrfDockToStock><%= render_xml(@item.trf_dock_to_stock) %></TrfDockToStock> | ||
32 | + <TrfFixTimePeriod><%= render_xml(@item.trf_fix_time_period) %></TrfFixTimePeriod> | ||
33 | + <LabourCost><%= render_xml(@item.labour_cost) %></LabourCost> | ||
34 | + <MaterialCost><%= render_xml(@item.material_cost) %></MaterialCost> | ||
35 | + <FixedOverhead><%= render_xml(@item.fixed_overhead) %></FixedOverhead> | ||
36 | + <VariableOverhead><%= render_xml(@item.variable_overhead) %></VariableOverhead> | ||
37 | + <SubContractCost><%= render_xml(@item.sub_contract_cost) %></SubContractCost> | ||
38 | + <ManualCostFlag><%= render_xml(@item.manual_cost_flag, "N") %></ManualCostFlag> | ||
39 | + <% if @item.e_signature %> | ||
40 | + <eSignature><%= render_xml(@item.e_signature) %></eSignature> | ||
41 | + <% end %> | ||
42 | + </Item> | ||
43 | +</SetupInvWarehouse> | ||
0 | \ No newline at end of file | 44 | \ No newline at end of file |
test/comsfm_test.rb
@@ -24,7 +24,7 @@ class ComsFmTest < Minitest::Test | @@ -24,7 +24,7 @@ class ComsFmTest < Minitest::Test | ||
24 | cust_form.validate_only = "Y" | 24 | cust_form.validate_only = "Y" |
25 | cust_form.items = [cust_item] | 25 | cust_form.items = [cust_item] |
26 | 26 | ||
27 | - errors = cust_form.call(user_id.guid) | 27 | + errors = cust_form.add(user_id.guid) |
28 | 28 | ||
29 | assert_equal errors.length, 0 | 29 | assert_equal errors.length, 0 |
30 | end | 30 | end |
1 | +# frozen_string_literal: true | ||
2 | + | ||
3 | +require 'test_helper' | ||
4 | + | ||
5 | +class ComsFmTest < Minitest::Test | ||
6 | + extend Minitest::Spec::DSL | ||
7 | + | ||
8 | + let(:username) { ENV['SYSPRO_USERNAME'] } | ||
9 | + let(:password) { ENV['SYSPRO_PASSWORD'] } | ||
10 | + let(:company) { ENV['SYSPRO_COMPANY'] } | ||
11 | + let(:company_password) { '' } | ||
12 | + let(:user_id) do | ||
13 | + Syspro::Logon.logon(username, password, company, company_password) | ||
14 | + end | ||
15 | + | ||
16 | + def test_comsfm | ||
17 | + invsws_item = Syspro::BusinessObjects::Models::InvSwsItem.new | ||
18 | + invsws_item.key_stock_code = "1003" | ||
19 | + invsws_item.key_warehouse = "P0" | ||
20 | + invsws_item.default_bin = "P0" | ||
21 | + | ||
22 | + invsws_req = Syspro::BusinessObjects::InvSws.new | ||
23 | + invsws_req.validate_only = "Y" | ||
24 | + invsws_req.apply_product_class_default = "BA" | ||
25 | + invsws_req.ignore_warnings = "N" | ||
26 | + invsws_req.apply_if_entire_document_valid = "Y" | ||
27 | + invsws_req.item = invsws_item | ||
28 | + | ||
29 | + invsws_resp = invsws_req.add(user_id.guid) | ||
30 | + | ||
31 | + assert_equal invsws_resp[:error_numbers].length, 0 | ||
32 | + end | ||
33 | +end | ||
0 | \ No newline at end of file | 34 | \ No newline at end of file |