Re: Help with inventory control

From: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>
To: fgrijalba(at)gmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Help with inventory control
Date: 2005-09-30 19:19:00
Message-ID: 200509301919.j8UJJ05h007429@gw.tssi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> User1 starts order and takes the last two units. User2 starts order 1 minut=
> e
> after and checks inventory. He sees 2 units left and adds them to the his
> order. User1 commits his order. Now User2 cannot finish his order because
> the products are not available anymore.
>
> This is the problem I want to avoid. Therefore if User1 takes the product
> but does not finish the order I want the inventory to still show that the
> product is sold out to other users.
>
> Any suggestions on how to implemnt that?

One common way to deal with it is to have a separate 'hold quantity'
field (or table) for items in pending orders. You can commit to that
field or table as each line item is entered, revised or deleted during
order entry. When the order is finalized, you simultaneously release
the hold and take the item out of inventory.

The primary problem with this method is abandoned orders, because you
want to release that inventory so someone else can order it.

That's more of an issue if you are writing an application for your
customers than if it's being used by a sales staff who will know to
cancel an abandoned order. (However, you probably still need a 'cancel
pending transaction' capability to deal with things like system crashes.)

I once designed a web-based transaction system which kept a timestamp on
each 'on hold' line item. It assumed that if the order wasn't completed
within an hour the order had been abandoned, and at that point it released
the hold on any items. (Actually it just checked the timestamp when
adding up the 'on hold' quantity during an inventory check and ignored
any timestamp that was more than an hour old.)

There was also a one hour inactivity timeout on the web form, as I recall.

You should be able to do most of this with trigger functions.
--
Mike Nolan

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joe Maldonado 2005-09-30 19:27:14 not quite expected behaviour when using IN clause
Previous Message Douglas McNaught 2005-09-30 17:03:39 Re: Help with inventory control