Tuesday, August 30, 2022

Re: Negative Stock Prevention

On Mon, Aug 29, 2022 at 05:18:39PM +0300, tech george wrote:
> Please help crack the below code, I want to prevent negative stock, and if
> the stock is == 0, deduct it from reorder_level instead.
> Currently, the stock goes negative.
>
> models.py
>
> class Stock(models.Model):
> quantity = models.IntegerField(default='0', blank=True, null=True)
> reorder_level = models.IntegerField(default='0', blank=True, null=True)
>
> class Dispense(models.Model):
> 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)

Maybe change quantity and reorder_level to PositiveIntegerField?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20220830144358.GE1858%40fattuba.com.

No comments:

Post a Comment