简体   繁体   中英

Associate invoice to a Sales Order

I am not able to set "Created From" on Invoice to reference a Sales Order record through the SOAP web service. I have tried setting this field directly and also through Initialize API (initializing a invoice record using the sales order and then copying the CreatedFrom field from the initialized invoice to the invoice being created).

I don't get any errors yet the Created From field doesn't get set on the created invoice record.

The code I am trying looks something like this:

// initialize invoice from sales order
var initializeRecord = new InitializeRecord()
            {
                type = InitializeType.invoice,
                reference = new InitializeRef() { internalId = "sales-order-internal-id", type = InitializeRefType.salesOrder, typeSpecified = true }
            };            
            var result = Utility.Do(async () => await connector.NetSuiteClient.initializeAsync(initializeRecord));
SuiteTalk.Invoice initializedInvoice = result.record;

// create a invoice and copy over the "createdFrom" field
var invoice = new SuiteTalk.Invoice();
invoice.createdFrom = initializedInvoice.createdFrom;

/* set other fields on the invoice and add some line items
....
...
..
*/

// finally create the invoice
var result = Utility.Do(async () => await connector.NetSuiteClient.addAsync(invoice));

How I can associate this invoice to a sales order while creating it?

What you will have to do -- as painful as it is -- is to use the transformed record provided to you by netsuite from the initializeRecord call, and then modify it. It is a pain because there are several fields that you will have to unset as you fill in the record.

The issue is that there are createdFrom associations on both the header level, and the line level, that need to be filled in for the sales order to invoice association to take.

here are the list of line fields that I had to unset in the invoice:

line-level:

  • quantityRemaining
  • quantityAvailable
  • quantityFulfilled
  • quantityOrdered
  • quantityOnHand
  • costEstimate
  • taxRate1

here are the header-level fields:

  • subTotal
  • total
  • totalCostEstimate
  • estGrossProfit
  • estGrossProfitPercent
  • discountTotal
  • giftCertApplied
  • shippingTax1Rate

Thank you 2ps . In my case this code was enough

Invoice invoice = (Invoice)initializeResponse.record;
                    invoice.totalCostEstimateSpecified = false;
                    invoice.estGrossProfitPercentSpecified = false;
                    invoice.discountTotalSpecified = false;
                    invoice.totalSpecified = false;

                    foreach (var item in invoice.itemList?.item)
                    {
                        item.quantityRemainingSpecified = false;
                        item.costEstimateSpecified = false;
                    }

                    var writeResponse = svc2.add(invoice);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM