This is a follow on from this Ubercart post http://drupal.org/node/942906. Our wish is to have the ability to manage stock using decimal values instead of integers. Lots of business store their inventory in bulk which renders the rigid one to one (one item ordered removes one item from inventory) approach to inventory management virtually useless.

On a typical day, a business like this might take orders for both six 1.5ml packages and eight 12.5ml packages of some precious substance. Then they go to their single container of 3.7 liters of the stuff and then measure it out into the smaller containers to fill the orders.

In this use case, it's completely impractical to deal with the stock as if it were discrete units. It turns out that every order needs a different amount of the stuff so it's impossible to have it sitting around in lots of separate containers of all of the different amounts they might sell. In addition, this stuff is perishable so has to be stored in bulk anyway.

Even if Commerce Stock had a way to remove multiple items of stock when a single item is purchased (I imagine Rules might actually start making that pretty easy), we'd still find ourselves breaking down the inventory into ridiculously small units to accurately manage this situation. Then we'd have to do something really silly like create "kits" containing 12,500 units of the same item just to deliver a 12.5ml package and remove that amount of product from stock. My point is that trying to solve this problem integers gets pretty absurd after a while. Using decimals to manage stock solves all of this very easily.

I'd be curious to hear what others think about supporting decimal inventory throughout Drupal Commerce...

Comments

rfay’s picture

Well, inventory isn't supported at all in core.

I'm open to the idea of decimal inventory; it has a number of problems associated with it (introducing rounding errors and additional data requirements, see below). I did think about it when working on this, but decided that simpler was better.

It would mean that you would have to not only have a field on the product that listed the amount of inventory, but have a second field that said how much inventory this product accounts for, and have that default to 1.

Essentially, lots of added complexity, not clear how many people get the benefit.

videographics’s picture

