Dev - Rounding issue in Invoice adjustment

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Dev - Rounding issue in Invoice adjustment

Jacopo Cappellato
Hi all,

I think there is a problem in the invoice adjustments routine
(InvoiceServices.createInvoiceForOrder service, line 420).
The problem is caused by the following instructions (lines 423-424):

BigDecimal amount =
adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"),
decimals, rounding);
amount = amount.multiply(invoiceItem.getBigDecimal("quantity"));

In the first line the OrderAdjustment.amount is divided by the
OrderItem.quantity to get the "unit adjustment amount".
In the second line the "unit adjustment amount" is multiplied by
InvoiceItem.quantity to get the total adjustment amount for the invoice
item.

The problem is that, in the first line, the division is rounded to two
decimals (the default decimals for invoices) and this can cause
approximations problems.

For example:

OrderItem.quantity = 5
OrderAdjustment.amount = 0.473
InvoiceItem.quantity = 5

After the first operation we get:

OrderAdjustment.amount / OrderItem.quantity = 0.47 / 5 = 0.094 = 0.09

After the second operation we get:

amount * InvoiceItem.quantity = 0.09 * 5 = 0.45

That is different from the adjustment in the order (0.45 != 0.47)

I propose to remove the rounding operation from the first line.

What do you think?

Jacopo
 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - Rounding issue in Invoice adjustment

Jacopo Cappellato
Hi again,

please find attached a proposed patch. I'm still not so comfortable with
BigDecimals, so your review and comments are welcome.

Jacopo



Jacopo Cappellato wrote:

> Hi all,
>
> I think there is a problem in the invoice adjustments routine
> (InvoiceServices.createInvoiceForOrder service, line 420).
> The problem is caused by the following instructions (lines 423-424):
>
> BigDecimal amount =
> adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"),
> decimals, rounding);
> amount = amount.multiply(invoiceItem.getBigDecimal("quantity"));
>
> In the first line the OrderAdjustment.amount is divided by the
> OrderItem.quantity to get the "unit adjustment amount".
> In the second line the "unit adjustment amount" is multiplied by
> InvoiceItem.quantity to get the total adjustment amount for the invoice
> item.
>
> The problem is that, in the first line, the division is rounded to two
> decimals (the default decimals for invoices) and this can cause
> approximations problems.
>
> For example:
>
> OrderItem.quantity = 5
> OrderAdjustment.amount = 0.473
> InvoiceItem.quantity = 5
>
> After the first operation we get:
>
> OrderAdjustment.amount / OrderItem.quantity = 0.47 / 5 = 0.094 = 0.09
>
> After the second operation we get:
>
> amount * InvoiceItem.quantity = 0.09 * 5 = 0.45
>
> That is different from the adjustment in the order (0.45 != 0.47)
>
> I propose to remove the rounding operation from the first line.
>
> What do you think?
>
> Jacopo
>  
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.ofbiz.org/mailman/listinfo/dev
>

