Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update list #376

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
[SuiteSync, the Stripe-NetSuite integration](http://suitesync.io) uses this gem and funds the majority of it's development and maintenance.
18 changes: 14 additions & 4 deletions lib/netsuite/actions/initialize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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={})
Expand All @@ -26,7 +27,7 @@ def request(credentials={})
# </platformCore:reference>
# </platformMsgs:initializeRecord>
def request_body
{
body = {
'platformMsgs:initializeRecord' => {
'platformCore:type' => @klass.to_s.split('::').last.lower_camelcase,
'platformCore:reference' => {},
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/netsuite/records/item_fulfillment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ 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

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
Expand Down
4 changes: 2 additions & 2 deletions lib/netsuite/records/sales_order_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/netsuite/support/records.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AgustinSuarez why did this functionality need to be moved out of the sublist module? I believe replaceAll is only applicable to sublists, so I don't think it should be required anywhere else. What am I missing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in order to upsert sales orders and other type of transaction correctly, you need to be able to define it as follows <listRel:addressbookList replaceAll="false"/> The problem with the previous code is that it added it as a field and didn't take it into consideration.

This helps when upserting records like addresses and line items


if v.kind_of?(NetSuite::Records::RecordRef) && v.type
hash[:attributes!] ||= {}
hash[:attributes!][kname] ||= {}
Expand Down
4 changes: 0 additions & 4 deletions lib/netsuite/support/sublist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down