Skip to content
Snippets Groups Projects
Commit 5ace02c0 authored by Sebastian Pongratz's avatar Sebastian Pongratz :ping_pong:
Browse files

Merge branch 'sales_1079916_FixOfferOrderUpdatePerformance' into '2021.1'

[Projekt: xRM-Sales][TicketNr.: 1079916][Angebot/Beleg - Posten: Aktualisieren...

See merge request xrm/basic!1059
parents 97ce69c5 49475b90
No related branches found
No related tags found
No related merge requests found
......@@ -9,31 +9,38 @@ import("Sql_lib");
var oid = vars.get("$field.OFFER_ID");
if(oid != "")
{
var discount = vars.exists("$param.Discount_param") ? vars.get("$param.Discount_param"): "";
var cols = ["NET", "VAT"];
var oiUtils = new OfferItemUtils(oid);
var vals = oiUtils.getNetAndVat();
var discountedVals = OfferItemUtils.getDiscountedNet(null, oid, discount);
let config = entities.createConfigForUpdatingRows()
config.entity("Offer_entity");
if(discountedVals){
config.fieldValues({
"NET": vals[0],
"VAT": vals[1],
"DISCOUNTED_NET": discountedVals[0],
"DISCOUNTED_VAT": discountedVals[1]
});
}
else{
config.fieldValues({
"NET": vals[0],
"VAT": vals[1]
});
if(!vars.get("$field.ITEMPOSITION").includes("."))//only the topItems affect the Offer price
{
var discount = vars.exists("$param.Discount_param") ? vars.get("$param.Discount_param"): "";
var cols = ["NET", "VAT"];
var oiUtils = new OfferItemUtils(oid);
var vals = oiUtils.getNetAndVat();
var discountedVals = OfferItemUtils.getDiscountedNet(null, oid, discount);
let config = entities.createConfigForUpdatingRows()
config.entity("Offer_entity");
if(discountedVals)
{
config.fieldValues({
"NET": vals[0],
"VAT": vals[1],
"DISCOUNTED_NET": discountedVals[0],
"DISCOUNTED_VAT": discountedVals[1]
});
}
else
{
config.fieldValues({
"NET": vals[0],
"VAT": vals[1]
});
}
config.uid(oid);
entities.updateRow(config);
}
config.uid(oid);
entities.updateRow(config);
//this process get's executed for every child of this offerItem since we use writeEntiy, so we use the param to make sure we don't execute it for the children
if(vars.getString("$param.IgnoreOnUpdateProcess_param") != "true")
{
......@@ -47,29 +54,30 @@ if(oid != "")
var loadConfig = entities.createConfigForLoadingRows().entity("Offeritem_entity").addParameter("OfferId_param", oid).fields(["OFFERITEMID", "ASSIGNEDTO", "PRODUCT_ID", "QUANTITY"])
var rows = entities.getRows(loadConfig);
var potentialAsignees = {};
var offerItemsToUpdate = {};
var statements = [];
var stop = false;
while(stop == false)//we have too loop forall the rows for each row that needs updating, since those are also pontially asignees
while(stop == false)//we have too loop for all the rows for each row that needs updating, since those are also pontially asignees
{
stop = true;
for(var offeritem in rows)//loop trough all the rows and build offerItemsToUpdate
{
if(!(rows[offeritem]["OFFERITEMID"] in offerItemsToUpdate) &&(rows[offeritem]["ASSIGNEDTO"] == offerItemId || rows[offeritem]["ASSIGNEDTO"] in potentialAsignees))
{
statements.push(
newWhere("OFFERITEM.OFFERITEMID", rows[offeritem]["OFFERITEMID"]).buildUpdateStatement({
"QUANTITY": parseInt(rows[offeritem]["QUANTITY"])*multiplier
})
);
offerItemsToUpdate[rows[offeritem]["OFFERITEMID"]] = parseInt(rows[offeritem]["QUANTITY"])*multiplier;
potentialAsignees[rows[offeritem]["OFFERITEMID"]] = "";
stop = false;
}
}
}
var updateConfig = entities.createConfigForUpdatingRows().entity("Offeritem_entity").addParameter("OfferId_param", oid).addParameter("IgnoreOnUpdateProcess_param", true);
for(var object_Id in offerItemsToUpdate)
{
entities.updateRow(updateConfig.fieldValues({"QUANTITY": offerItemsToUpdate[object_Id]}).uid(object_Id))
}
db.execute(statements);// no write entity -> performance reason
}
}
}
\ No newline at end of file
......@@ -8,32 +8,35 @@ import("Sql_lib");
var oid = vars.get("$local.rowdata")["SALESORDERITEM.SALESORDER_ID"];
if(oid != "")
{
var discount = vars.exists("$param.Discount_param") ? vars.get("$param.Discount_param"): "";
var oiUtils = new OrderItemUtils(oid);
var vals = oiUtils.getNetAndVat();
var discountedVals = OrderItemUtils.getDiscountedNet(null, oid, discount);
let config = entities.createConfigForUpdatingRows()
config.entity("Order_entity");
if(discountedVals){
config.fieldValues({
"NET": vals[0],
"VAT": vals[1],
"DISCOUNTED_NET": discountedVals[0],
"DISCOUNTED_VAT": discountedVals[1]
});
}
else
if(!vars.get("$field.ITEMPOSITION").includes("."))//only the topItems affect the Order price
{
config.fieldValues({
"NET": vals[0],
"VAT": vals[1]
});
}
config.uid(oid);
entities.updateRow(config);
var discount = vars.exists("$param.Discount_param") ? vars.get("$param.Discount_param"): "";
var oiUtils = new OrderItemUtils(oid);
var vals = oiUtils.getNetAndVat();
var discountedVals = OrderItemUtils.getDiscountedNet(null, oid, discount);
let config = entities.createConfigForUpdatingRows()
config.entity("Order_entity");
if(discountedVals)
{
config.fieldValues({
"NET": vals[0],
"VAT": vals[1],
"DISCOUNTED_NET": discountedVals[0],
"DISCOUNTED_VAT": discountedVals[1]
});
}
else
{
config.fieldValues({
"NET": vals[0],
"VAT": vals[1]
});
}
config.uid(oid);
entities.updateRow(config);
}
//this process get's executed for every child of this offerItem since we use writeEntiy, so we use the param to make sure we don't execute it for the children
if(vars.getString("$param.IgnoreOnUpdateProcess_param") != "true")
......@@ -51,6 +54,7 @@ if(oid != "")
var potentialAsignees = {};
var offerItemsToUpdate = {};
var statements = [];
var stop = false;
while(stop == false)//we have too loop forall the rows for each row that needs updating, since those are also pontially asignees
{
......@@ -59,18 +63,18 @@ if(oid != "")
{
if(!(rows[offeritem]["SALESORDERITEMID"] in offerItemsToUpdate) &&(rows[offeritem]["ASSIGNEDTO"] == offerItemId || rows[offeritem]["ASSIGNEDTO"] in potentialAsignees))
{
statements.push(
newWhere("OFFERITEM.OFFERITEMID", rows[offeritem]["OFFERITEMID"]).buildUpdateStatement({
"QUANTITY": parseInt(rows[offeritem]["QUANTITY"])*multiplier
})
);
offerItemsToUpdate[rows[offeritem]["SALESORDERITEMID"]] = parseInt(rows[offeritem]["QUANTITY"])*multiplier;
potentialAsignees[rows[offeritem]["SALESORDERITEMID"]] = "";
stop = false;
}
}
}
var updateConfig = entities.createConfigForUpdatingRows().entity("Orderitem_entity").addParameter("OrderId_param", oid).addParameter("IgnoreOnUpdateProcess_param", true);
for(var object_Id in offerItemsToUpdate)
{
entities.updateRow(updateConfig.fieldValues({"QUANTITY": offerItemsToUpdate[object_Id]}).uid(object_Id))
}
db.execute(statements);// no write entity -> performance reason
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment