You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by "Jacopo Cappellato (JIRA)" <ji...@apache.org> on 2014/03/28 16:20:21 UTC

[jira] [Commented] (OFBIZ-5549) getBillingAccountBalance wrong viewEntity OrderPurchasePaymentSummary

    [ https://issues.apache.org/jira/browse/OFBIZ-5549?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13950874#comment-13950874 ] 

Jacopo Cappellato commented on OFBIZ-5549:
------------------------------------------

Robert,

thank you for your report; I am pretty sure you have found a bug; I didn't look deeply the code, however I don't think that the fix you are proposing is the best solution; in fact the view entity OrderPurchasePaymentSummary is used in other parts of the system, and the change you propose may break them.
As a side note, while I was exploring the code, I have noticed that there were two (mostly identical) methods to get the billing account balance: one in the accounting application (the one that you have modified) and one in the order application; in rev. 1582774 I have moved the code from accounting to order and removed the duplicated code, at least now we have just one method to fix.
Unfortunately I don't have much time now but if you could provide a simple use case of the problem you have reported, possibly using the OFBiz demo data, then it will be easier for us to recreate and try to help to fix it.
Thanks

> getBillingAccountBalance wrong viewEntity OrderPurchasePaymentSummary
> ---------------------------------------------------------------------
>
>                 Key: OFBIZ-5549
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-5549
>             Project: OFBiz
>          Issue Type: Bug
>          Components: accounting
>            Reporter: Robert Gan
>              Labels: BillingAccountWorker, OrderPurchasePaymentSummary, getBillingAccountBalance
>
> To get the billing account balance the Method getBillingAccountBalance(GenericValue billingAccount) Method in Class BillingAccountWorker is called. To calculate the balance the Method checks the viewentity "OrderPurchasePaymentSummary". 
> When I have an Invoice created and the customer makes a payment smaller than the invoice amount. In this case there is a split payment created and the Entity OrderPaymentPreference gets a second entry for that Order (normally only one is there). The above named view entity collects the orderHeader and the OrderPaymentPreference entity (and other irrelevant ones). The viewentity entry "grandTotal" from orderHeader is 2 times therebecause of the 2 OrderPaymentPreference entries. Here is the bug: The creation of the viewentity (in entityModel_view.xml) is set for grandTotal with:
> <alias entity-alias="OH" name="grandTotal" function="sum"/>
> The sum function sums the grandTotal entries. But because now we have 2 OrderPaymentPreference entries, we sum the grandTotal field 2 times, which is wrong and results in a wrong balance.
> I am not sure for what the viewEntity is also used, but I fixed it with removing the sum function, so that it looks like that:
> <alias entity-alias="OH" name="grandTotal" group-by="true"/>
> Is this way safe? I think because I dont know any case where we have more than one orderHeader for an order. Am I wrong?
> the complete view entity (corrected) is here:
> <view-entity entity-name="OrderPurchasePaymentSummary"
>             package-name="org.ofbiz.order.order"
>             never-cache="true"
>             title="Order Purchase Payment Summary View Entity">
>       <member-entity entity-alias="OH" entity-name="OrderHeader"/>
>       <member-entity entity-alias="OPP" entity-name="OrderPaymentPreference"/>
>       <member-entity entity-alias="PMT" entity-name="PaymentMethodType"/>
>       <!-- only the fields desired should be included in fields-to-select, and can otherwise be used as select critera (or both too) -->
>       <alias entity-alias="OH" name="webSiteId" group-by="true"/>
>       <alias entity-alias="OH" name="productStoreId" group-by="true"/>
>       <alias entity-alias="OH" name="originFacilityId" group-by="true"/>
>       <alias entity-alias="OH" name="terminalId" group-by="true"/>
>       <alias entity-alias="OH" name="statusId" group-by="true"/>
>       <alias entity-alias="OPP" name="paymentMethodTypeId" group-by="true"/>
>       <alias entity-alias="PMT" name="description" group-by="true"/>
>       <alias entity-alias="OPP" name="maxAmount" function="sum"/>
>       <alias entity-alias="OH" name="orderId" group-by="true"/>
>       <alias entity-alias="OH" name="orderTypeId" group-by="true"/>
>        <alias entity-alias="OH" name="grandTotal" group-by="true"/>
>       <alias entity-alias="OH" name="orderDate" group-by="true"/>
>       <alias entity-alias="OH" name="billingAccountId" group-by="true"/>
>       <alias entity-alias="OPP" name="preferenceStatusId" field="statusId" group-by="true"/>
>       <view-link entity-alias="OH" rel-entity-alias="OPP">
>         <key-map field-name="orderId"/>
>       </view-link>
>       <view-link entity-alias="OPP" rel-entity-alias="PMT">
>         <key-map field-name="paymentMethodTypeId"/>
>       </view-link>
>     </view-entity>



--
This message was sent by Atlassian JIRA
(v6.2#6252)