Index: applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
===================================================================
--- applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java (revision 6918)
+++ applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java (working copy)
@@ -420,8 +420,9 @@
                         GenericValue adj = (GenericValue) itemAdjIter.next();
                         if (adj.get("amount") != null) {
                             // pro-rate the amount
-                            BigDecimal amount = adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"), decimals, rounding);
+                            BigDecimal amount = adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"), 100, rounding);
                             amount = amount.multiply(invoiceItem.getBigDecimal("quantity"));
+                            amount.setScale(decimals, rounding);
                             GenericValue adjInvItem = delegator.makeValue("InvoiceItem", UtilMisc.toMap("invoiceId", invoiceId, "invoiceItemSeqId", invoiceItemSeqId));
                             adjInvItem.set("invoiceItemTypeId", getInvoiceItemType(delegator, adj.getString("orderAdjustmentTypeId"), invoiceType, "INVOICE_ITM_ADJ"));
                             adjInvItem.set("productId", orderItem.get("productId"));

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - Rounding issue in Invoice adjustment

Si Chen-2
Jacopo,

Yes, this is exactly what the problem was.  However, there are two
subtleties:
1.  You can't do

amount.setScale(decimals, rounding);

You must always do

amount = amount.setScale(decimals, rounding);

Otherwise the value won't change--BigDecimals are immutable.

2.  Later you'd have to re-cast to Double before doing a set, or Entity Engine complains:

adjInvItem.set("amount", new Double(amount.doubleValue()));

Thanks for tracking this down -- It's been bothering me.

See our http://www.opensourcestrategies.com/ofbiz/ofbiz_bigdecimal_cookbook.txt for more details.

Si


Jacopo Cappellato wrote:

> Hi again,
>
> please find attached a proposed patch. I'm still not so comfortable
> with BigDecimals, so your review and comments are welcome.
>
> Jacopo
>
>
>
> Jacopo Cappellato wrote:
>
>> Hi all,
>>
>> I think there is a problem in the invoice adjustments routine
>> (InvoiceServices.createInvoiceForOrder service, line 420).
>> The problem is caused by the following instructions (lines 423-424):
>>
>> BigDecimal amount =
>> adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"),
>> decimals, rounding);
>> amount = amount.multiply(invoiceItem.getBigDecimal("quantity"));
>>
>> In the first line the OrderAdjustment.amount is divided by the
>> OrderItem.quantity to get the "unit adjustment amount".
>> In the second line the "unit adjustment amount" is multiplied by
>> InvoiceItem.quantity to get the total adjustment amount for the
>> invoice item.
>>
>> The problem is that, in the first line, the division is rounded to
>> two decimals (the default decimals for invoices) and this can cause
>> approximations problems.
>>
>> For example:
>>
>> OrderItem.quantity = 5
>> OrderAdjustment.amount = 0.473
>> InvoiceItem.quantity = 5
>>
>> After the first operation we get:
>>
>> OrderAdjustment.amount / OrderItem.quantity = 0.47 / 5 = 0.094 = 0.09
>>
>> After the second operation we get:
>>
>> amount * InvoiceItem.quantity = 0.09 * 5 = 0.45
>>
>> That is different from the adjustment in the order (0.45 != 0.47)
>>
>> I propose to remove the rounding operation from the first line.
>>
>> What do you think?
>>
>> Jacopo
>>  
>> _______________________________________________
>> Dev mailing list
>> [hidden email]
>> http://lists.ofbiz.org/mailman/listinfo/dev
>>
>
>------------------------------------------------------------------------
>
>Index: applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
>===================================================================
>--- applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java (revision 6918)
>+++ applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java (working copy)
>@@ -420,8 +420,9 @@
>                         GenericValue adj = (GenericValue) itemAdjIter.next();
>                         if (adj.get("amount") != null) {
>                             // pro-rate the amount
>-                            BigDecimal amount = adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"), decimals, rounding);
>+                            BigDecimal amount = adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"), 100, rounding);
>                             amount = amount.multiply(invoiceItem.getBigDecimal("quantity"));
>+                            amount.setScale(decimals, rounding);
>                             GenericValue adjInvItem = delegator.makeValue("InvoiceItem", UtilMisc.toMap("invoiceId", invoiceId, "invoiceItemSeqId", invoiceItemSeqId));
>                             adjInvItem.set("invoiceItemTypeId", getInvoiceItemType(delegator, adj.getString("orderAdjustmentTypeId"), invoiceType, "INVOICE_ITM_ADJ"));
>                             adjInvItem.set("productId", orderItem.get("productId"));
>  
>
>------------------------------------------------------------------------
>
>
>_______________________________________________
>Dev mailing list
>[hidden email]
>http://lists.ofbiz.org/mailman/listinfo/dev
>
 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - Rounding issue in Invoice adjustment

Jacques Le Roux
Administrator
Si,

Your cookbook seems very interesting. Is there a way to see all available ?
Maybe you can share them through the Wiki ? That way they could be enhanced by
other parties, what do you think ?

Jacques

----- Original Message -----
From: "Si Chen" <[hidden email]>
To: "OFBiz Project Development Discussion" <[hidden email]>
Sent: Friday, March 10, 2006 6:32 PM
Subject: Re: [OFBiz] Dev - Rounding issue in Invoice adjustment


> Jacopo,
>
> Yes, this is exactly what the problem was.  However, there are two
> subtleties:
> 1.  You can't do
>
> amount.setScale(decimals, rounding);
>
> You must always do
>
> amount = amount.setScale(decimals, rounding);
>
> Otherwise the value won't change--BigDecimals are immutable.
>
> 2.  Later you'd have to re-cast to Double before doing a set, or Entity Engine
complains:
>
> adjInvItem.set("amount", new Double(amount.doubleValue()));
>
> Thanks for tracking this down -- It's been bothering me.
>
> See our
http://www.opensourcestrategies.com/ofbiz/ofbiz_bigdecimal_cookbook.txt for more
details.

>
> Si
>
>
> Jacopo Cappellato wrote:
>
> > Hi again,
> >
> > please find attached a proposed patch. I'm still not so comfortable
> > with BigDecimals, so your review and comments are welcome.
> >
> > Jacopo
> >
> >
> >
> > Jacopo Cappellato wrote:
> >
> >> Hi all,
> >>
> >> I think there is a problem in the invoice adjustments routine
> >> (InvoiceServices.createInvoiceForOrder service, line 420).
> >> The problem is caused by the following instructions (lines 423-424):
> >>
> >> BigDecimal amount =
> >> adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"),
> >> decimals, rounding);
> >> amount = amount.multiply(invoiceItem.getBigDecimal("quantity"));
> >>
> >> In the first line the OrderAdjustment.amount is divided by the
> >> OrderItem.quantity to get the "unit adjustment amount".
> >> In the second line the "unit adjustment amount" is multiplied by
> >> InvoiceItem.quantity to get the total adjustment amount for the
> >> invoice item.
> >>
> >> The problem is that, in the first line, the division is rounded to
> >> two decimals (the default decimals for invoices) and this can cause
> >> approximations problems.
> >>
> >> For example:
> >>
> >> OrderItem.quantity = 5
> >> OrderAdjustment.amount = 0.473
> >> InvoiceItem.quantity = 5
> >>
> >> After the first operation we get:
> >>
> >> OrderAdjustment.amount / OrderItem.quantity = 0.47 / 5 = 0.094 = 0.09
> >>
> >> After the second operation we get:
> >>
> >> amount * InvoiceItem.quantity = 0.09 * 5 = 0.45
> >>
> >> That is different from the adjustment in the order (0.45 != 0.47)
> >>
> >> I propose to remove the rounding operation from the first line.
> >>
> >> What do you think?
> >>
> >> Jacopo
> >>
> >> _______________________________________________
> >> Dev mailing list
> >> [hidden email]
> >> http://lists.ofbiz.org/mailman/listinfo/dev
> >>
> >
> >------------------------------------------------------------------------
> >
> >Index:
applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
> >===================================================================
> >---
applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
(revision 6918)
> >+++
applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
(working copy)
> >@@ -420,8 +420,9 @@
> >                         GenericValue adj = (GenericValue)
itemAdjIter.next();
> >                         if (adj.get("amount") != null) {
> >                             // pro-rate the amount
> >-                            BigDecimal amount =
adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"),
decimals, rounding);
> >+                            BigDecimal amount =
adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"), 100,
rounding);
> >                             amount =
amount.multiply(invoiceItem.getBigDecimal("quantity"));
> >+                            amount.setScale(decimals, rounding);
> >                             GenericValue adjInvItem =
delegator.makeValue("InvoiceItem", UtilMisc.toMap("invoiceId", invoiceId,
"invoiceItemSeqId", invoiceItemSeqId));
> >                             adjInvItem.set("invoiceItemTypeId",
getInvoiceItemType(delegator, adj.getString("orderAdjustmentTypeId"),
invoiceType, "INVOICE_ITM_ADJ"));
> >                             adjInvItem.set("productId",
orderItem.get("productId"));

> >
> >
> >------------------------------------------------------------------------
> >
> >
> >_______________________________________________
> >Dev mailing list
> >[hidden email]
> >http://lists.ofbiz.org/mailman/listinfo/dev
> >
>
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.ofbiz.org/mailman/listinfo/dev

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - Rounding issue in Invoice adjustment

Si Chen-2
You can look at all of them with
www.opensourcestrategies.com/ofbiz/tutorials.php

Unfortunately writing them with the wiki is much harder, so we've chosen
to do it this way.  If you have tips, send it on the mailing list and
we'll include it.

Si

Jacques Le Roux wrote:

>Si,
>
>Your cookbook seems very interesting. Is there a way to see all available ?
>Maybe you can share them through the Wiki ? That way they could be enhanced by
>other parties, what do you think ?
>
>Jacques
>
>----- Original Message -----
>From: "Si Chen" <[hidden email]>
>To: "OFBiz Project Development Discussion" <[hidden email]>
>Sent: Friday, March 10, 2006 6:32 PM
>Subject: Re: [OFBiz] Dev - Rounding issue in Invoice adjustment
>
>
>  
>
>>Jacopo,
>>
>>Yes, this is exactly what the problem was.  However, there are two
>>subtleties:
>>1.  You can't do
>>
>>amount.setScale(decimals, rounding);
>>
>>You must always do
>>
>>amount = amount.setScale(decimals, rounding);
>>
>>Otherwise the value won't change--BigDecimals are immutable.
>>
>>2.  Later you'd have to re-cast to Double before doing a set, or Entity Engine
>>    
>>
>complains:
>  
>
>>adjInvItem.set("amount", new Double(amount.doubleValue()));
>>
>>Thanks for tracking this down -- It's been bothering me.
>>
>>See our
>>    
>>
>http://www.opensourcestrategies.com/ofbiz/ofbiz_bigdecimal_cookbook.txt for more
>details.
>  
>
>>Si
>>
>>
>>Jacopo Cappellato wrote:
>>
>>    
>>
>>>Hi again,
>>>
>>>please find attached a proposed patch. I'm still not so comfortable
>>>with BigDecimals, so your review and comments are welcome.
>>>
>>>Jacopo
>>>
>>>
>>>
>>>Jacopo Cappellato wrote:
>>>
>>>      
>>>
>>>>Hi all,
>>>>
>>>>I think there is a problem in the invoice adjustments routine
>>>>(InvoiceServices.createInvoiceForOrder service, line 420).
>>>>The problem is caused by the following instructions (lines 423-424):
>>>>
>>>>BigDecimal amount =
>>>>adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"),
>>>>decimals, rounding);
>>>>amount = amount.multiply(invoiceItem.getBigDecimal("quantity"));
>>>>
>>>>In the first line the OrderAdjustment.amount is divided by the
>>>>OrderItem.quantity to get the "unit adjustment amount".
>>>>In the second line the "unit adjustment amount" is multiplied by
>>>>InvoiceItem.quantity to get the total adjustment amount for the
>>>>invoice item.
>>>>
>>>>The problem is that, in the first line, the division is rounded to
>>>>two decimals (the default decimals for invoices) and this can cause
>>>>approximations problems.
>>>>
>>>>For example:
>>>>
>>>>OrderItem.quantity = 5
>>>>OrderAdjustment.amount = 0.473
>>>>InvoiceItem.quantity = 5
>>>>
>>>>After the first operation we get:
>>>>
>>>>OrderAdjustment.amount / OrderItem.quantity = 0.47 / 5 = 0.094 = 0.09
>>>>
>>>>After the second operation we get:
>>>>
>>>>amount * InvoiceItem.quantity = 0.09 * 5 = 0.45
>>>>
>>>>That is different from the adjustment in the order (0.45 != 0.47)
>>>>
>>>>I propose to remove the rounding operation from the first line.
>>>>
>>>>What do you think?
>>>>
>>>>Jacopo
>>>>
>>>>_______________________________________________
>>>>Dev mailing list
>>>>[hidden email]
>>>>http://lists.ofbiz.org/mailman/listinfo/dev
>>>>
>>>>        
>>>>
>>>------------------------------------------------------------------------
>>>
>>>Index:
>>>      
>>>
>applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
>  
>
>>>===================================================================
>>>---
>>>      
>>>
>applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
>(revision 6918)
>  
>
>>>+++
>>>      
>>>
>applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
>(working copy)
>  
>
>>>@@ -420,8 +420,9 @@
>>>                        GenericValue adj = (GenericValue)
>>>      
>>>
>itemAdjIter.next();
>  
>
>>>                        if (adj.get("amount") != null) {
>>>                            // pro-rate the amount
>>>-                            BigDecimal amount =
>>>      
>>>
>adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"),
>decimals, rounding);
>  
>
>>>+                            BigDecimal amount =
>>>      
>>>
>adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"), 100,
>rounding);
>  
>
>>>                            amount =
>>>      
>>>
>amount.multiply(invoiceItem.getBigDecimal("quantity"));
>  
>
>>>+                            amount.setScale(decimals, rounding);
>>>                            GenericValue adjInvItem =
>>>      
>>>
>delegator.makeValue("InvoiceItem", UtilMisc.toMap("invoiceId", invoiceId,
>"invoiceItemSeqId", invoiceItemSeqId));
>  
>
>>>                            adjInvItem.set("invoiceItemTypeId",
>>>      
>>>
>getInvoiceItemType(delegator, adj.getString("orderAdjustmentTypeId"),
>invoiceType, "INVOICE_ITM_ADJ"));
>  
>
>>>                            adjInvItem.set("productId",
>>>      
>>>
>orderItem.get("productId"));
>  
>
>>>------------------------------------------------------------------------
>>>
>>>
>>>_______________________________________________
>>>Dev mailing list
>>>[hidden email]
>>>http://lists.ofbiz.org/mailman/listinfo/dev
>>>
>>>      
>>>
>>_______________________________________________
>>Dev mailing list
>>[hidden email]
>>http://lists.ofbiz.org/mailman/listinfo/dev
>>    
>>
>
>
>_______________________________________________
>Dev mailing list
>[hidden email]
>http://lists.ofbiz.org/mailman/listinfo/dev
>
>  
>
 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - Rounding issue in Invoice adjustment

