Introduction
I want from my product a specific discount like a linear function, how to do it?
Custom field
Discount parameter custom field
Custom script
export function onBeforeCalculate(quoteModel, quoteLineModels, conn) {
return applyDiscountParameter(quoteModel, quoteLineModels, conn);
}
function applyDiscountParameter(_quoteModel, quoteLineModels, conn) {
let promises = [];
if (quoteLineModels.length > 0) {
quoteLineModels.forEach(function (l) {
if (l.record["SBQQ__Product__c"]) {
let ProductId = l.record["SBQQ__Product__c"];
let queryPromise = conn.query("SELECT Id, Parameter1__c,Parameter2__c FROM DiscountParameter__c where Product__c = '" + ProductId + "'")
.then(function (results) {
if (results.totalSize > 1) {
console.error("more than one discount parameter for this product")
} else if (results.totalSize === 1) {
// Apply discount if there is exactly one discount parameter
let discountParams = results.records[0];
l.record["SBQQ__AdditionalDiscountAmount__c"] = discountParams.Parameter1__c * l.record["SBQQ__ListPrice__c"] - discountParams.Parameter2__c;
}
});
promises.push(queryPromise);
}
});
}
return Promise.all(promises);
}
Conclusion
If you want another function or add other parameters, you can add in the custom script what you need
the link for the github : https://github.com/AourLegacy/AourFactory/tree/Discount-parameters
Commentaires