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

Cld 1835 netsuite null fields #481

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
cf1338c
[CLOUD-737-attach-functionality]
reginad1 Nov 5, 2019
55bea99
Merge pull request #1 from CloudsnapInc/add-attach-functionlity
reginad1 Nov 12, 2019
2b61c83
[hotfix-CLOUD-737]
reginad1 Nov 18, 2019
633895a
Merge pull request #2 from CloudsnapInc/fix-add-action-file
reginad1 Nov 18, 2019
f4e02c9
[HOTFIX-CLOUD-737-add-action-for-file]
reginad1 Nov 18, 2019
247a8db
Merge pull request #3 from CloudsnapInc/add-action-for-file
reginad1 Nov 18, 2019
022a6e6
[CLD-597-intercompany-updates]
reginad1 Jan 31, 2020
e4dcb31
[CLD-571-expense-report]
reginad1 Jan 30, 2020
3d77d54
Merge pull request #4 from CloudsnapInc/CLD-597-sales-order
reginad1 Feb 3, 2020
656ca69
Merge pull request #5 from CloudsnapInc/CLD-571-expense-report
reginad1 Feb 3, 2020
439e871
[CLD-659-sales-order-lines]
reginad1 Feb 17, 2020
3ef6d6c
Merge pull request #6 from CloudsnapInc/CLD-619-sales-order-item
reginad1 Feb 20, 2020
fe66da5
[CLD-669-vendorcredit-record-refs]
reginad1 Feb 24, 2020
fe96eff
Merge pull request #7 from CloudsnapInc/CLD-669-vendorcredit
reginad1 Feb 24, 2020
330ffa6
[CLD-725-expenses-on-purchaseorders]
reginad1 Mar 13, 2020
f9b05f7
Merge pull request #8 from CloudsnapInc/CLD-725-purchase-order-expense
reginad1 Mar 16, 2020
7fbe5b2
[CLD-737-item-receipt-expenses]
reginad1 Mar 17, 2020
bc79ecf
Merge pull request #9 from CloudsnapInc/CLD-737-expense-item-receipt
reginad1 Mar 18, 2020
0423790
[CLD-756-Add-Expense-Categories]
reginad1 Mar 25, 2020
99b040d
Merge pull request #10 from CloudsnapInc/CLD-756-Add-Expense-Category
reginad1 Mar 25, 2020
3a3c747
[CLD-882-large-response]
reginad1 Apr 21, 2020
811e421
pry
reginad1 Apr 21, 2020
3d0f984
remove pry
reginad1 Apr 21, 2020
1a2045e
pry
reginad1 Apr 21, 2020
e188a5d
remove pry
reginad1 Apr 21, 2020
28125a4
Merge pull request #11 from CloudsnapInc/increase-timeout
reginad1 Apr 21, 2020
e20132a
[CLD-878-support-later-version]
reginad1 May 2, 2020
16371f7
Merge pull request #12 from CloudsnapInc/update-config-for-versions
reginad1 May 11, 2020
c36ebba
[CLD-917-vendor-credit-klass]
reginad1 May 11, 2020
7db5d5d
Merge pull request #13 from CloudsnapInc/cld-917-class-at-vendorcredit
reginad1 May 11, 2020
ce4b0fb
[CLD-918] Added custom fields to Account class.
gmike11 May 18, 2020
8db4b19
Merge pull request #14 from CloudsnapInc/gmike11/CLD-918
gmike11 May 18, 2020
b3f65d1
[CLD-1157-expense-accounts-added]
reginad1 Sep 8, 2020
f61fd97
Merge pull request #15 from CloudsnapInc/CLD-1157-expense-accounts
reginad1 Sep 9, 2020
e27f858
[CLD-1220-service-purchase-item-endpoint]
reginad1 Sep 24, 2020
3b941d2
Merge pull request #16 from CloudsnapInc/CLD-1220-service-purchase-item
reginad1 Sep 24, 2020
c3145a6
CLD-1154 Improve error messaging
gmike11 Oct 6, 2020
805c7cd
Merge pull request #17 from CloudsnapInc/CLD-1154-error-messages
gmike11 Oct 16, 2020
a89db03
[CLD-1276-fix-typo]
reginad1 Oct 28, 2020
ccc3e31
Merge pull request #18 from CloudsnapInc/CLD-1279-fix-typo
reginad1 Oct 29, 2020
4251842
[CLD-1324-update-global-config]
reginad1 Nov 19, 2020
f73435d
Merge pull request #19 from CloudsnapInc/CLD-1324-update-global-config
reginad1 Nov 24, 2020
d410bee
[L3-39-add-accounting_period_fields]
dbbarkley Dec 17, 2020
489aa8b
Merge pull request #20 from CloudsnapInc/add_accounting_period_fields
dbbarkley Dec 17, 2020
cdc3e50
update readme to include Cloudsnap additions
reginad1 Jan 22, 2021
d74d3be
Merge pull request #21 from CloudsnapInc/update-readme
reginad1 Jan 25, 2021
67a0215
fix multiselect bug
dbbarkley Mar 5, 2021
a4460fe
Merge pull request #23 from CloudsnapInc/multi_select_support
dbbarkley Mar 9, 2021
4f0cc2c
added employee address records
dbbarkley Apr 7, 2021
1776652
Merge pull request #24 from CloudsnapInc/employee_address_support
dbbarkley Apr 8, 2021
1ac62f8
added default address field on employee class
jiminhuh Apr 13, 2021
f7fd347
Merge pull request #25 from CloudsnapInc/L3-199_adding_default_address
shaneblaser-cloudsnap Apr 13, 2021
6227de5
Initial commit WIP
gmike11 Jun 23, 2021
d8ff880
removed commented fields, using NullFieldList class
dbbarkley Jun 30, 2021
bb7f976
Why:
gmike11 Jul 13, 2021
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gem 'simplecov', :require => false

