Models Culculations

Skip to first unread message

tech george

Aug 4, 2022, 1:59:20 AMAug 4

Please help with the below, I am trying to get dispense_quantity from Dispense Model and subtract it from the quantity on Stock Model.

Then after that get something like this;

def closing_stock(self):
      return (self.quantity - self. quantity_issued  )

class Stock(models.Model):
unit_price = models.DecimalField(max_digits=10, decimal_places=2, default='0', blank=True, null=True)
quantity = models.IntegerField(default='0', blank=True, null=True)
total_price = models.DecimalField(max_digits=10, decimal_places=2, default=1)
total_stock = models.IntegerField(default='0', blank=True, null=True)
receive_quantity = models.IntegerField(default='0', blank=True, null=True)
reorder_level = models.IntegerField(default='0', blank=True, null=True)
reorder_price = models.DecimalField(max_digits=10, decimal_places=2, default='0', blank=True, null=True)

def __str__(self):
return str(self.drug_name)

def total_price(self):
return (self.quantity + self.reorder_level) * self.unit_price

def total_stock(self):
return (self.quantity + self.reorder_level)

def reorder_stock(self):
return (self.reorder_level * self.reorder_price)

class Dispense(models.Model):
nurse = models.ForeignKey(Pharmacist, on_delete=models.CASCADE, null=True)
patient_id = models.ForeignKey(Patients, on_delete=models.DO_NOTHING, null=True)
drug_id = models.ForeignKey(Stock, on_delete=models.SET_NULL, null=True, blank=False)
dispense_quantity = models.PositiveIntegerField(default='1', blank=False, null=True)
taken = models.CharField(max_length=300, null=True, blank=True)
Reply all
Reply to author
0 new messages