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:
parent
2bab42e3c5
commit
7dc8c798c3
4
db.py
4
db.py
|
@ -71,7 +71,6 @@ class PurchaseEntry(Base):
|
||||||
self.product_bar_code = product.bar_code
|
self.product_bar_code = product.bar_code
|
||||||
self.purchase = purchase
|
self.purchase = purchase
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
self.product.stock -= 1
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<PurchaseEntry('%s', '%s')>" % (self.product.name, self.amount )
|
return "<PurchaseEntry('%s', '%s')>" % (self.product.name, self.amount )
|
||||||
|
|
||||||
|
@ -97,6 +96,9 @@ class Transaction(Base):
|
||||||
def perform_transaction(self):
|
def perform_transaction(self):
|
||||||
self.time = datetime.datetime.now()
|
self.time = datetime.datetime.now()
|
||||||
self.user.credit -= self.amount
|
self.user.credit -= self.amount
|
||||||
|
if self.purchase:
|
||||||
|
for entry in self.purchase.entries:
|
||||||
|
entry.product.stock -= entry.amount
|
||||||
|
|
||||||
|
|
||||||
class Purchase(Base):
|
class Purchase(Base):
|
||||||
|
|
Loading…
Reference in New Issue