gem 'pry-nav'
gem 'pry-rescue'
gem 'pry'
Copy link
Member

Choose a reason for hiding this comment

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

Why did you need to include this directly?


# optional dependency for more accurate timezone conversion
gem 'tzinfo', '1.2.5'
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,23 @@ 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.




# Cloudsnap Additions

I generally refer to the Netsuite Schema Browser as a source of truth over the actions, records, and fields that you see in this gem. That documentation can be found here: https://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2018_1/schema/record/account.html?mode=package

**One note is to be mindful of the version that you are looking at in the schema browser and the version that you are using when you configure the netsuite credentials.

### Actions
attach.rb--> lib/netsuite/actions/attach.rb
Based on the Netsuite Schema documentation, we added in the attach action functionality. This is primarily used to attach records considered File Cabinate


### Records
If you see the record in the netsuite schema browser, you can easily add it to the records in this gem. Use the fields and sub lists mentioned in the Netsuite schema browser to build out the record file following the same format as the other record files.

### Other Cloudsnap Changes
We made a few changes to the configuration.rb file. The check credentials method and set attributes methods were added to support the updated way of passing credentials. In the connection method, we also added the ability to set the wsdl and the endpoint level for the Savon client that is configured. This was required to connect to Netsuite api versions 2020+
Copy link
Member

Choose a reason for hiding this comment

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

After this is merged, I'll go ahead and edit these readme changes a bit to fit within the existing readme structure.

16 changes: 16 additions & 0 deletions lib/netsuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module Support

