【问题标题】:Setting the orderLine property on an item when updating an invoice更新发票时设置项目的 orderLine 属性
【发布时间】:2015-12-15 05:45:02
【问题描述】:

我的问题是,在创建发票后,我永远无法获取新的行项目来引用其对应的销售订单行项目。

我一直在通过 SuiteTalk 生成发票。当我最初创建发票时,我清空 lineItemList 并重新添加我需要的项目。我确保 orderLine 属性与销售订单行项目行号匹配。这很好用。

但是,当我尝试使用其他行项目更新发票时,我永远无法让新项目保留其 orderLine 属性。 orderLine 属性用于销售订单上的“发票”列。

为了使引用正确,我需要删除发票并使用我需要的所有行项目重新创建它。

有谁知道我想要做的事情是否可行?


在此示例中,我使用此 CreateInvoice 函数从头开始创建发票并将其添加到 NetSuite。一切正常。

public void CreateInvoice(SalesOrder salesOrder) {
    Invoice brandNewInvoice = new Invoice() {
        createdFrom = new RecordRef() {
            internalId = salesOrder.internalId,
        },
        entity = salesOrder.entity,
        tranDate = endDate,
        tranDateSpecified = true,
        startDate = startDate,
        startDateSpecified = true,
        endDate = endDate,
        endDateSpecified = true,
        itemList = new InvoiceItemList(),
    };


    invoice.itemList.item = GetInvoiceItemList(salesOrder); //see the function shown further down

    netSuiteService.add(brandNewInvoice);
}

在此示例中,发票已创建,因此我从 NetSuite 获取它,然后将现有 itemList 替换为新的。更新后,发票现在将没有任何行项目的 orderLine 属性。发票也会丢失其“创建自”字段,因为没有设置 orderLine 属性的行项目。

public void UpdateInvoice(SalesOrder salesOrder, String invoiceInternalId) {
    Invoice invoice = GetNetSuiteInvoice(invoiceInternalId);        

    invoice.itemList.item = GetInvoiceItemList(salesOrder); //see the function shown further down


    netSuiteService.update(invoice);
}

这是用于创建 itemList 的函数:

public InvoiceItem[] GetInvoiceItemList(SalesOrder salesOrder) {
    InvoiceItem[] invoiceItemList = new InvoiceItem[salesOrder.itemList.item.Length];

    for (int i = 0; i < salesOrder.itemList.item.Length; i++) {
        SalesOrderItem soItem = salesOrder.itemList.item[i];
        double quantity = 1;

        invoiceItemList[i] = new InvoiceItem() {
            item = new RecordRef() {
                internalId = soItem.item.internalId,
                name = soItem.item.name,
            },
            amount = quantity * Double.Parse(soItem.rate),
            amountSpecified = true,
            quantity = quantity,
            quantitySpecified = true,
            price = new RecordRef() {
                internalId = soItem.price.internalId,
                name = soItem.price.name,
            },
            rate = soItem.rate,
            orderLine = soItem.line, //this will establish the link between the invoice and the sales order
            orderLineSpecified = true,
            taxRate1 = soItem.taxRate1,
            taxRate1Specified = true,
        };
    }

    return invoiceItemList;
}

【问题讨论】:

    标签: c# web-services netsuite


    【解决方案1】:

    其实你要找的是初始化操作。您需要使用初始化,以便 Netsuite 正确填写 created from 和 orderline 道具。从 NS 帮助中有一个创建现金销售的 C# 示例:

    私人无效初始化() { this.login(true);

            InitializeRef ref1 = new InitializeRef();
            ref1.type = InitializeRefType.salesOrder;
    
                    //internal id of the sales order to be converted to cash sale
            ref1.internalId = "792"; 
            ref1.typeSpecified = true;
    
            InitializeRecord rec = new InitializeRecord();
            rec.type = InitializeType.cashSale;
            rec.reference = ref1;
    
            ReadResponse read1 = _service.initialize(rec);
                }
    

    【讨论】:

    • 在我的示例中,我试图证明我可以成功地从头开始创建发票,但更新不成功,即使我基本上使用相同的代码来构建它们。
    • 在我的情况下,发票已经创建,我想用一些额外的项目来更新它。示例:销售订单有 ItemA、ItemB 和 ItemC。发票仅使用 ItemA 创建。此时,一切看起来都正确; SO 显示它已为 itemA 开具发票。现在,我更新了发票并添加了 ItemB,但这不起作用。似乎更新操作丢弃了 orderLine;我希望有办法防止这种情况发生。
    • 你不能这样做。如果您想合并发票,通常需要根据您的要求将其作为自定义记录/自定义表单。
    • 正确,我会使用初始化来创建发票。
    • 谢谢。 (我希望这不是答案......现在回到绘图板)
    【解决方案2】:

    这是正常的,当将一个事务转换为另一个事务时(例如,SO 到 Inv,PO 到 IR)。转换时,源交易中的大部分信息都将被继承。就像您正在做的事情是从销售订单创建发票(基于您下面的代码)。

            createdFrom = new RecordRef() {
            internalId = salesOrder.internalId,
        },
    

    您不需要从销售订单中获取行项目信息并将其放入发票中,因为一旦您从销售订单中创建它就会预先填充(除非您需要更改行项目的值柱子)。

    转换记录的一种行为(在您的情况下为发票),如果您从发票中删除一个行项目,您将失去到销售订单(orderLine)的链接,如果您删除所有行项目,您将完全失去两个事务之间的链接(createdfrom)。这就是你正在经历的。 orderLine/createdFrom 是系统填充的字段,看起来您正在填充它,但实际上不是。

    【讨论】:

    • orderLine 绝对是我可以在初始添加操作中修改的东西,但似乎我无法在更新操作中修改它。
    猜你喜欢
    • 2012-02-24
    • 2023-03-12
    • 1970-01-01
    • 2017-10-01
    • 2011-01-01
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 2012-08-26
    相关资源
    最近更新 更多