On Feb 23, 2010, at 5:29 PM, Bob Morley wrote:

> Jacopo --
> 
> I like the utility method that you provided.  However, the implementation of
> these services is in minilang so calling it is a little bit of a pain.  

Yes, there are some examples of its usage in Minilang, like:

 <set field="isMarketingPkgAuto" value="${groovy: 
org.ofbiz.common.CommonWorkers.hasParentType(delegator, 'ProductType', 
'productTypeId', product.productTypeId, 'parentTypeId', 'MARKETING_PKG_AUTO')}" 
type="Boolean"/>

but I agree it is not very good; the other option is to use the 
<call-class-method element (that I like more).
But the utility method you have created is fine, especially if you have to use 
it a lot.
Or maybe its variant:

  public static boolean hasInvoiceParentType(GenericValue invoice, String 
parentTypeId)

Kind regards,

Jacopo

> As a
> result, I have done the following (which is consistent with other recursive
> checks in accounting related objects like payment types and account types).
> 
> Updated UtilAccountiing.java with the following:
> 
>    public static boolean isPurchaseInvoice(GenericValue invoice) throws
> GenericEntityException {
>        if (invoice == null) {
>            return false;
>        }
>        return CommonWorkers.hasParentType(invoice.getDelegator(),
> "InvoiceType", "invoiceTypeId", invoice.getString("invoiceTypeId"),
> "parentTypeId", "PURCHASE_INVOICE");
>    }
> 
> Then in my simple method I am doing the following ...
> 
>  <entity-one entity-name="Invoice" value-field="invoice"/>
>    <set type="Boolean" field="isPurchaseInvoice"
> value="${bsh:org.ofbiz.accounting.util.UtilAccounting.isPurchaseInvoice(invoice)}"
> />

Just a minor detail but I'd recommend using ${groovy: instead of ${bsh:



>    <if-compare field="isPurchaseInvoice" operator="equals" value="true"
> type="Boolean">
>      [logic ...]
> 
> 
> I have not executed this; but if we are in agreement I will go ahead and
> test it out and then create a patch for trunk.
> -- 

Reply via email to