From 592da3ca3ad2de6badbe8cee2c1f9a2b21987e3c Mon Sep 17 00:00:00 2001 From: AgustinSuarez <31255403+AgustinSuarez@users.noreply.github.com> Date: Tue, 21 Nov 2017 09:09:02 -0500 Subject: [PATCH 1/3] Added support for references on Initialize --- lib/netsuite/actions/initialize.rb | 18 ++++++++++++++---- lib/netsuite/records/item_fulfillment.rb | 2 +- lib/netsuite/records/sales_order_item.rb | 4 ++-- lib/netsuite/support/records.rb | 6 ++++++ lib/netsuite/support/sublist.rb | 4 ---- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/netsuite/actions/initialize.rb b/lib/netsuite/actions/initialize.rb index 8e5ab949c..926a64f44 100644 --- a/lib/netsuite/actions/initialize.rb +++ b/lib/netsuite/actions/initialize.rb @@ -4,9 +4,10 @@ module Actions class Initialize include Support::Requests - def initialize(klass, object) + def initialize(klass, object, options = {}) @klass = klass @object = object + @options = options end def request(credentials={}) @@ -26,7 +27,7 @@ def request(credentials={}) # # def request_body - { + body = { 'platformMsgs:initializeRecord' => { 'platformCore:type' => @klass.to_s.split('::').last.lower_camelcase, 'platformCore:reference' => {}, @@ -38,6 +39,15 @@ def request_body } } } + + if @options.key?(:aux_reference) + body['platformMsgs:initializeRecord']['platformCore:auxReference'] = {} + body['platformMsgs:initializeRecord'][:attributes!]['platformCore:auxReference'] = { + 'internalId' => @options[:aux_reference][:internal_id], + :type => @options[:aux_reference][:type] + } + end + body end def response_hash @@ -65,8 +75,8 @@ def self.included(base) module ClassMethods - def initialize(object, credentials={}) - response = NetSuite::Actions::Initialize.call([self, object], credentials) + def initialize(object, options, credentials={}) + response = NetSuite::Actions::Initialize.call([self, object, options], credentials) if response.success? new(response.body) else diff --git a/lib/netsuite/records/item_fulfillment.rb b/lib/netsuite/records/item_fulfillment.rb index fd5e691d3..63bac72a7 100644 --- a/lib/netsuite/records/item_fulfillment.rb +++ b/lib/netsuite/records/item_fulfillment.rb @@ -16,7 +16,7 @@ class ItemFulfillment read_only_fields :handling_cost record_refs :custom_form, :entity, :created_from, :ship_carrier, :ship_method, - :ship_address_list, :klass, :ship_country + :ship_address_list, :klass, :ship_country, :shipping_group # NOTE API version < 2015_1 only field :transaction_ship_address, ShipAddress diff --git a/lib/netsuite/records/sales_order_item.rb b/lib/netsuite/records/sales_order_item.rb index 0b659a5ea..fb52af093 100644 --- a/lib/netsuite/records/sales_order_item.rb +++ b/lib/netsuite/records/sales_order_item.rb @@ -17,11 +17,11 @@ class SalesOrderItem :rev_rec_start_date, :rev_rec_term_in_months, :serial_numbers, :shipping_cost, :tax1_amt, :tax_rate1, :tax_rate2, :vsoe_allocation, :vsoe_amount, :vsoe_deferral, - :vsoe_delivered, :vsoe_permit_discount, :vsoe_price + :vsoe_delivered, :vsoe_permit_discount, :vsoe_price, :ship_group field :custom_field_list, CustomFieldList - record_refs :department, :item, :job, :klass, :location, :price, :rev_rec_schedule, :tax_code, :units + record_refs :department, :item, :job, :klass, :location, :price, :rev_rec_schedule, :tax_code, :units, :ship_address def initialize(attributes_or_record = {}) case attributes_or_record diff --git a/lib/netsuite/support/records.rb b/lib/netsuite/support/records.rb index 74f3aa9d2..763acdb8a 100644 --- a/lib/netsuite/support/records.rb +++ b/lib/netsuite/support/records.rb @@ -35,6 +35,12 @@ def to_attributes!(hash, kname, v) hash[:attributes!][kname]['externalId'] = v.external_id end + if v.respond_to?(:replace_all) && !v.replace_all.to_s.empty? + hash[:attributes!] ||= {} + hash[:attributes!][kname] ||= {} + hash[:attributes!][kname]['replaceAll'] = v.replace_all + end + if v.kind_of?(NetSuite::Records::RecordRef) && v.type hash[:attributes!] ||= {} hash[:attributes!][kname] ||= {} diff --git a/lib/netsuite/support/sublist.rb b/lib/netsuite/support/sublist.rb index 4266f09d1..99bf5c4e2 100644 --- a/lib/netsuite/support/sublist.rb +++ b/lib/netsuite/support/sublist.rb @@ -37,10 +37,6 @@ def initialize(attributes = {}) def to_record rec = { "#{record_namespace}:#{sublist_key.to_s.lower_camelcase}" => send(self.sublist_key).map(&:to_record) } - if !replace_all.nil? - rec["#{record_namespace}:replaceAll"] = !!replace_all - end - rec end From bf93d9f7be7f77e590cc848f155ac192ab795765 Mon Sep 17 00:00:00 2001 From: AgustinSuarez <31255403+AgustinSuarez@users.noreply.github.com> Date: Thu, 7 Dec 2017 10:39:38 -0500 Subject: [PATCH 2/3] Allowed options parameter to be optional. added created_from_ship_group --- lib/netsuite/actions/initialize.rb | 2 +- lib/netsuite/records/item_fulfillment.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/netsuite/actions/initialize.rb b/lib/netsuite/actions/initialize.rb index 926a64f44..51983b386 100644 --- a/lib/netsuite/actions/initialize.rb +++ b/lib/netsuite/actions/initialize.rb @@ -75,7 +75,7 @@ def self.included(base) module ClassMethods - def initialize(object, options, credentials={}) + def initialize(object, options = {}, credentials={}) response = NetSuite::Actions::Initialize.call([self, object, options], credentials) if response.success? new(response.body) diff --git a/lib/netsuite/records/item_fulfillment.rb b/lib/netsuite/records/item_fulfillment.rb index 63bac72a7..d56a66f29 100644 --- a/lib/netsuite/records/item_fulfillment.rb +++ b/lib/netsuite/records/item_fulfillment.rb @@ -11,7 +11,7 @@ class ItemFulfillment fields :tran_date, :tran_id, :shipping_cost, :memo, :ship_company, :ship_attention, :ship_addr1, :ship_addr2, :ship_city, :ship_state, :ship_zip, :ship_phone, :ship_is_residential, - :ship_status, :last_modified_date, :created_date + :ship_status, :last_modified_date, :created_date, :created_from_ship_group read_only_fields :handling_cost From e39f0199059942e62e62fbbfe7e98be6d1466448 Mon Sep 17 00:00:00 2001 From: AgustinSuarez <31255403+AgustinSuarez@users.noreply.github.com> Date: Wed, 10 Jan 2018 12:12:08 -0500 Subject: [PATCH 3/3] Added documentation for auxReference --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a6332fbe4..cb7e154ad 100644 --- a/README.md +++ b/README.md @@ -547,6 +547,25 @@ deposit.payment = 20 deposit.add ``` + +## Initialize Fulfillment from Sales Order with Multi Ship Enabled + +```ruby + # You can initialize a fulfillment by specifying an auxReference to retrieve a specific Ship Group + # This will return a fulfillment with line items linked to said ship group which is associated to + # a specific location. + aux_reference = { + aux_reference: { + internal_id: 1, # Ship Group IDs can be found on Line Items on the Sales Order + type: "shippingGroup" + } + } + + + fulfillment = NetSuite::Records::ItemFulfillment.initialize(@sales_order, aux_reference) +``` + + ## Non-standard Operations ```ruby @@ -570,4 +589,4 @@ states.to_array.first[:get_all_response][:get_all_result][:record_list][:record] # About SuiteSync -[SuiteSync, the Stripe-NetSuite integration](http://suitesync.io) uses this gem and funds the majority of it's development and maintenance. \ No newline at end of file +[SuiteSync, the Stripe-NetSuite integration](http://suitesync.io) uses this gem and funds the majority of it's development and maintenance.