module Actions
autoload :Add, 'netsuite/actions/add'
autoload :Attach, 'netsuite/actions/attach'
autoload :Delete, 'netsuite/actions/delete'
autoload :DeleteList, 'netsuite/actions/delete_list'
autoload :Get, 'netsuite/actions/get'
Expand All @@ -74,6 +75,7 @@ module Records
autoload :Account, 'netsuite/records/account'
autoload :AccountingPeriod, 'netsuite/records/accounting_period'
autoload :Address, 'netsuite/records/address'
autoload :AttachBasicReference, 'netsuite/records/attach_basic_reference'
autoload :BaseRefList, 'netsuite/records/base_ref_list'
autoload :BillAddress, 'netsuite/records/bill_address'
autoload :BillingSchedule, 'netsuite/records/billing_schedule'
Expand Down Expand Up @@ -156,8 +158,16 @@ module Records
autoload :DescriptionItem, 'netsuite/records/description_item'
autoload :DiscountItem, 'netsuite/records/discount_item'
autoload :Duration, 'netsuite/records/duration'
autoload :EmployeeAddressbookList, 'netsuite/records/employee_addressbook_list'
autoload :EmployeeAddressbook, 'netsuite/records/employee_addressbook'
autoload :Employee, 'netsuite/records/employee'
autoload :EntityCustomField, 'netsuite/records/entity_custom_field'
autoload :ExpenseCategory, 'netsuite/records/expense_category'
autoload :ExpenseCategoryRate, 'netsuite/records/expense_category_rate'
autoload :ExpenseCategoryRatesList, 'netsuite/records/expense_category_rates_list'
autoload :ExpenseReport, 'netsuite/records/expense_report'
autoload :ExpenseReportExpense, 'netsuite/records/expense_report_expense'
autoload :ExpenseReportExpenseList, 'netsuite/records/expense_report_expense_list'
autoload :File, 'netsuite/records/file'
autoload :GiftCertificate, 'netsuite/records/gift_certificate'
autoload :GiftCertificateItem, 'netsuite/records/gift_certificate_item'
Expand Down Expand Up @@ -195,6 +205,8 @@ module Records
autoload :ItemMember, 'netsuite/records/item_member'
autoload :ItemMemberList, 'netsuite/records/item_member_list'
autoload :ItemReceipt, 'netsuite/records/item_receipt'
autoload :ItemReceiptExpenseList, 'netsuite/records/item_receipt_expense_list'
autoload :ItemReceiptExpense, 'netsuite/records/item_receipt_expense'
autoload :ItemReceiptItemList, 'netsuite/records/item_receipt_item_list'
autoload :ItemReceiptItem, 'netsuite/records/item_receipt_item'
autoload :ItemVendor, 'netsuite/records/item_vendor'
Expand All @@ -217,6 +229,7 @@ module Records
autoload :NonInventoryResaleItem, 'netsuite/records/non_inventory_resale_item'
autoload :Note, 'netsuite/records/note'
autoload :NoteType, 'netsuite/records/note_type'
autoload :NullFieldList, 'netsuite/records/null_field_list'
autoload :Opportunity, 'netsuite/records/opportunity'
autoload :OpportunityItem, 'netsuite/records/opportunity_item'
autoload :OpportunityItemList, 'netsuite/records/opportunity_item_list'
Expand All @@ -235,6 +248,8 @@ module Records
autoload :PromotionsList, 'netsuite/records/promotions_list'
autoload :Promotions, 'netsuite/records/promotions'
autoload :PurchaseOrder, 'netsuite/records/purchase_order'
autoload :PurchaseOrderExpenseList, 'netsuite/records/purchase_order_expense_list'
autoload :PurchaseOrderExpense, 'netsuite/records/purchase_order_expense'
autoload :PurchaseOrderItemList, 'netsuite/records/purchase_order_item_list'
autoload :PurchaseOrderItem, 'netsuite/records/purchase_order_item'
autoload :Roles, 'netsuite/records/roles'
Expand All @@ -252,6 +267,7 @@ module Records
autoload :SalesOrderItemList, 'netsuite/records/sales_order_item_list'
autoload :SalesRole, 'netsuite/records/sales_role'
autoload :SalesTaxItem, 'netsuite/records/sales_tax_item'
autoload :ServicePurchaseItem, 'netsuite/records/service_purchase_item'
autoload :ServiceResaleItem, 'netsuite/records/service_resale_item'
autoload :ServiceSaleItem, 'netsuite/records/service_sale_item'
autoload :SerializedAssemblyItem, 'netsuite/records/serialized_assembly_item'
Expand Down
3 changes: 1 addition & 2 deletions lib/netsuite/actions/add.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ def errors
module Support
def add(credentials={})
response = NetSuite::Actions::Add.call([self], credentials)

@errors = response.errors

if response.success?
@internal_id = response.body[:@internal_id]
@internal_id = response.body.dig(:@internal_id) unless response.body.class == Nori::StringIOFile
Copy link
Member

Choose a reason for hiding this comment

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

What is response.body.class == Nori::StringIOFile protecting against?

Copy link
Contributor

Choose a reason for hiding this comment

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

#495 likely adds some more context around where Nori::StringIOFile is coming from and attempts to address it in a way that still ensures the internal_id is extracted.

true
else
false
Expand Down
87 changes: 87 additions & 0 deletions lib/netsuite/actions/attach.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
module NetSuite
module Actions
class Attach
include Support::Requests

attr_reader :response_hash

def initialize(object=nil)
@object = object
end

private

def request(credentials={})
NetSuite::Configuration.connection({}, credentials).call(:attach, :message => request_body)
end

