Models Culculations

8 views
Skip to first unread message

tech george

unread,
Aug 4, 2022, 1:59:20 AMAug 4
to django...@googlegroups.com
Hello,

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)

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

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

@property
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
Forward
0 new messages