Fractional quantities?

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

Fractional quantities?

Ean Schuessler
Ok, I'm probably missing something really basic here... but... are fractional
quantities supported? The database is all double, the interfaces on
ShoppingCart are all double but the ShoppingCart itself just sort of quietly
casts the double to an int. Whazzap with that?

I commented it out and used some fractional quantities and that all seems cool
enough. Am I about to descend into some hell of double arithmetic rounding
errors? The prices are all BigDecimal, right? The Price Is Right, right?!?

A short diff for your amusement:

Index:
applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
===================================================================
--- applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java  
(revision 462)
+++ applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java  
(working copy)
@@ -673,11 +673,6 @@
         this.setQuantity(quantity, dispatcher, cart, triggerExternalOps,
true);
     }
 
-    /** Sets the quantity for the item and validates the change in quantity,
etc */
-    public void setQuantity(double quantity, LocalDispatcher dispatcher,
ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup) throws
CartItemModifyException {
-        this.setQuantity((int) quantity, dispatcher, cart,
triggerExternalOps, resetShipGroup);
-    }
-
     /** returns "OK" when the product can be booked or returns a string with
the dates the related fixed Asset is not available */
     public static String checkAvailability(String productId, double quantity,
Timestamp reservStart, double reservLength, ShoppingCart cart) {
         GenericDelegator delegator = cart.getDelegator();
@@ -767,7 +762,7 @@
             return "I am sorry, not available at these dates: " +
resultMessage + "item not added to the shopping cart.....";
     }
 