#please note, reference is spelled referece and is documented that way in NetSuite's documentation
# <soap:Body>
# <platformMsgs:attach>
# <platformMsgs:attachReferece xsi:type="platformCore:AttachBasicReference">
# <platformCore:attachTo internalId="443" type="vendorBill" xsi:type="platformCore:RecordRef"/>
# <platformCore:attachedRecord type="file" internalId="353" xsi:type="platformCore:RecordRef"/>
# </platformMsgs:attachReferece>
# </platformMsgs:attach>
# </soap:Body>

def request_body
hash = {
'platformMsgs:attachReferece' => {
:content! => @object.to_record,
'@xsi:type' => @object.record_type
}
}
#not crazy about this solution but not sure how else to get the 'xsi:type' var in the hash
hash["platformMsgs:attachReferece"][:content!][:attributes!]["platformCore:attachTo"]["xsi:type"] = "platformCore:RecordRef"
hash["platformMsgs:attachReferece"][:content!][:attributes!]["platformCore:attachedRecord"]["xsi:type"] = "platformCore:RecordRef"

hash
end

def success?
@success ||= response_hash[:status][:@is_success] == 'true'
end

def response_body
@response_body ||= response_hash[:base_ref]
end

def response_errors
if response_hash[:status] && response_hash[:status][:status_detail]
@response_errors ||= errors
end
end

def response_hash
@response_hash ||= @response.to_hash[:attach_response][:write_response]
end

def errors
error_obj = response_hash[:status][:status_detail]
error_obj = [error_obj] if error_obj.class == Hash
error_obj.map do |error|
NetSuite::Error.new(error)
end
end


module Support
def attach(credentials={})
response = NetSuite::Actions::Attach.call([self], credentials)

@errors = response.errors

if response.success?
@internal_id = response.body[:@internal_id]
true
else
false
end
end
end


end
end
end
13 changes: 12 additions & 1 deletion lib/netsuite/actions/get.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ def response_hash
@response_hash = @response.body[:get_response][:read_response]
end

def response_errors
if response_hash[:status] && response_hash[:status][:status_detail]
@response_errors ||= errors
end
end

def errors
error_obj = response_hash.dig(:status,:status_detail)
OpenStruct.new(status: 404, status_detail: error_obj)
end
Copy link
Member

Choose a reason for hiding this comment

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

Can we pull this logic into a separate PR?


module Support

def self.included(base)
Expand All @@ -71,7 +82,7 @@ def get(options = {}, credentials = {})
if response.success?
new(response.body)
else
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found, NetSuite message: #{response.errors.status_detail[:message]}"
end
end

Expand Down
1 change: 0 additions & 1 deletion lib/netsuite/actions/get_select_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def get_select_value(options = {}, credentials={})
}

response = NetSuite::Actions::GetSelectValue.call([self, message], credentials)

if response.success?
new(response.body)
else
Expand Down
6 changes: 6 additions & 0 deletions lib/netsuite/actions/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def request_body
hash['platformMsgs:record']['@platformMsgs:externalId'] = updated_record.external_id
end

inner = hash.dig("platformMsgs:record", :content!)
if inner.keys.grep(/(.*):nullFieldList?/).any?
null_field_key = inner.keys.grep(/(.*):nullFieldList?/)
hash["platformMsgs:record"][:content!]["platformCore:nullFieldList"] = hash["platformMsgs:record"][:content!].delete null_field_key[0]
end
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain what's going on here? Could you pull this into a separate PR?

Choose a reason for hiding this comment

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

I needed to extract the NullFieldList stuff and this part makes sure the updated_record.record_type isn't used for the nullFieldList


hash
end

Expand Down
22 changes: 21 additions & 1 deletion lib/netsuite/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def attributes
end

def connection(params={}, credentials={})
check_credentials(credentials)
Copy link
Member

Choose a reason for hiding this comment

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

Why were these changes required in your case? This smells like something specific to your application and not something we'd want to include in the netsuite gem.


client = Savon.client({
wsdl: cached_wsdl || wsdl,
read_timeout: read_timeout,
Expand All @@ -27,10 +29,28 @@ def connection(params={}, credentials={})
log_level: log_level,
log: !silent, # turn off logging entirely if configured
}.update(params))
client.wsdl.endpoint = client.wsdl.endpoint.to_s.sub('//webservices.netsuite.com/', "//#{wsdl_domain}/")
Copy link
Member

