Apply Discounts to a Sales Order

If you are using the contract-based REST API to integrate MYOB Acumatica with an external system, this external system can apply the available discounts to a document (such as a sales order or AR invoice) in a single API call. For details about the configuration and application of discounts, see Configuring and Applying Customer Discounts.

A user scenario involving the need to apply discounts can be the following: Through an external system, a manager of the company needs to import sales orders or other documents to MYOB Acumatica and apply the available discounts to them. For details about the preparation of data for the import, creation, and running of import scenarios, see Preparing Data for Import and Export by Using Scenarios, Configuring Import Scenarios, and Data Import.

Note: Although discounts can be applied to other types of documents, in this example, sales orders will be imported.

Testing of the Request

Before you test the code below, you do the following to configure your client application and the MYOB Acumatica instance to be used:

  1. Deploy a new MYOB Acumatica instance with the U100 dataset. For details on deploying an instance, see To Deploy an MYOB Acumatica Instance.
  2. On the Enable/Disable Features (CS100000) form, make sure the Inventory and Order Management, Inventory, and Customer Discounts features are enabled.
  3. If you use Postman as the client application for testing, in the IntegrationDevelopmentGuide.postman_collection.json collection (which is located in the IntegrationDevelopment\Help folder of the Help-and-Training-Examples repository on GitHub), make sure the collection variables have the proper values.
  4. To sign in to the instance in the client application, use the tenant name (which you specified when you created the instance) and the HEADOFFICE branch.

To continue preparing the system, you need to create a discount code and a discount based on this discount code, and then import a sales order to which the discount is applicable and another sales order to which the discount is not applicable. You perform these tasks as follows:

  1. On the Discount Codes (AR209000) form, add a row, and create a discount code of the Line discount type that is applicable to Customer and Item. In the row, leave the four check boxes cleared for the discount code. It is especially important that the check box in the Manual column be cleared so that the system will calculate the discount automatically. Click Save on the form toolbar.
  2. On the Discounts (AR209500) form, select the discount code created in the previous instruction; then in the Sequence box, type the name and description for a new sequence, and click Save on the form toolbar.
  3. Specify the following settings in the Summary area:
    • Discount By: Percent
    • Break By: Amount
    • Active: Selected
    • Promotional: Selected
    • Effective Date: Today's date
    • Expiration Date: Any future date
  4. On the Discount Breakpoints tab, add a row to the table, and specify the following settings in the row:
    • Break Amount: 500
    • Discount Percent: 5
  5. On the Items tab, add a row to the table, and in the Inventory ID column of the row, select APJAM32.
  6. On the Customers tab, add a row to the table, and in the Customer column, select GOODFOOD.
  7. On the form toolbar, click Save.
  8. Create a CSV file with the following contents.
    ORDER NBR;ORDER TYPE;CUSTOMER;LOCATION;BRANCH;INVENTORY ID;QUANTITY
    SO0001;SO;GOODFOOD;MAIN;HEADOFFICE;APJAM32;10
    SO0002;SO;CANDYY;MAIN;HEADOFFICE;APJAM32;10
  9. On the Data Providers (SM206015) form, create a data provider as follows:
    1. In the Name box, specify the name to be used for the data provider.
    2. In the Provider Type box, select CSV Provider.
    3. Save the data provider.
    4. Drag the CSV file that you have created onto the form.
    5. On the Parameters tab, set the value of the Delimiter parameter to ;.
    6. On the Schema tab, fill the schema of the data provider as follows:
      1. On the left pane toolbar, click Fill Schema Objects.
      2. In the Active column of the Source Objects table, select the check box in every row.
      3. On the right pane toolbar, click Fill Schema Fields.
    7. On the form toolbar, click Save.
  10. On the Import Scenarios (SM206025) form, create an import scenario. In the Summary area, specify the following settings for it (other settings in the area should remain unchanged):
    • Screen Name: Sales Orders (the Screen ID is SO.30.10.00)
    • Provider: The data provider you created
    • Provider Object: The CSV file used as the source for the data provider
  11. Click Save on the form toolbar.
  12. For the created import scenario, on the Mapping tab, add rows with the settings shown in the following table (leaving the Active check box selected in each row).
    Target Object Field / Action Name Source Field / Value
    Order Summary Key: OrderType =[Document.OrderType]
    Order Summary Key: OrderNbr =[Document.OrderNbr]
    Order Summary Action: Cancel
    Order Summary Order Nbr. ORDER NBR
    Order Summary Action: Cancel
    Order Summary Order Type ORDER TYPE
    Order Summary Customer CUSTOMER
    Order Summary Location LOCATION
    Details <Line Number> =-1
    Details Branch BRANCH
    Details Inventory ID INVENTORY ID
    Details Quantity QUANTITY
    Order Summary Action: Save
  13. Click Save on the form toolbar.
  14. On the Import by Scenario (SM206036) form, select the import scenario you have created, click Prepare, make sure that the table on the Prepared Data tab contains the correct data of two sales orders, and click Import.

Request

You can use the following example of an HTTP request to apply available discounts to both imported sales orders. To affect both sales orders, you need to call the HTTP request twice, each time specifying the proper order number as the value of the entity/OrderNbr field.
Tip: In the request example below, <MYOB Acumatica instance URL> is the URL of the MYOB Acumatica instance (such as https://my.acumatica.com/MyInstance). You can omit the instance name in the URL (that is, you can use https://my.acumatica.com) if the instance is installed in the root of the website.
POST / HTTP/1.1
Host: [<MYOB Acumatica instance URL>]/entity/Default/23.200.001/SalesOrder/AutoRecalculateDiscounts
Accept: application/json
Content-Type: application/json

{
    "entity" :
    {
        "OrderType" : {"value" : "SO"},
        "OrderNbr" : {"value" : "000065"}
    },
    "parameters": { }
}

Check the imported sales orders. Notice that the discount you created affected the imported sales order whose OrderNbr is specified in the request, but the discount did not affect the other imported sales order.