-    protected void setQuantity(int quantity, LocalDispatcher dispatcher,
ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup) throws
CartItemModifyException {
+    protected void setQuantity(double quantity, LocalDispatcher dispatcher,
ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup) throws
CartItemModifyException {
         if (this.quantity == quantity) {
             return;
         }

--
Ean Schuessler, CTO
[hidden email]
214-720-0700 x 315
Brainfood, Inc.
http://www.brainfood.com
Reply | Threaded
Open this post in threaded view
|

Re: Fractional quantities?

Jacques Le Roux
Administrator
Hi Ean,

You may find those threads interesting (using view threaded):

http://www.nabble.com/Users---Decimal-quantity-on-orders-tf1448709.html#a4029250
http://www.nabble.com/Users---Units-of-measure-for-quantities-in-sales-purchase-manufacturing-orders-and-for-inventory-tf941809.html#a2472113

Jacques


----- Original Message -----
From: "Ean Schuessler" <[hidden email]>
To: <[hidden email]>
Sent: Friday, December 22, 2006 3:54 AM
Subject: Fractional quantities?


> Ok, I'm probably missing something really basic here... but... are fractional
> quantities supported? The database is all double, the interfaces on
> ShoppingCart are all double but the ShoppingCart itself just sort of quietly
> casts the double to an int. Whazzap with that?
>
> I commented it out and used some fractional quantities and that all seems cool
> enough. Am I about to descend into some hell of double arithmetic rounding
> errors? The prices are all BigDecimal, right? The Price Is Right, right?!?
>
> A short diff for your amusement:
>
> Index:
> applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
> ===================================================================
> --- applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
> (revision 462)
> +++ applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
> (working copy)
> @@ -673,11 +673,6 @@
>          this.setQuantity(quantity, dispatcher, cart, triggerExternalOps,
> true);
>      }
>
> -    /** Sets the quantity for the item and validates the change in quantity,
> etc */
> -    public void setQuantity(double quantity, LocalDispatcher dispatcher,
> ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup) throws
> CartItemModifyException {
> -        this.setQuantity((int) quantity, dispatcher, cart,
> triggerExternalOps, resetShipGroup);
> -    }
> -
>      /** returns "OK" when the product can be booked or returns a string with
> the dates the related fixed Asset is not available */
>      public static String checkAvailability(String productId, double quantity,
> Timestamp reservStart, double reservLength, ShoppingCart cart) {
>          GenericDelegator delegator = cart.getDelegator();
> @@ -767,7 +762,7 @@
>              return "I am sorry, not available at these dates: " +
> resultMessage + "item not added to the shopping cart.....";
>      }
>
> -    protected void setQuantity(int quantity, LocalDispatcher dispatcher,
> ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup) throws
> CartItemModifyException {
> +    protected void setQuantity(double quantity, LocalDispatcher dispatcher,
> ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup) throws
> CartItemModifyException {
>          if (this.quantity == quantity) {
>              return;
>          }
>
> --
> Ean Schuessler, CTO
> [hidden email]
> 214-720-0700 x 315
> Brainfood, Inc.
> http://www.brainfood.com

Reply | Threaded
Open this post in threaded view
|

Re: Fractional quantities?

Jacques Le Roux
Administrator
Actually the thread I was looking for is this :
http://www.nabble.com/Question-about-SupplierProduct.unitsIncluded-tf2219815.html#a6162837

Finally it's not exactly related (talk most about prices) but maybe interesting too...

Jacques

----- Original Message -----
From: "Jacques Le Roux" <[hidden email]>
To: <[hidden email]>
Sent: Friday, December 29, 2006 11:00 PM
Subject: Re: Fractional quantities?


> Hi Ean,
>
> You may find those threads interesting (using view threaded):
>
> http://www.nabble.com/Users---Decimal-quantity-on-orders-tf1448709.html#a4029250
>
http://www.nabble.com/Users---Units-of-measure-for-quantities-in-sales-purchase-manufacturing-orders-and-for-inventory-tf941809.html#a2472113

>
> Jacques
>
>
> ----- Original Message -----
> From: "Ean Schuessler" <[hidden email]>
> To: <[hidden email]>
> Sent: Friday, December 22, 2006 3:54 AM
> Subject: Fractional quantities?
>
>
> > Ok, I'm probably missing something really basic here... but... are fractional
> > quantities supported? The database is all double, the interfaces on
> > ShoppingCart are all double but the ShoppingCart itself just sort of quietly
> > casts the double to an int. Whazzap with that?
> >
> > I commented it out and used some fractional quantities and that all seems cool
> > enough. Am I about to descend into some hell of double arithmetic rounding
> > errors? The prices are all BigDecimal, right? The Price Is Right, right?!?
> >
> > A short diff for your amusement:
> >
> > Index:
> > applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
> > ===================================================================
> > --- applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
> > (revision 462)
> > +++ applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
> > (working copy)
> > @@ -673,11 +673,6 @@
> >          this.setQuantity(quantity, dispatcher, cart, triggerExternalOps,
> > true);
> >      }
> >
> > -    /** Sets the quantity for the item and validates the change in quantity,
> > etc */
> > -    public void setQuantity(double quantity, LocalDispatcher dispatcher,
> > ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup) throws
> > CartItemModifyException {
> > -        this.setQuantity((int) quantity, dispatcher, cart,
> > triggerExternalOps, resetShipGroup);
> > -    }
> > -
> >      /** returns "OK" when the product can be booked or returns a string with
> > the dates the related fixed Asset is not available */
> >      public static String checkAvailability(String productId, double quantity,
> > Timestamp reservStart, double reservLength, ShoppingCart cart) {
> >          GenericDelegator delegator = cart.getDelegator();
> > @@ -767,7 +762,7 @@
> >              return "I am sorry, not available at these dates: " +
> > resultMessage + "item not added to the shopping cart.....";
> >      }
> >
> > -    protected void setQuantity(int quantity, LocalDispatcher dispatcher,
> > ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup) throws
> > CartItemModifyException {
> > +    protected void setQuantity(double quantity, LocalDispatcher dispatcher,
> > ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup) throws
> > CartItemModifyException {
> >          if (this.quantity == quantity) {
> >              return;
> >          }
> >
> > --
> > Ean Schuessler, CTO
> > [hidden email]
> > 214-720-0700 x 315
> > Brainfood, Inc.
> > http://www.brainfood.com

Reply | Threaded
Open this post in threaded view
|

Re: Fractional quantities?

Ean Schuessler
In reply to this post by Jacques Le Roux
On Friday 29 December 2006 16:00, Jacques Le Roux wrote:
> You may find those threads interesting (using view threaded):
>
> http://www.nabble.com/Users---Decimal-quantity-on-orders-tf1448709.html#a40
>29250
> http://www.nabble.com/Users---Units-of-measure-for-quantities-in-sales-purc
>hase-manufacturing-orders-and-for-inventory-tf941809.html#a2472113

OK, I see. I should have searched more carefully.

Will the database entities eventually migrate to being integers?

--
Ean Schuessler, CTO
[hidden email]
214-720-0700 x 315
Brainfood, Inc.
http://www.brainfood.com
Reply | Threaded
Open this post in threaded view
|

Re: Fractional quantities?

David E Jones-2

On Dec 29, 2006, at 6:24 PM, Ean Schuessler wrote:

> On Friday 29 December 2006 16:00, Jacques Le Roux wrote:
>> You may find those threads interesting (using view threaded):
>>
>> http://www.nabble.com/Users---Decimal-quantity-on-orders- 
>> tf1448709.html#a40
>> 29250
>> http://www.nabble.com/Users---Units-of-measure-for-quantities-in- 
>> sales-purc
>> hase-manufacturing-orders-and-for-inventory-tf941809.html#a2472113
>
> OK, I see. I should have searched more carefully.
>
> Will the database entities eventually migrate to being integers?

This is the million dollar question (sorry for the localized saying).

There is still some debate about whether we want to continue on the  
(unfinished) path of the quantity/amount pair, or just go back to a  
fractional quantity on its own.

Personally I'd much rather see the quantity/amount move forward, but  
it is incomplete and so needs some work. I've heard things actually  
function if the integer restriction is removed, so that is probably  
the easier, but less flexible and future proof, way to go (ie just  
tweak it to accept franctional quantities).

-David

Reply | Threaded
Open this post in threaded view
|

Re: Fractional quantities?

Ean Schuessler
On Friday 29 December 2006 19:40, David E Jones wrote:

> This is the million dollar question (sorry for the localized saying).
>
> There is still some debate about whether we want to continue on the
> (unfinished) path of the quantity/amount pair, or just go back to a
> fractional quantity on its own.
>
> Personally I'd much rather see the quantity/amount move forward, but
> it is incomplete and so needs some work. I've heard things actually
> function if the integer restriction is removed, so that is probably
> the easier, but less flexible and future proof, way to go (ie just
> tweak it to accept franctional quantities).

It seems to me that fractional quantities (perhaps with a flag that blocks
non-integer values for some items) is cleaner. I would think that typically
different "amount" type things would show up as actual separate SKUs.

For instance, in the lumber example, I would think you would have separate
actual SKUs for a 8' and 10' board and that you would not want to ring up 3
8' boards as a 2.4 amount of a 10' SKU.

The fractional quantities seem to work for me. I need to try the amount stuff,
does that reflect into inventories correctly? How does that part work?

--
Ean Schuessler, CTO
[hidden email]
214-720-0700 x 315
Brainfood, Inc.
http://www.brainfood.com
Reply | Threaded
Open this post in threaded view
|

Re: Fractional quantities?

David E Jones-2

On Dec 29, 2006, at 6:54 PM, Ean Schuessler wrote:

> On Friday 29 December 2006 19:40, David E Jones wrote:
>> This is the million dollar question (sorry for the localized saying).
>>
>> There is still some debate about whether we want to continue on the
>> (unfinished) path of the quantity/amount pair, or just go back to a
>> fractional quantity on its own.
>>
>> Personally I'd much rather see the quantity/amount move forward, but
>> it is incomplete and so needs some work. I've heard things actually
>> function if the integer restriction is removed, so that is probably
>> the easier, but less flexible and future proof, way to go (ie just
>> tweak it to accept franctional quantities).
>
> It seems to me that fractional quantities (perhaps with a flag that  
> blocks
> non-integer values for some items) is cleaner. I would think that  
> typically
> different "amount" type things would show up as actual separate SKUs.
>
> For instance, in the lumber example, I would think you would have  
> separate
> actual SKUs for a 8' and 10' board and that you would not want to  
> ring up 3
> 8' boards as a 2.4 amount of a 10' SKU.
>
> The fractional quantities seem to work for me. I need to try the  
> amount stuff,
> does that reflect into inventories correctly? How does that part work?

For amounts there is a field on the product (requireAmount if I  
remember right) to denote that a product should be purchased with  
both a quantity and amount.

You're right that things which are pre-cut should be variants or  
something with separate productIds and those would not have a  
fractional amount. Some things are easily cut in a somewhat build-to-
order fashion, like rope or wire or rolls of anything really. The  
idea with the combination of an integer quantity and a fractional  
amount is that you could specify, with the rope example, that you  
want 4 lengths of rope that are 100 ft each (ft being the amount unit  
on the product).

The way it _should_ work in inventory checking, reserving, and  
issuing is to multiply the quantity by the amount to get the  
fractional quantity for the InventoryItem, etc. I think this is where  
the implementation historically left off, and I don't know if it has  
seen any action since its early days. This really needs to be tested  
and finished for the purchase and reservation, issuing and shipping,  
invoicing, returning, etc.

-David