【发布时间】:2023-04-10 20:33:01
【问题描述】:
我正在使用 Acumatica 的基于合同的 API 从 ASP.net 应用程序创建销售订单。创建销售订单时,我需要更新销售订单上“运输设置”选项卡下的“运输条款”字段(见下文),但我找不到要在通过提供的 ASP.net 对象上使用的属性基于合约的 API。我将如何做到这一点?
这是我当前如何创建销售订单的代码:
using (DefaultSoapClient client = new DefaultSoapClient(binding, address))
{
//Sales order data
string customerID = "CUST1234;
string orderDescription = "Automated Order";
string customerOrder = "TEST";
var orderDetails = new List<SalesOrderDetail>();
foreach(var lineItem in order.line_items)
{
orderDetails.Add(new SalesOrderDetail {
InventoryID = new StringValue { Value = lineItem.sku },
Quantity = new DecimalValue { Value = lineItem.quantity },
UnitPrice = new DecimalValue { Value = Decimal.Parse(lineItem.price) }, //TODO this should only be done for MHR owned sites
UOM = new StringValue { Value = "EACH" },
});
}
//Specify the values of a new sales order
SalesOrder orderToBeCreated = new SalesOrder
{
OrderType = new StringValue { Value = "SO" },
CustomerID = new StringValue { Value = customerID },
Description = new StringValue { Value = orderDescription },
CustomerOrder = new StringValue { Value = customerOrder },
ExternalReference = new StringValue { Value = order.order_number.ToString() },
Details = orderDetails.ToArray<SalesOrderDetail>(),
ShippingAddressOverride = new BooleanValue { Value = true },
ShippingContactOverride = new BooleanValue { Value = true },
ShippingContact = new Contact()
{
DisplayName = new StringValue { Value = order.shipping_address.first_name + " " + order.shipping_address.last_name },
FirstName = new StringValue { Value = order.shipping_address.first_name },
LastName = new StringValue { Value = order.shipping_address.last_name },
Address = new Address()
{
AddressLine1 = new StringValue { Value = order.shipping_address.address_1 },
AddressLine2 = new StringValue { Value = order.shipping_address.address_2 },
City = new StringValue { Value = order.shipping_address.city },
State = new StringValue { Value = order.shipping_address.state },
Country = new StringValue { Value = order.shipping_address.country },
PostalCode = new StringValue { Value = order.shipping_address.postcode }
}
},
};
client.Login(_acumaticaUid, _acumaticaPwd, _acumaticaCompany, null, null);
//Create a sales order with the specified values
try
{
SalesOrder newOrder = (SalesOrder)await client.PutAsync(orderToBeCreated);
client.Logout();
return newOrder;
}
catch (Exception e)
{
//order addition to Acumatica failed, update the order status in Woo Commerce
client.Logout();
Console.WriteLine("Acumatica could not add specified entity: " + e);
return null;
}
}
更新: 根据 PatrickChen 的评论,我在 Acumatica“SalesOrderCustom”中创建了一个新的 Web 服务端点,其中我使用了所有默认字段,然后也将“ShippingTerms”添加到列表中。然后我将该 Web 服务导入到我的 .net 项目中(由于this 问题而有些头疼),并且能够使用该服务获取我想要添加运输条款的销售订单,并尝试更新它。代码执行正常,但是在 PUT 操作完成后,对象在 Acumatica 中没有更新,并且 ShippingTerms 属性返回为 NULL。我究竟做错了什么?代码如下:
public async Task<SalesOrderCustom> UpdateShippingTerms(string customerOrder, string originStore, string shippingSpeed)
{
var binding = CreateNewBinding(true, 655360000, 655360000);
var address = new EndpointAddress(ConfigurationManager.AppSettings["AcumaticaCustomUrl"]);
var soToBeFound = new SalesOrderCustom()
{
OrderType = new StringSearch { Value = "SO" },
CustomerOrder = new StringSearch { Value = customerOrder }
};
using (DefaultSoapClient client = new DefaultSoapClient(binding, address))
{
client.Login(_acumaticaUid, _acumaticaPwd, _acumaticaCompany, null, null);
try
{
var soToBeUpdated = (SalesOrderCustom) await client.GetAsync(soToBeFound);
soToBeUpdated.ShippingTerms = new StringValue { Value = "USPS 1 CLS" };
var updatedOrder = (SalesOrderCustom)await client.PutAsync(soToBeUpdated);
//ShippingTerms is still NULL on returned object even after updating the object!!! WHY???
client.Logout();
return updatedOrder;
}
catch (Exception e)
{
client.Logout();
Console.WriteLine("Acumatica could not find specified entity: " + e);
return null;
}
}
}
【问题讨论】:
-
您使用的是默认端点吗?我必须创建一个新的来填充运输条款。
-
@PatrickChen 是的,我使用的是默认端点。您是如何创建新的?
-
@PatrickChen,我创建了一个新端点。这似乎是版本低于版本 6(我使用的是 5.30)的解决方案。我发现在版本 6 之后,您可以简单地扩展端点。如果你想发表你的答案,我会接受它
-
很高兴它有帮助!
标签: acumatica