使用Netsuite Ruby Gem获取事务时出错 - Savon :: SOAPFault:(soapenv:Server.userException)

时间:2014-03-10 19:29:07

标签: ruby-on-rails ruby savon netsuite

我正在使用netsuite ruby​​ gem(https://github.com/RevolutionPrep/netsuite)。

我和宝石的创始人交谈过,我正在使用抓取交易的正确方法: https://github.com/RevolutionPrep/netsuite/issues/52

在Gemfile中:

gem 'netsuite'

我在进行交易搜索时一直这样做:

1.9.3p448 :008 > search = NetSuite::Records::Transaction.get(3820)
HTTPI GET request to webservices.netsuite.com (net_http)
HTTPI POST request to webservices.netsuite.com (net_http)
Savon::SOAPFault: (soapenv:Server.userException) org.xml.sax.SAXException: transaction is not a legal value for {urn:types.core_2013_2.platform.webservices.netsuite.com}RecordType

这也会产生同样的错误:

search = NetSuite::Records::Transaction.get(:internal_id => 3820)

这有效:

def getAllTransactions
    #SearchStringField, searchValue

    t = Time.new 

    search = NetSuite::Records::Transaction.search({
        criteria: {
        basic: [
            {
                field: 'type',
                operator: 'anyOf',
                type: 'SearchEnumMultiSelectField',
                value: [ "_invoice" ]
            },
            {
                field: 'tranDate',
                operator: 'within',

                type: 'SearchDateField',
                value: [
                      Date.parse("12/1/2013").strftime("%Y-%m-%dT%H:%M:%S%z"),
                      Date.parse("#{t.month}/#{t.day}/#{t.year}").strftime("%Y-%m-%dT%H:%M:%S%z")
                    ]
            }
            ]
        }
    })

    search
end

这也有效:

NetSuite::Records::Customer.get(:internal_id => 3820)

这些不起作用:

1.9.3p448 :007 > customer = NetSuite::Records::Invoice.get(:internal_id => 7996) 
HTTPI GET request to webservices.netsuite.com (net_http)
HTTPI POST request to webservices.netsuite.com (net_http)
NetSuite::RecordNotFound: NetSuite::Records::Invoice with OPTIONS={:internal_id=>7996} could not be found
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/netsuite-0.2.0/lib/netsuite/actions/get.rb:73:in `get'
    from (irb):7
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:5:in `require'
    from script/rails:5:in `<main>'

1.9.3p448 :008 > customer = NetSuite::Records::SalesOrder.get(:internal_id => 7996)
HTTPI GET request to webservices.netsuite.com (net_http)
HTTPI POST request to webservices.netsuite.com (net_http)
NetSuite::RecordNotFound: NetSuite::Records::SalesOrder with OPTIONS={:internal_id=>7996} could not be found
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/netsuite-0.2.0/lib/netsuite/actions/get.rb:73:in `get'
    from (irb):8
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:5:in `require'
    from script/rails:5:in `<main>'

1.9.3p448 :009 > customer = NetSuite::Records::CashSale.get(:internal_id => 7996)
HTTPI GET request to webservices.netsuite.com (net_http)
HTTPI POST request to webservices.netsuite.com (net_http)
NetSuite::RecordNotFound: NetSuite::Records::CashSale with OPTIONS={:internal_id=>7996} could not be found
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/netsuite-0.2.0/lib/netsuite/actions/get.rb:73:in `get'
    from (irb):9
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:5:in `require'
    from script/rails:5:in `<main>'

这有效:

1.9.3p448 :010 > customer = NetSuite::Records::Customer.get(:internal_id => 7996)
HTTPI GET request to webservices.netsuite.com (net_http)
HTTPI POST request to webservices.netsuite.com (net_http)

2 个答案:

答案 0 :(得分:3)

当NS gem生成SOAP XML时,它实际上是添加了一个不正确的类型:

<env:Body>
  <platformMsgs:get>
    <platformMsgs:baseRef xsi:type="platformCore:RecordRef" internalId="130619" type="transaction"/>
  </platformMsgs:get>
</env:Body>

type ='transaction'被正确报告为错误。当您查看Schema Browser时,可以单击左上方框架中的'[types]来查找'platform core.xsd'。然后单击左下方框中显示的“RecordType”链接。

单击RecordType后,右侧框架中将显示RecordTypes列表。滚动浏览此列表时,您将看到它不包含“事务”条目。

但是,NetSuite::Records::Transaction类似乎只是SalesOrder类的包装器。

当我在控制台中运行以下内容时,所有事务(即销售)数据都在SalesOrder对象中返回:

NetSuite::Records::SalesOrder.get(interal_id: 1234)

长话短说,如果你只需要抓住一个交易(与搜索交易相比,你记得确实有效),你的应用和要求是否允许你只使用SalesOrder类?

答案 1 :(得分:3)

您无法提取交易记录 - 您必须提取特定的类型或交易记录。某些类型包括:Invoice,SalesOrder和CashSale。

尝试访问以下网址:

https://system.netsuite.com/app/accounting/transactions/transaction.nl?id=3820

这可以让您了解记录的事务类型。如果是发票,您可以使用以下方式检索它:

NetSuite::Records::Invoice.get(1234)

以下是NS交易流程的一些粗略说明。其中一些可能是我们的实例特有的,但其中大部分都适用于NS作为一个整体,可能对您或其他试图拼凑NS如何工作的人有所帮助。

  • 大部分时间每个CashSale(CS)和发票都有与之关联的销售订单(SO)。如果是经常性费用(如每月服务费),CS或发票不必与之相关联的SO
  • SO可以有销售付款订单或与之相关的发票。例如:如果某人当场用CC付款,那么它会产生“现金销售”
  • SO,CS订单和发票都有类似的数据,但都有唯一的NS ID。它们不是同一数据的不同视图,即同一NS ID上的Contact vs Customer视图。
  • 即使已经全额付款,SO也永远不会超过“收费”状态
  • 交易是一个流程。每条记录代表语义上的东西。因此,在正常的业务流程中,可能会产生一个人的后果。因此,销售订单意味着,销售人员正在与一个人打电话,如果公司将在以后收到“收费”时生成发票,他们会订购一些东西,这是一份要求支付货物的声明/服务