The Accorto pricing engine is very powerful and can be extended (or replaced) by custom logic.

Examples are volume- or value-based pricing or custom price metrics.


As the first step, the price based on the logic of the Accorto Pricing engine is calculated and the information is then passed over to the custom apex class for adding bespoke logic.


/**
 * Resource Pricing implementation example
 */
global with sharing class ResourcePricing implements Callable {

    public Object call(String action, Map<String,Object> args) {
        if (action == 'getRate') {
            return getRate(
                    (Id) args.get('resourceId'),
                    (Date) args.get('invoiceDate'),
                    (Id) args.get('accountId'),
                    (Id) args.get('contractId'),
                    (Id) args.get('projectId'),
                    (Id) args.get('activityId'),
                    (String) args.get('isoCode'),
                    (Id) args.get('finAccountId'),
                    (Decimal) args.get('qty'), // hours
                    (Decimal) args.get('price'),
                    (Decimal) args.get('costs')
            );
        }
        return null;
    } // call

    /**
     * @return list with price|cost
     */
    public List<Decimal> getRate(Id resourceId, Date invoiceDate,
            Id accountId, Id contractId, Id projectId, Id activityId, String isoCode, Id finAccountId,
            Decimal qty, Decimal price, Decimal costs) {
        // add fixed amount to price/costs if there is an account
        if (accountId != null) {
            List<Decimal> rates = new List<Decimal>();
            rates.add(price == null ? 10 : price + 10);
            rates.add(costs == null ? 9 : costs + 9); // optional
            return rates;
        }
        return null;
    } // getRate

} // ResourcePricing


You can test the implementation via

Id resourceId = accorto.TestData.theResource.Id;
Date invoiceDate = Date.today();
Id accountId = accorto.TestData.theAccount.Id;
Id contractId = null;
Id projectId = null;
Id activityId = null;
String isoCode = null;
Id finAccountId = null;
Decimal qty = null; // hours

accorto__Resource_Price__c rp = accorto.Resource.getResourcePrice(
  resourceId, invoiceDate, accountId, contractId, projectId, activityId, isoCode, finAccountId);
System.assertEquals(10, rp.accorto__UnitPrice__c);
System.assertEquals(9, rp.accorto__Cost_h__c);