Introduction
I want to calculate the price of a product with a subscription term, how to do it ?
Custom Script
export function onAfterCalculate(_quote, lines, _conn) {
lines.forEach(function (line) {
oneTimeSubscriptionPricing(line);
});
return Promise.resolve();
}
function oneTimeSubscriptionPricing(line) {
if (line.record['SBQQ__ProductFamily__c'] == "TestSub" && line.record['SBQQ__OriginalPrice__c'] != 0.0) {
var OriginalPrice = line.record['SBQQ__OriginalPrice__c'];
var SubscriptionTerm = line.record['SBQQ__SubscriptionTerm__c'];
var AdditionalDiscountAmount = line.record['SBQQ__AdditionalDiscountAmount__c'];
console.log(AdditionalDiscountAmount)
var Quantity = line.record['SBQQ__Quantity__c'];
var ListPrice = OriginalPrice / SubscriptionTerm;
var NetUnitPrice = ListPrice - AdditionalDiscountAmount;
var NetPrice = NetUnitPrice * SubscriptionTerm;
var NetTotal = NetPrice * Quantity;
line.record['SBQQ__ListPrice__c'] = ListPrice;
line.record['NetUnitPrice__c'] = NetUnitPrice;
line.record['SBQQ__NetPrice__c'] = NetPrice;
line.record['SBQQ__NetTotal__c'] = NetTotal;
} else {
console.log(" > Did not execute");
}
}
Custom field
Upgrade time
Maybe in the custom script, if you have a discount in percentage, it should be counted
Result
the link for the github: https://github.com/AourLegacy/AourFactory/tree/Subscription-calculation
Comments