Jacques Le Roux
Administrator
Ok, good, thanks

Jacques

----- Original Message -----
From: "Si Chen" <[hidden email]>
To: "OFBiz Project Development Discussion" <[hidden email]>
Sent: Friday, March 10, 2006 7:02 PM
Subject: Re: [OFBiz] Dev - Rounding issue in Invoice adjustment


> You can look at all of them with
> www.opensourcestrategies.com/ofbiz/tutorials.php
>
> Unfortunately writing them with the wiki is much harder, so we've chosen
> to do it this way.  If you have tips, send it on the mailing list and
> we'll include it.
>
> Si
>
> Jacques Le Roux wrote:
>
> >Si,
> >
> >Your cookbook seems very interesting. Is there a way to see all available ?
> >Maybe you can share them through the Wiki ? That way they could be enhanced
by

> >other parties, what do you think ?
> >
> >Jacques
> >
> >----- Original Message -----
> >From: "Si Chen" <[hidden email]>
> >To: "OFBiz Project Development Discussion" <[hidden email]>
> >Sent: Friday, March 10, 2006 6:32 PM
> >Subject: Re: [OFBiz] Dev - Rounding issue in Invoice adjustment
> >
> >
> >
> >
> >>Jacopo,
> >>
> >>Yes, this is exactly what the problem was.  However, there are two
> >>subtleties:
> >>1.  You can't do
> >>
> >>amount.setScale(decimals, rounding);
> >>
> >>You must always do
> >>
> >>amount = amount.setScale(decimals, rounding);
> >>
> >>Otherwise the value won't change--BigDecimals are immutable.
> >>
> >>2.  Later you'd have to re-cast to Double before doing a set, or Entity
Engine