Choose a reason for hiding this comment

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

This should be fixed by this PR #473

cache_wsdl(client)
return client
end

def check_credentials(creds)
if !creds.blank?
set_attributes(creds)
end
end

def set_attributes(credentials)
account(credentials[:account])
consumer_key(credentials[:consumer_key])
consumer_secret(credentials[:consumer_secret])
token_id(credentials[:token_id])
token_secret(credentials[:token_secret])
api_version(credentials[:api_version])
wsdl_domain(credentials[:wsdl_domain])
soap_header(credentials[:soap_header])
end

def filters(list = nil)
if list
self.filters = list
Expand Down Expand Up @@ -323,7 +343,7 @@ def read_timeout(timeout = nil)
if timeout
self.read_timeout = timeout
else
attributes[:read_timeout] ||= 60
attributes[:read_timeout] ||= 120
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/netsuite/records/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Account

field :subsidiary_list, RecordRefList

field :custom_field_list, CustomFieldList

attr_reader :internal_id
attr_accessor :external_id
attr_accessor :search_joins
Expand Down
2 changes: 1 addition & 1 deletion lib/netsuite/records/accounting_period.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AccountingPeriod

actions :get, :get_list, :add, :delete, :upsert, :search

fields :allow_non_gl_changes, :end_date, :is_adjust, :is_quarter, :is_year, :period_name, :start_date
fields :allow_non_gl_changes, :end_date, :is_adjust, :is_quarter, :is_year, :period_name, :start_date, :all_locked, :ap_locked, :ar_locked, :closed, :closed_on_date, :payroll_locked

record_refs :parent

Expand Down
20 changes: 20 additions & 0 deletions lib/netsuite/records/attach_basic_reference.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module NetSuite
module Records
class AttachBasicReference
include Support::Fields
include Support::RecordRefs
include Support::Records
include Support::Actions
include Namespaces::PlatformCore

actions :attach

record_refs :attach_to, :attached_record

def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end

end
end
end
1 change: 1 addition & 0 deletions lib/netsuite/records/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Contact
field :custom_field_list, CustomFieldList
# field :subscriptions_list, SubscriptionsList
# field :category_list, CategoryList
field :null_field_list, NullFieldList

read_only_fields :last_modified_date, :date_created

Expand Down
1 change: 1 addition & 0 deletions lib/netsuite/records/credit_memo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CreditMemo
field :item_list, CreditMemoItemList
field :apply_list, CreditMemoApplyList
field :ship_group_list, SalesOrderShipGroupList
field :null_field_list, NullFieldList

# field :bill_address_list,
field :transaction_bill_address, BillAddress
Expand Down
9 changes: 6 additions & 3 deletions lib/netsuite/records/custom_field_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ def extract_custom_field(custom_field_data)
if type == "platformCore:SelectCustomFieldRef"
attrs[:value] = CustomRecordRef.new(custom_field_data[:value])
elsif type == 'platformCore:MultiSelectCustomFieldRef'
attrs[:value] = custom_field_data[:value].map do |entry|
CustomRecordRef.new(entry)
# if only one value of multiselect is selected it will be a hash, not an array
if attrs[:value].is_a?(Array)
attrs[:value] = custom_field_data[:value].map { |entry| CustomRecordRef.new(entry) }
else
attrs[:value] = CustomRecordRef.new(custom_field_data[:value])
Copy link
Member

Choose a reason for hiding this comment

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

This was recently fixed: 3377c97

Can you remove this change from your PR?

end
end

custom_fields << CustomField.new(attrs)

end
end

Expand Down
1 change: 1 addition & 0 deletions lib/netsuite/records/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Customer
field :partners_list, CustomerPartnersList
field :subscriptions_list, CustomerSubscriptionsList
field :sales_team_list, CustomerSalesTeamList
field :null_field_list, NullFieldList

read_only_fields :balance, :consol_balance, :deposit_balance, :consol_deposit_balance, :overdue_balance,
:consol_overdue_balance, :unbilled_orders, :consol_unbilled_orders
Expand Down
1 change: 1 addition & 0 deletions lib/netsuite/records/customer_payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CustomerPayment

field :custom_field_list, CustomFieldList
field :apply_list, CustomerPaymentApplyList
field :null_field_list, NullFieldList

read_only_fields :applied, :balance, :pending, :total, :unapplied

Expand Down
Loading