+1

Create payables from receivables macro

Ádám Csillag 10 months ago • updated 8 months ago 2

Hi,

I'm trying to create a macro that creates a payable for every receivable in the project. The problem is that $tmSavingsFactory.createTMSavings() is always returning null. Is this the right approach? Thanks in advance.


#set($service = $utils.getService("com.radzisz.xtrf.service.ActivityService"))
#set($service2 = $utils.getService("com.radzisz.xtrf.service.TMSavingsService"))
#set($catTool = $service2.getAvailableCatTools()[0].catTool)
#set($tmSavingsFactory = $utils.createInstance("com.radzisz.xtrf.service.chargeTmSavings.TmSavingsForChargeFactory"))

#foreach( $project in $utils.unwrap(${list}) )
    #foreach($task in $project.tasks)
        #set($tf = $task.projectFinance)
        #foreach($r in $tf.catReceivables)
            #foreach($activity in $task.activities)
                #set($rates = $activity.providerPriceProfile.getTmRates($catTool))
                #set($tmSavings = $r.TmSavings)
                #set($tmSavingPayable = $tmSavingsFactory.createTMSavings($tmSavings, $rates))
                #set($payable = $service.createActivityCatPayable($activity))
                $payable.updateTmSavings($tmSavingPayable)
                $activity.addCATPayable($payable)
            #end
        #end
    #end
#end

Hi Adam,

Please keep in mind that since XTRF7 using Groovy (www.groovy-lang.org) is both available and recommended way to write your macros. If it's not available on your XTRF instance, please contact our Helpdesk so they can unlock the feature for you.

You can just create TmSavings using its constructor and then just add it to your payable via UpdateTmSavings. 

Kind regards,

Bartosz

Hi Bartosz,

We have Groovy on our instance, are planning to switch to it, but it's currently more convenient to reuse our legacy Velocity code.

The problem is, the constructor of TmSavings is really not straightforward because of the Map of TMSavingItem objects.

To create the map, I need to create TMSavingItem objects something like this:

#set($param = ["eu.xtrf.cat.MatchType","com.radzisz.xtrf.model.rate.values.QuantityValue","com.radzisz.xtrf.model.rate.values.RateValue","com.radzisz.xtrf.model.rate.values.RateValue"])
#set($savingsItem = $utils.createInstanceWithSpecificParamTypeNames("com.radzisz.xtrf.model.charge.tmsaving.TMSavingItem", $param, $item.matchType, $item.quantity, $item.fixedRate, $item.percentageRate))

But this doesn't work, just returns null objects.