(Sorry, I didn't mean to imply that there was anything related to inventory in core.)

Thanks for putting in some thinking on this and thanks for being open to this. I think it's pretty clear that now is the time to be dealing with this. Trying to make this work after the fact would clearly require implementing a completely separate stock management module and then, even if it got built, that module would probably end up existing on an island.

I see two parts to implementing this. The first is simply adjusting the schema and coming up with a way of dealing with rounding errors. The second involves adding a inventory ratio field for the product entity (defaulted to 1), and then modifying (or creating anew) the Action "Adjust the product stock level, given a line item" to multiply the quantity for the line item by the inventory ratio for the product.

With just the first part done, the rest might be able to be accomplished as a separate module, but I think there would be some benefits to having it integrated. If the inventory ratio field became a standard part of Commerce Stock (even without support for decimal values), anyone who dealt with multi-item packages that weren't prebuilt could benefit. Adding this would effectively create a very easy and standardized way to implement kits in cases where all of the items are the same. Lots of businesses have items that don't get packed into cases until the orders are placed because they don't know ahead of time whether the items will be purchased as 6 packs, 12 packs, separate items, or whatever. I think this need is pretty much universal.

Then take it to the next level and think of those businesses that don't fill the containers until the orders are placed. This situation actually applies to just about any business that deals with products that are sold by weight or by liquid measure. This encompases a broad spectrum of major industries like food production, chemical production, biotech, materials production, and all the companies that distribute those products, and even many retail businesses like groceries, garden supply stores selling mulch and soil... the list goes on. Lack of support for fractional measures of inventory can quickly become a total deal-breaker for any of those businesses. This is hardly an edge case. Hopefully we can start using decimals and bring them all into the fold.

travelertt’s picture

My thoughts are to have decimal inventory be a secondary module. Decimal inventory is most useful on Raw materials, liquids, and fabrics. Those materials have additional rules and best practices on how they are handled and stocked. Decimal inventory products need more controls, rules, and limitations than other product types. It seems best to keep those additional rules sets out side of the initial module and be added in with a secondary module when needed.

Here are some examples of what I mean.

Let’s say you sell fabric. Your customers will order your BLUE-LINEN-01 in units of meters (keeping it international). You would set up the product type with some limitations. You want your customers to have the ability to order the length of fabric they want, but it's not feasible to allow your customers to order any decimal units they want. Yes, they may only need 10.4m of BLUE-LINEN-01, but it causes you more overhead in allowing that type of transaction. Instead you may allow HALF units or quarter units to be sold. That’s a Limitation on Units of Measure (UOM).

In addition your reams of BLUE-LINEN-01 are 50m long, so this limits the total amount a customer can buy on a single line item. If your customer wants 100m of fabric, too bad you don't have that. (Maybe you can make a special order with your manufacturer.) That’s a Limitation on the quantity ordered.

There is an analog component to Decimal Inventory Products. It’s harder to get an accurate measure of units sold. You may not want the system to handle the stock levels for these items. Things like raw materials, liquid, fabric or other measurable substances have to be measured out. Your customer orders 10m of BLUE-LINEN-01 but you cut off 10.02m of fabric. Then the next order you cut of 8.1m, followed by 6.08m, 7.04m, and so on. At the end of the day you could be off by 5m! In fact you expect to be, because ONE you’re not perfect, and TWO you want to give the customer just a little more slack. So, there is a Limitation of Accuracy.

In fact most operations wouldn’t trust a system where stock was handled in this manner. Stock levels would checked at the end of the day, week, month, or whatever the cycle, in order to get a more accurate number of the actual stock on hand.

There is also the issue were multiple products come from the same SUPPLY, or SUPPLY product. A company would sell items SIX-1_5ML-BRW and EIGHT-12_5ML-BRW that both contain the same SUPPLY product. These two items wouldn't have stock levels. The SUPPLY product, SPC-STUFF, would have a stock field and would be used to monitor the stock on hand. At the end of every day the tanks where SPC-STUFF is stored would be measured, and then the stock level would be adjusted. This is a Limitation of Measure.
Hope this is helpful.

serialjaywalker’s picture

Commerce Line Item stores quantities to two decimal places, but by default, form validation prevents decimal values from being entered. Since stock changes will often arise from line items, it seems like it would make sense to follow the same convention for stock (except, of course, that this would require more work, but work I'd be willing to contribute).

guy_schneerson’s picture

see Commerce_stock Roadmap for the idea of using a sub module system where the current integer stock system will be a single sub module 'simple stock' and other sub modules can be developed like 'decimal stock'

videographics’s picture

I'm curious about the history behind the Commerce Line Item storing decimal quantities (identified in #4). How did it get there? What was the reasoning behind it? Is it documented? Why would it be limited to 2 decimal places? Does anyone know?

Also, how did you happen to discover it was there?

serialjaywalker’s picture

I can't say I know anything about the history. I discovered it by reading commerce_line_item_schema() in commerce_line_item.install.

guy_schneerson’s picture

Status: Active » Closed (works as designed)

Closing the issue as this is not a real issue with the current version of stock and we can look at this for version 2 again if needed, we have a link from the roadmap so we can get back to this if needed.

videographics’s picture

Does anyone know the logic behind why the schema for Commerce Line Items goes to 2 decimal places? Is this arbitrary? Shall we assume the potential for rounding errors play a part?

Guy, are you sure this isn't a "closed (won't fix)" situation? Shouldn't Commerce Stock at least support what's in the schema for the Drupal Commerce line items?

Per #3: Wouldn't Commerce Stock itself need to be aware of the fractional inventory for any other modules to work with fractional inventory in any way?

I'm sorry to see something like this getting set aside -- especially with Commerce Stock still in early alpha. My sense is that this is just the kind of thing that's going to be increasingly difficult to implement after the fact as all of the other related modules get established dealing exclusively with items instead of amounts. I still can't envision a method by which an add-on module could implement this capability if Commerce Stock doesn't support it. Instead, we might be faced with branching Commerce Stock very early on which would be most undesirable. Even if there's not an interface, is there a possibility that we can at least get the schema set to support this so other modules trying to support this would have a chance for some integration?

I agree that this feature is somewhat "special" in the sense that it doesn't exist in lots of other "successful" inventory software solutions, but it does have a wide range of use cases and does have the ability to further distinguish Drupal Commerce as a system that's open enough to handle a diverse range of situations.

rfay’s picture

Conversation with rszrama in IRC:

it is indeed arbitrary, but it is there to support fractional quantities
<rszrama> rfay: all you have to do to have fractional quantities is tweak the form so it doesn't validate for integers
<rfay> rszrama, hmm. So Commerce might be able to support fractional quantities? Stock has tried not to do that :-)
<rszrama> rfay: yeah, Commerce definitely does support it; we just don't offer a UI based way to change the forms to support it
<rszrama> rfay: it's kinda like multiple order types; we support it, but we don't offer any practical way to use it through the UI
guy_schneerson’s picture

