Robert Gan created OFBIZ-5549:
---------------------------------

             Summary: 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


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.1.5#6160)

Reply via email to