Loading
Prepare for Email to Become the Default Login ExperienceRead More
Get Started with Communications, Media, and Energy & Utilities (CME)...
DefaultApprovalStatusImplementation

DefaultApprovalStatusImplementation

If the Cart Level Discount Approval Required CPQ configuration settingCPQ Configuration Settings Reference is set to true, new or edited discount records have an ApprovalStatus value of Not Submitted. Discount records must be submitted to the approval process.

This interface only sets the value of the ApprovalStatus field. It does not call the update method. The update method must be called by the method that invokes this interface.

For more information, see Approving DiscountsApprove Discounts in Industries CPQ.

Interface

ApprovalStatusInterfaceApprovalStatusInterface

Sample Code

global class CpqCustomDiscountApprovalService implements VlocityOpenInterface {
 private String NSP = 'vlocity_cmt__';
 private String customSettingName = 'Cart Level Discount Approval Required';
 private static String DISCOUNT_APPROVAL_SETTING = 'Cart Level Discount Approval Required';
 private Boolean isDiscountApprovalRequired = false;
 public CpqCustomDiscountApprovalService() {}
 global Boolean invokeMethod(String methodName,
  Map <String, Object> input,
  Map <String, Object> output,
  Map <String, Object> options) {
  try {
   if (methodName == 'generateApprovalStatus') {
    generateApprovalStatus(input, output, options);
   }
   return true;
  } catch (Exception ex) {
   System.debug(LoggingLevel.ERROR, ex);
   System.debug(LoggingLevel.ERROR, ex.getStackTraceString());
   output.put('errors', true);
   output.put('errorResult', ex.getMessage());
   return false;
  }
 }
 public void generateApprovalStatus(Map <String, Object> input, Map <String, Object> output,
  Map <String, Object> options) {
  List <SObject> sObjList = (List <SObject> ) input.get('discounts');
  List <SObject> settings = [SELECT Id, Name, vlocity_cmt__SetupValue__c from
   vlocity_cmt__CpqConfigurationSetup__c where Name =: DISCOUNT_APPROVAL_SETTING LIMIT 1
  ];
  //Get the Value for Custom Setting
  String setupValue = (String) settings[0].get(NSP + 'SetupValue__c');
  if (setupValue.equalsIgnoreCase('True')) {
   isDiscountApprovalRequired = true;
  }
  //Update Approval Status for each discountItem
  for (SObject oneObj: sObjList) {
   String discountType = (String) oneObj.get(NSP + 'DiscountType__c');
   if (discountType.equals('Contract')) {
    continue;
   }
   if (isDiscountApprovalRequired) {
    oneObj.put(NSP + 'ApprovalStatus__c', 'Not Submitted');
   } else {
    oneObj.put(NSP + 'ApprovalStatus__c', 'Approved');
   }
  }
 }
}

To implement the corresponding test class, use the following sample code from CpqCustomDiscountApprovalServiceTest.cls:

@isTest
public class CpqCustomDiscountApprovalServiceTest {

 public static vlocity_cmt__QuoteDiscount__c notSubmittedDiscount;
 public static vlocity_cmt__QuoteDiscount__c approvedDiscount;
 public static vlocity_cmt__QuoteDiscount__c pendingDiscount;
 private static String NSP = 'vlocity_cmt__';
 public static testMethod void test() {

  Opportunity oppty = new Opportunity(Name = 'test Opp', StageName = 'Draft', CloseDate = Date.Today() + 365);
  insert oppty;

  vlocity_cmt__CpqConfigurationSetup__c configSetup = new vlocity_cmt__CpqConfigurationSetup__c(Name = 'Cart Level Discount Approval Required', vlocity_cmt__SetupValue__c = 'False');
  insert configSetup;

  Quote testQuote = new Quote(
   Name = 'test Quote',
   OpportunityId = oppty.Id,
   Pricebook2Id = Test.getStandardPricebookId());
  insert testQuote;

  List <vlocity_cmt__InterfaceImplementation__c> discountInterfaceImplList = new List <vlocity_cmt__InterfaceImplementation__c> ();
  vlocity_cmt__InterfaceImplementation__c discountApprovalInterface = new vlocity_cmt__InterfaceImplementation__c(
   Name = 'DiscountApproval',
   vlocity_cmt__ImplementationClassName__c = 'CpqCustomDiscountApprovalService');
  discountInterfaceImplList.add(discountApprovalInterface);
  insert discountInterfaceImplList;
  List <vlocity_cmt__CustomClassImplementation__c> customClassImplList = new List <vlocity_cmt__CustomClassImplementation__c> ();
  customClassImplList.add(new vlocity_cmt__CustomClassImplementation__c(Name = 'DiscountApproval', vlocity_cmt__ClassName__c = 'CpqCustomDiscountApprovalService'));
  insert customClassImplList;

  List <vlocity_cmt__QuoteDiscount__c> discountList = new List <QuoteDiscount__c> ();
  notSubmittedDiscount = new vlocity_cmt__QuoteDiscount__c(
   vlocity_cmt__ApprovalStatus__c = 'Not Submitted',
   Name = 'Contract Discount',
   vlocity_cmt__DiscountType__c = 'Contract',
   vlocity_cmt__QuoteId__c = testQuote.Id);
  discountList.add(notSubmittedDiscount);

  approvedDiscount = new vlocity_cmt__QuoteDiscount__c(
   vlocity_cmt__ApprovalStatus__c = 'Not Submitted',
   Name = 'Account Discount',
   vlocity_cmt__DiscountType__c = 'Account',
   vlocity_cmt__QuoteId__c = testQuote.Id);
  discountList.add(approvedDiscount);
  pendingDiscount = new vlocity_cmt__QuoteDiscount__c(
   vlocity_cmt__ApprovalStatus__c = 'Pending',
   Name = 'Order Discount',
   vlocity_cmt__DiscountType__c = 'Order',
   vlocity_cmt__QuoteId__c = testQuote.Id);
  discountList.add(pendingDiscount);

  insert discountList;

  Map <String, Object> inputMap = new Map <String, Object> {
   'discounts' => discountList
  };
  Map <String, Object> outputMap = new Map <String, Object> ();
  Map <String, Object> optionsMap = new Map <String, Object> ();
  InvokeService.invokeOpenImplementation('DiscountApproval', 'generateApprovalStatus', inputMap, outputMap, optionsMap);
 }
}

Related Implementations

None

 
Loading
Salesforce Help | Article