@videographics as stated by the roadmap, the idea of version 2 is to create a framework that uses sub-modules to implement the specific stock check.
The result I believe will be a very small sub module “simple stock” implementing the decimal stock. This will act as an example to other sub-modules like a potential decimal stock without the need to branch the main stock module.

However I will be very happy to look into an implementation of a decimal stock as part of the basic “simple stock” module or a second “decimal stock” module if you or anyone can provide an example site that utilises decimal quantities.

videographics’s picture

Would a decimal stock sub-module have any chance of working properly if Commerce Stock and all of the other related Commerce Stock modules were to carry on assuming they they're only going to ever be dealing with integers?

videographics’s picture

It sounds like travelertt has a site. I like the custom-cut fabric model if that's what it is.

I have a fancy food purveyor (currently on OS Commerce) selling premium olive oils, vinegars, honey, and preserves, that might be a good candidate for this. They store much of their stock in bulk.

I know a lot of wineries that could benefit from this.

I've also got one client selling small amounts of biological chemicals for medical research. They typically sell in only 5 different volumes of measure (between 0.5 and 25 ml.), but virtually ever order they fill is custom measured from bulk storage because it requires special refrigeration and they never know what quantities will be purchased. If someone orders 25ml, they can't realistically ship 50 x 0.5ml containers. This is definitely an issue for them.

guy_schneerson’s picture

Hi @videographics,
The Commerce Stock V2 module will not make any assumptions about the stock, will not do any of the checking, inc/dec of stock or the storing of stock.
The current stock handling functionality will move into a sub module "simple stock" and it will be easy to create new sub modules, however i think it would be better to add decimal support for it if we can.
If you can get an example site or good instructions on how to set one up that has a decimal add to cart formatter it would help as I will need something to test it on.
The actual work on the “simple stock” module is going to be towards the end of the work as the framework needs to be in place first, so we got some time ( I am hoping to start work on V2 in the next two weeks if 1 is stable).

videographics’s picture

I'd be surprised if anyone is currently taking advantage of the fractional quantity capability in Commerce. I'd just like to see a cart working with the integer validations removed before getting too far into the stock aspects of this. I'm pretty maxed out these days so it's going to be a while before I'm going to have the bandwidth to play around with it. If anyone has a chance to remove the integer validation on the add to cart form and report back, I'd be curious to know that at least that part's working.

videographics’s picture

I'd be surprised if anyone is currently taking advantage of the fractional quantity capability in Commerce. I'd just like to see a cart working with the integer validations removed before getting too far into the stock aspects of this. I'm pretty maxed out these days so it's going to be a while before I'm going to have the bandwidth to play around with it. If anyone has a chance to remove the integer validation on the add to cart form and report back, I'd be curious to know that at least that part's working.

guy_schneerson’s picture

Status: Closed (works as designed) » Active
videographics’s picture

I'm afraid my last comment was misinterpreted and led you to check this off your list prematurely. There is a substantial need for this. I've got real clients that can't manage their inventory in Drupal because of it. I was just saying that if those of us interested in this topic are just finding out about the fact that fractional quantities are supported in Commerce, it's unlikely that there are people already taking advantage of fractional quantities in Commerce -- especially if it's all still hardcoded to validate for integers. My point is that removing the validation and testing the fractional quantity capability in Commerce is the first step toward implementing fractional quantities in a Stock module.

guy_schneerson’s picture

@videographics - i think i got you and that's why i set the issue back to open.
I opened the issue up so everyone can see it and hopefully someone with the need and some time can help out.

videographics’s picture

thx guy

czigor’s picture

@guy: Has there been any progress on this? Our customer wants to sell curtains so I might have the time to work on a decimal submodule. Is it decided yet how the submodules will be able to hook into the 2.0 module?

czigor’s picture

