Sha256: 3bc2fb13b5bb91b2d39d7d8eb86dfbc4d4b56fa5dec2822943a234611e0c99c3

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

module NetSuiteRails
  module UrlHelper

    # TODO create a xxx_netsuite_url helper generator

    def self.netsuite_url(record = self)
      prefix = "https://system#{".sandbox" if NetSuite::Configuration.sandbox}.netsuite.com/app"

      if record.class.to_s.start_with?('NetSuite::Records')
        record_class = record.class
        internal_id = record.internal_id
        is_custom_record = false
      else
        record_class = record.netsuite_record_class
        internal_id = record.netsuite_id
        is_custom_record = record.netsuite_custom_record?
      end

      # TODO support NS classes, should jump right to the list for the class

      # https://system.sandbox.netsuite.com/app/common/scripting/scriptrecordlist.nl
      # https://system.sandbox.netsuite.com/app/common/scripting/script.nl

      if is_custom_record
        "#{prefix}/common/custom/custrecordentry.nl?id=#{internal_id}&rectype=#{record.class.netsuite_custom_record_type_id}"
      elsif [ NetSuite::Records::InventoryItem, NetSuite::Records::NonInventorySaleItem, NetSuite::Records::AssemblyItem].include?(record_class)
        "#{prefix}/common/item/item.nl?id=#{internal_id}"
      elsif record_class == NetSuite::Records::Task
        "#{prefix}/crm/calendar/task.nl?id=#{internal_id}"
      elsif record_class == NetSuite::Records::Customer
        "#{prefix}/common/entity/custjob.nl?id=#{internal_id}"
      elsif record_class == NetSuite::Records::Contact
        "#{prefix}/common/entity/contact.nl?id=#{internal_id}"
      elsif [ NetSuite::Records::SalesOrder, NetSuite::Records::Invoice, NetSuite::Records::CustomerRefund ].include?(record_class)
        "#{prefix}/accounting/transactions/transaction.nl?id=#{internal_id}"
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
netsuite_rails-0.2.2 lib/netsuite_rails/url_helper.rb
netsuite_rails-0.2.1 lib/netsuite_rails/url_helper.rb
netsuite_rails-0.2.0 lib/netsuite_rails/url_helper.rb