> >>
> >>
> >complains:
> >
> >
> >>adjInvItem.set("amount", new Double(amount.doubleValue()));
> >>
> >>Thanks for tracking this down -- It's been bothering me.
> >>
> >>See our
> >>
> >>
> >http://www.opensourcestrategies.com/ofbiz/ofbiz_bigdecimal_cookbook.txt for
more

> >details.
> >
> >
> >>Si
> >>
> >>
> >>Jacopo Cappellato wrote:
> >>
> >>
> >>
> >>>Hi again,
> >>>
> >>>please find attached a proposed patch. I'm still not so comfortable
> >>>with BigDecimals, so your review and comments are welcome.
> >>>
> >>>Jacopo
> >>>
> >>>
> >>>
> >>>Jacopo Cappellato wrote:
> >>>
> >>>
> >>>
> >>>>Hi all,
> >>>>
> >>>>I think there is a problem in the invoice adjustments routine
> >>>>(InvoiceServices.createInvoiceForOrder service, line 420).
> >>>>The problem is caused by the following instructions (lines 423-424):
> >>>>
> >>>>BigDecimal amount =
> >>>>adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"),
> >>>>decimals, rounding);
> >>>>amount = amount.multiply(invoiceItem.getBigDecimal("quantity"));
> >>>>
> >>>>In the first line the OrderAdjustment.amount is divided by the
> >>>>OrderItem.quantity to get the "unit adjustment amount".
> >>>>In the second line the "unit adjustment amount" is multiplied by
> >>>>InvoiceItem.quantity to get the total adjustment amount for the
> >>>>invoice item.
> >>>>
> >>>>The problem is that, in the first line, the division is rounded to
> >>>>two decimals (the default decimals for invoices) and this can cause
> >>>>approximations problems.
> >>>>
> >>>>For example:
> >>>>
> >>>>OrderItem.quantity = 5
> >>>>OrderAdjustment.amount = 0.473
> >>>>InvoiceItem.quantity = 5
> >>>>
> >>>>After the first operation we get:
> >>>>
> >>>>OrderAdjustment.amount / OrderItem.quantity = 0.47 / 5 = 0.094 = 0.09
> >>>>
> >>>>After the second operation we get:
> >>>>
> >>>>amount * InvoiceItem.quantity = 0.09 * 5 = 0.45
> >>>>
> >>>>That is different from the adjustment in the order (0.45 != 0.47)
> >>>>
> >>>>I propose to remove the rounding operation from the first line.
> >>>>
> >>>>What do you think?
> >>>>
> >>>>Jacopo
> >>>>
> >>>>_______________________________________________
> >>>>Dev mailing list
> >>>>[hidden email]
> >>>>http://lists.ofbiz.org/mailman/listinfo/dev
> >>>>
> >>>>
> >>>>
> >>>------------------------------------------------------------------------
> >>>
> >>>Index:
> >>>
> >>>
> >applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
> >
> >
> >>>===================================================================
> >>>---
> >>>
> >>>
> >applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
> >(revision 6918)
> >
> >
> >>>+++
> >>>
> >>>
> >applications/accounting/src/org/ofbiz/accounting/invoice/InvoiceServices.java
> >(working copy)
> >
> >
> >>>@@ -420,8 +420,9 @@
> >>>                        GenericValue adj = (GenericValue)
> >>>
> >>>
> >itemAdjIter.next();
> >
> >
> >>>                        if (adj.get("amount") != null) {
> >>>                            // pro-rate the amount
> >>>-                            BigDecimal amount =
> >>>
> >>>
> >adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"),
> >decimals, rounding);
> >
> >
> >>>+                            BigDecimal amount =
> >>>
> >>>
> >adj.getBigDecimal("amount").divide(orderItem.getBigDecimal("quantity"), 100,
> >rounding);
> >
> >
> >>>                            amount =
> >>>
> >>>
> >amount.multiply(invoiceItem.getBigDecimal("quantity"));
> >
> >
> >>>+                            amount.setScale(decimals, rounding);
> >>>                            GenericValue adjInvItem =
> >>>
> >>>
> >delegator.makeValue("InvoiceItem", UtilMisc.toMap("invoiceId", invoiceId,
> >"invoiceItemSeqId", invoiceItemSeqId));
> >
> >
> >>>                            adjInvItem.set("invoiceItemTypeId",
> >>>
> >>>
> >getInvoiceItemType(delegator, adj.getString("orderAdjustmentTypeId"),
> >invoiceType, "INVOICE_ITM_ADJ"));
> >
> >
> >>>                            adjInvItem.set("productId",
> >>>
> >>>
> >orderItem.get("productId"));
> >
> >
> >>>------------------------------------------------------------------------
> >>>
> >>>
> >>>_______________________________________________
> >>>Dev mailing list
> >>>[hidden email]
> >>>http://lists.ofbiz.org/mailman/listinfo/dev
> >>>
> >>>
> >>>
> >>_______________________________________________
> >>Dev mailing list
> >>[hidden email]
> >>http://lists.ofbiz.org/mailman/listinfo/dev
> >>
> >>
> >
> >
> >_______________________________________________
> >Dev mailing list
> >[hidden email]
> >http://lists.ofbiz.org/mailman/listinfo/dev
> >
> >
> >
>
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.ofbiz.org/mailman/listinfo/dev

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev