Netsuite名称空间冲突(core_2017_2.platform与Accounting_2017_2.lists) [英] Netsuite namespace conflict (core_2017_2.platform vs accounting_2017_2.lists)

查看:105
本文介绍了Netsuite名称空间冲突(core_2017_2.platform与Accounting_2017_2.lists)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的Python脚本中向Netsuite发布日记条目.我正在使用zeep与SuiteTalk交谈.

I want to post a journal entry to Netsuite from my Python script. I am using zeep to talk to SuiteTalk.

我是Netsuite的新手,也是SOAP的新手.在网上示例中,我设法使用以下代码通过Python脚本添加了测试客户:

I am new to Netsuite and I am new to SOAP. Following on internet examples, I managed to add a test customer via Python script using the below code:

def make_app_info(client):
    AppInfo = client.get_type('ns4:ApplicationInfo')
    app_info = AppInfo(applicationId=NS_APPID)
    return app_info


def make_passport(client):
    RecordRef = client.get_type('ns0:RecordRef')
    Passport = client.get_type('ns0:Passport')
    role = RecordRef(internalId=NS_ROLE)

    return Passport(email=NS_EMAIL,
                    password=NS_PASSWORD,
                    account=NS_ACCOUNT,
                    role=role)


def login_client():
    client = Client(WSDL_URL)
    login = client.service.login(passport=make_passport(client), _soapheaders={'applicationInfo': make_app_info(client)})
    return client

我正在使用的WSDL_URL https://webservices.netsuite.com /wsdl/v2017_2_0/netsuite.wsdl

使用上述客户,以下代码可添加客户:

Using the above client the below code adds the customer:

def add_customer():
    client = login_client()

    Customer = client.get_type('ns13:Customer')
    customer = Customer(
        lastName='Prasad',
        firstName='Vikas',
        email='vikasprasad@example.com',
        companyName='Test Company'
    )

    client.service.add(customer)

add_customer()

以上内容已成功将Customer添加到Netsuite帐户中,我可以在Web应用程序的列表中看到它. 继续上面的示例,我编写了以下代码以添加JournalEntry:

The above adds the Customer successfully to the Netsuite account and I can see it in the list on the webapp. Continuing on the above example, I wrote this code to add JournalEntry:

def get_record_by_type(client, type, internal_id):
    RecordRef = client.get_type('ns0:RecordRef')

    record = RecordRef(internalId=internal_id, type=type)
    response = client.service.get(record,
        _soapheaders={
            'applicationInfo': make_app_info(client),
            'passport': make_passport(client),
        }
    )
    r = response.body.readResponse
    if r.status.isSuccess:
        return r.record

def add_journal_entry():
    client = login_client()

    # get subsidiary by internal id
    subsidiary = get_record_by_type(client, 'subsidiary', '1')
    print(subsidiary)    # This prints a valid subsidiary having internal id 1

    # create two journal entry lines
    JournalEntryLine = client.get_type('ns31:JournalEntryLine')
    credit_line = JournalEntryLine(account=get_record_by_type(client, 'account', '1'), credit=100)
    debit_line = JournalEntryLine(account=get_record_by_type(client, 'account', '2'), debit=100)
    print(credit_line)    # This prints credit_line with a valid account having internal id 1
    print(debit_line)    # This prints debit_line with a valid account having internal id 2

    JournalEntryLineList = client.get_type('ns31:JournalEntryLineList')
    journal_entry_line_list = JournalEntryLineList(line=[credit_line, debit_line])

    JournalEntry = client.get_type('ns31:JournalEntry')
    journal_entry = JournalEntry(subsidiary=subsidiary, lineList=journal_entry_line_list)

    client.service.add(journal_entry, _soapheaders={'passport': make_passport(client),
                   'applicationInfo': make_app_info(client)})  # Fails on this line.

add_journal_entry()

这在呼叫client.service.add(...)时失败,并显示错误:

This fails on the call client.service.add(...) with the error:

zeep.exceptions.Fault:org.xml.sax.SAXException:预期 找到{urn:core_2017_2.platform.webservices.netsuite.com}名称 {urn:accounting_2017_2.lists.webservices.netsuite.com}名称

zeep.exceptions.Fault: org.xml.sax.SAXException: Expected {urn:core_2017_2.platform.webservices.netsuite.com}name, found {urn:accounting_2017_2.lists.webservices.netsuite.com}name

我确信这在SOAP领域是很愚蠢的,但是我不确定要调试到哪个方向.为什么期望值和发现值之间有区别?我在任何地方都没有提到任何特定的名称空间.在此之上仅进行WSDL v2017_2_0和所有client.get_type()调用.这个错误是从哪里来的?

I am sure this is something silly in the world of SOAP, but I am not sure which direction to debug into. Why is there a difference between the expected and the found one? I have nowhere mentioned any specific namespaces. Its just WSDL v2017_2_0 and all the client.get_type() call are made on top of this. Where is this error coming from?

在Netsuite用户组中提出了相同的问题: https://usergroup.netsuite.com/users/forum/platform-areas/web-services-suitetalk/434717-netsuite-namespace-conflict#post434717

Have asked the same question at Netsuite user group: https://usergroup.netsuite.com/users/forum/platform-areas/web-services-suitetalk/434717-netsuite-namespace-conflict#post434717

更新: 根据@Justin W的回答,事实证明,我可以直接告诉Suitetalk type和<使用RecordRef和Suitetalk的c8>将了解要使用的subsidiaryaccount.

UPDATE: Based on @Justin W's answer it turns out, that instead of fetching the subsidiary and accounts by their internalId from Suitetalk and then adding them in the request, I can directly tell Suitetalk the type and the internalId using a RecordRef and Suitetalk will understand what subsidiary and accounts to use.

subsidiary = get_record_by_type(client, 'subsidiary', '1')可以更改为subsidiary = RecordRef(internalId='1', type='subsidiary')

类似地

credit_line = JournalEntryLine(account=get_record_by_type(client, 'account', '1'), credit=100)
debit_line = JournalEntryLine(account=get_record_by_type(client, 'account', '2'), debit=100)

可以更改为

credit_line = JournalEntryLine(account=RecordRef(internalId='1', type='account'), credit=100)
debit_line = JournalEntryLine(account=RecordRef(internalId='2', type='account'), debit=100)

推荐答案

我认为您的get_account()可能返回Account,但JournalEntryLine.account应该是RecordRef(实际上,对于get_subsidiary())

I think it's probably that your get_account() returns an Account but JournalEntryLine.account is supposed to be a RecordRef (actually, the same problem for get_subsidiary() as well)

这篇关于Netsuite名称空间冲突(core_2017_2.platform与Accounting_2017_2.lists)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