For curtains we need the following functionality (summing up what's been said so far):
We need a decimal_stock field.

Its settings page:

  • Unit (e.g. m). This will be attached after the display of commerce_price. Not required.
  • Precision (e.g. 0.3) - the customer can buy only (smallest_quantity + n*Precision) quantity of the product (where n is a nonnegative integer). Not required.
  • Smallest quantity (defaults to Precision). Not required.

Display:

  • After the price attach the unit. E.g. $50/m
  • Write a help text below the quantity field such as "You can buy only multiples of 0.3m."

As for the Limitation of Accuracy in #3 I don't think you can do anything about it but set the stock level by hand every now and then.

What else do we need?

I don't really understand rfay's suggestion in #1 saying "have a second field that said how much inventory this product accounts for, and have that default to 1." Is this about product bundles? Or can you give an example?

guy_schneerson’s picture

@czigor - while version two is not ready it has most of the functionality you probably need.
it uses rules to validate the add to cart and will soon use rules for determining the enabled/disabled of the add to cart form.
as far as a decimal sub module the situation is:
i am happy to try and get the main module out with decimal stock instead of an integer one as i think it can serve both cases.
what i really need is an example (copy or setup instructions) of a working site using decimal values to test this on.
as things are you can add your own field to a product and create stock checking rules with out the need for a special module.

videographics’s picture

I do think it's worth pointing out that if someone absolutely needs this to work right now, one can just create their own decimal field for the product entity and use rules to manipulate and check it. But isn't it still a problem when you go to create an order? I'd imagine we'd then have to rig up some rules to create a product with a custom size (qty 1) for each order based on the amount that's needed. Am I missing something? Is there an easier way?

Ultimately, I think the main point of this issue is to have a decimal inventory system that is implemented in a standard way so that it's going to play nice with Drupal Commerce and stock-related contrib modules out of the box.

FYI, I'd like to help with a test implementation of this but my needs from earlier this year have waned a bit. I still have three sites that could that have the potential to take advantage of this but things have shifted recently and none are imminent. I also have an industry I'm looking at supporting long-term that would absolutely require this, but that's a direction I won't be going for a while. I do expect I'm going to need this sooner or later, but my current best prospect for an initial implementation of this is on hold and my second best is probably looking at early next year. It sounds like cizigor is ready to go.

videographics’s picture

To clarify the whole idea of an inventory ratio as I was envisioning it in #2:

The ratio describes how many units of inventory are represented by a single unit of a particular product. For example, if you were selling a liquid measure, you might measure your stock in milliliters but you might have five different filled to order amounts available for sale: 0.1ml, 0.5ml, 5ml, 10ml, and 25ml. If the stock was managed in milliliter units, then the 0.1ml product would have an inventory ratio of 0.1 to show that one of these items represents one tenth of one unit of inventory. Similarly, the 5ml product would have an inventory ratio of 5 to show that one of these items represents 5 units of inventory. (Perfect for storing individual bottles and selling 6-packs and 12-packs, no?) This has the extra benefit of creating an easy way to implement "kits" (as long as you're packaging multiple units of the same product) without having to implement a separate kit module.

RKS’s picture

I don't need any non-integer stock but I do see in the past with UC there were people who needed a weight-based stock. It might be simpler to design a frame of sorts were users can hook in with their specific stock needs.

As far as comment #10, it sounds like what I had to do once with UC Tax module. It was also designed to check for an integer and the hardcode in .module was set to something like >0. Since it was for a personal site and of a limited use case, I just changed what I needed to something like >-100. Changing the actual modules is bad practice so it definitely isn't a solution, but if you provide your own patch you can continue to apply the patch when you update the module (at least until the submodule is added.) If this is for a client you'll have to wait for a submodule since they won't know to continue applying the patch and it will break their functionality when they update the module.

guy_schneerson’s picture

@RKS see #14

RKS’s picture

Yeah, sometimes I don't read. Sorry to put my nose in.

czigor’s picture

I created a small contrib module which is supposed to make decimal quantities possible.

http://drupal.org/project/commerce_decimal_quantities

Bug reports are welcome!

guy_schneerson’s picture

@czigor, that's great ill check it out

guy_schneerson’s picture

Status: Active » Closed (works as designed)

this is now supported in version 2