Safe handling of items_in_stock

Issue #617 new
mk
created an issue

items_in_stock is currently handled in an unsafe manner (AFAICS):

  1. Open product in administration page
  2. Order 1 product -> decreases items_in_stock count by one
  3. Save product in administration -> overwrites items_in_stock with old value

This can be solved by introducing a model similar to the following:

{{{ class StockTransaction(models.Model): product = models.ForeignKey('product.Product') change = models.IntegerField( help_text=u'Enter negative numbers for sales and lendings.') created = models.DateTimeField(default=datetime.now, editable=False) note = models.TextField(default=u'', blank=True)

class Meta:
    db_table = 'satchmoext_stock_stocktransaction'

objects = StockTransactionManager()

def save(self, **kwargs):
    super(StockTransaction, self).save(**kwargs)
    self.product.recalculate_items_in_stock(save=True)

}}}

and two very simple changes to satchmo.payment.views.checkout.success and satchmo.product.models.save.

I'm attaching the current version of the code here for reference.

Comments (2)

  1. Hynek Cernoch
    • changed milestone to dev

    It can be solved by writing a special widget and mix-in which saves the old value to the hidden field in the form... (hopefully)

    Actually, the product is not removed from the stock by creating the order, it is only _reserved_. Transactions for this is overkill. A separate robust inventory is used.

    Every editing usually is made by an unsafe manner in any web application. The solution by widgets can be extensible to different important fields without complicating the model.

  2. Log in to comment