首页 文章

Acumatica更改销售订单创建的装运条款

提问于
浏览
0

我正在使用Acumatica基于 Contract 的API从ASP.net应用程序创建销售订单 . 我需要在创建它时更新销售订单上“运输设置”选项卡下的“运输条款”字段(见下文),但我找不到要在通过销售订单提供的ASP.net对象上使用的属性 . 基于 Contract 的API . 我怎么做到这一点?

enter image description here

以下是我目前创建销售订单的代码:

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;
    }

}

UPDATE: 根据PatrickChen的评论,我在Acumatica "SalesOrderCustom"中创建了一个新的Web服务 endpoints ,我在其中使用了所有默认字段,然后将"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;
        }
    }
}

2 回答

  • -1

    启动Acumatica 6,可以更新任何未包含在 Default endpoints 中的字段 . 此功能仅适用于实现第二版系统 Contract 的 endpoints :

    enter image description here

    以下示例显示如何通过使用 CustomFields 集合来更改 Shipping Terms 以及 Default 基于 Contract 的 endpoints 的销售订单:

    using (var client = new DefaultSoapClient())
    {
        client.Login("admin", "123", null, null, null);
        try
        {
            var order = new SalesOrder()
            {
                OrderType = new StringSearch { Value = "SO" },
                OrderNbr = new StringSearch { Value = "SO003729" }
            };
            order = client.Get(order) as SalesOrder;
            order.CustomFields = new CustomField[]
            {
                new CustomStringField
                {
                    fieldName = "ShipTermsID",
                    viewName = "CurrentDocument",
                    Value = new StringValue { Value = "FLATRATE2" }
                }
            };
            client.Put(order);
        }
        finally
        {
            client.Logout();
        }
    }
    

    在全新的Acumatica ERP 6.1实例上使用扩展的 Default 基于 Contract 的 endpoints 更新销售订单 Shipping Terms 时,在我的结束时也没有发现任何问题:

    using (var client = new DefaultSoapClient())
    {
        client.Login("admin", "123", null, null, null);
        try
        {
            var order = new SalesOrder()
            {
                OrderType = new StringSearch { Value = "SO" },
                OrderNbr = new StringSearch { Value = "SO003729" }
            };
            order = client.Get(order) as SalesOrder;
            order.ShippingTerms = new StringValue { Value = "FLATRATE1" };
            client.Put(order);
        }
        finally
        {
            client.Logout();
        }
    }
    

    作为参考,添加用于更新 SalesOrder 实体中的 Shipping Terms 的扩展 Default endpoints 的屏幕截图:

    enter image description here

  • 2

    我在创建新的6.0 endpoints 时能够添加运输条款 . Acumatica附带的默认 endpoints 不可扩展 .

相关问题