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.
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:
- Deploy a new MYOB Acumatica instance with the U100 dataset. For details on deploying an instance, see To Deploy an MYOB Acumatica Instance.
- On the Enable/Disable Features (CS100000) form, make sure the Inventory and Order Management, Inventory, and Customer Discounts features are enabled.
- 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.
- 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:
- 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.
- 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.
- 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
- 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
- On the Items tab, add a row to the table, and in the Inventory ID column of the row, select APJAM32.
- On the Customers tab, add a row to the table, and in the Customer column, select GOODFOOD.
- On the form toolbar, click Save.
- 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
- On the Data Providers (SM206015) form, create a
data provider as follows:
- In the Name box, specify the name to be used for the data provider.
- In the Provider Type box, select CSV Provider.
- Save the data provider.
- Drag the CSV file that you have created onto the form.
- On the Parameters tab, set the value of the
Delimiter
parameter to ;. - On the Schema tab, fill the schema of the data
provider as follows:
- On the left pane toolbar, click Fill Schema Objects.
- In the Active column of the Source Objects table, select the check box in every row.
- On the right pane toolbar, click Fill Schema Fields.
- On the form toolbar, click Save.
- 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
- Click Save on the form toolbar.
- 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 - Click Save on the form toolbar.
- 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 theentity/OrderNbr
field.<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.