The REST API allows you to recalculate the purchase and sales price of a bill of materials using actions prepocti-nakupni-cenu and prepocti-prodejni-cenu.
Recalculating bill of materials prices is used to update the product price when the prices of the materials that make up the product have changed. These are services that work the same way as the buttons in the application.
During the actual production process (i.e. when receiving the finished product into stock), however, the price of the received product is calculated automatically based on the actual cost of the consumed materials. It will therefore correspond to the material price regardless of the price specified in the bill of materials.
Note: The actions only sum prices from a single level of the bill of materials. Therefore, if a bill of materials consists of other bills of materials, those sub-level bills of materials must be recalculated first.
You can learn more about bills of materials in the documentation.
To perform the action prepocti-nakupni-cenu and prepocti-prodejni-cenu, you need to know the specific ID of the bill of materials, or you can use filtering to recalculate bills of materials at the same level.
Usage examples
The request is sent using the POST method to the URL:
POST https://demo.flexibee.eu/c/demo/kusovnik.xml (.json)
<winstrom version="1.0">
<kusovnik id="123" action="prepocti-nakupni-cenu" />
</winstrom>
Similarly, the request can be sent in JSON format using the bill of materials ID:
{
"winstrom": {
"kusovnik": {
"id": "123",
"@action": "prepocti-nakupni-cenu"
}
}
}
The ABRA Flexi response is then an update of the selected record:
{
"winstrom": {
"@version": "1.0",
"success": "true",
"stats": {
"created": "0",
"updated": "1",
"deleted": "0",
"skipped": "0",
"failed": "0"
},
"results": [
{
"id": "123",
"request-id": "123",
"ref": "/c/demo/kusovnik/123.json"
}
]
}
}
Filtering levels for recalculation
The bill of materials level determines which level of the bill of materials you intend to recalculate.
Note: This recalculates the prices of all bills of materials, not only those matching the filter — meaning that if it is not restricted to a specific bill of materials, all bills of materials at the given level will have their prices recalculated.
The action can be triggered in batch mode over a group of bills of materials using a filter:
<winstrom version="1.0">
<kusovnik filter="hladina eq 1" action="prepocti-nakupni-cenu" />
</winstrom>
Similarly, the request can be sent in JSON format using filtering:
{
"winstrom": {
"kusovnik": {
"@filter": "hladina eq 1",
"@action": "prepocti-nakupni-cenu"
}
}
}
Failed requests
1. The specified/filtered object (bill of materials) does not exist
If the object cannot be found or does not exist, the API response is:
"message": "Nebyl nalezen zaznam s id = 666: cz.winstrom.vo.cen.Kusovnik#1222 [1222]",
2. The action is incorrectly written
If you are calling the wrong action (typo or error in the name):
"message": "Atribut 'action' obsahuje špatnou hodnotu. Pro daný objekt smí obsahovat jen: [delete, prepocti-nakupni-cenu, prepocti-prodejni-cenu] [1]"
3. Incorrectly written filter
If the filter does not conform to the defined filtering rules, the response indicates the approximate position of the error in the filter:
<error>Špatný formát WQL dotazu, problém na pozici 11 poblíž textu 'now()'
org.antlr.v4.runtime.misc.ParseCancellationException
org.antlr.v4.runtime.NoViableAltException</error>
4. The level does not exist
If you attempt to recalculate a non-existent level, an empty result is returned
"results": []

