割り当て前に参照されたエラーローカル変数「stockqty」を解決するにはどうすればよいですか。モデルの1つに、アイテムを検索して数量、価格、コストなどの値を返すsaveメソッドがありますが、このエラーが発生し続けます。
def save(self):
callitems=Item.objects.filter(subcategory=self.ItemName)
for callitem in callitems:
stockqty=callitem.quantity
#stovkqty.append(callitem.quantity)
price=callitem.unitprice
#price.append(callitem.unitprice)
cost=callitem.unitcost
#cost.append(callitem.unitcost)
vat=callitem.tax.rate
if self.quantity < stockqty: the error complain is here
if self.discount==True:
self.total= self.discountprice * self.quantity
self.profit=self.total-(cost * self.quantity)
self.salesdate=date.today()
self.salestime=datetime.now()
self.staff='admin'
Item.objects.filter(subcategory=self.ItemName).update(quantity=stockqty-self.quantity)
else:
self.total= price * self.quantity
self.profit=self.total-(cost * self.quantity)
self.salesdate=date.today()
self.salestime=datetime.now()
self.staff='admin'
Item.objects.filter(subcategory=self.ItemName).update(quantity=stockqty-self.quantity)
super(RecordSales, self).save()