Fikset justering av stock ved kjøp.

To ting:

1) amount er ikke nødvendigvis 1 (selv om den alltid blir det slik vi
   lager PurchaseEntries nå).
2) Justering av stock skal skje i Transaction.perform_transaction,
   ikke når PurchaseEntry-en lages.
This commit is contained in:
Øystein Ingmar Skartsæterhagen 2011-03-07 17:10:00 +00:00
parent 2bab42e3c5
commit 7dc8c798c3
1 changed files with 3 additions and 1 deletions

4
db.py
View File

@ -71,7 +71,6 @@ class PurchaseEntry(Base):
self.product_bar_code = product.bar_code
self.purchase = purchase
self.amount = amount
self.product.stock -= 1
def __repr__(self):
return "<PurchaseEntry('%s', '%s')>" % (self.product.name, self.amount )
@ -97,6 +96,9 @@ class Transaction(Base):
def perform_transaction(self):
self.time = datetime.datetime.now()
self.user.credit -= self.amount
if self.purchase:
for entry in self.purchase.entries:
entry.product.stock -= entry.amount
class Purchase(Base):