Re: Negative Stock Prevention

2022-09-01 Thread Ryan Nowakowski
If you get this error during migration you likely have some existing Stock rows in your database with quantity that is less than 0. If this site is in production already, you'll need to create a data migration to change your negative quantities to zero. https://docs.djangoproject.com/en/4.1/top

Re: Negative Stock Prevention

2022-08-31 Thread tech george
I managed to remove the error, I had a negative stock in my DB. Thanks a lot for the help. On that note, I was also trying to get the dispensed from stock I was trying to do this but I don't think it can work since there is already a foreign key at Dispense model fetching drug_id from stock. W

Re: Negative Stock Prevention

2022-08-31 Thread tech george
Hello, Sorry the error is: django.db.utils.IntegrityError: CHECK constraint failed: quantity On Thu, Sep 1, 2022 at 3:45 AM Ryan Nowakowski wrote: > I don't see any error. Did you forget to post it? > > On August 31, 2022 5:57:32 AM CDT, tech george > wrote: >> >> Hello, >> >> Sorry for the

Re: Negative Stock Prevention

2022-08-31 Thread Ammar Mohammed
I don't think you need that constraint after using the PositiveIntegerField . On Thu, 1 Sep 2022, 02:45 Ryan Nowakowski, wrote: > I don't see any error. Did you forget to post it? > > On August 31, 2022 5:57:32 AM CDT, tech george > wrote: >> >> Hello, >> >> Sorry for the late reply. >> >> I c

Re: Negative Stock Prevention

2022-08-31 Thread Ryan Nowakowski
I don't see any error. Did you forget to post it? On August 31, 2022 5:57:32 AM CDT, tech george wrote: >Hello, > >Sorry for the late reply. > >I changed the models as below and added checkConstraint , But when I >migrate I get the below error. > >What am I still doing wrong? > >class Stock(model

Re: Negative Stock Prevention

2022-08-31 Thread tech george
Hello, Sorry for the late reply. I changed the models as below and added checkConstraint , But when I migrate I get the below error. What am I still doing wrong? class Stock(models.Model): quantity = models.PositiveIntegerField(default='0', blank=True, null=True) reorder_level = models.

Re: Negative Stock Prevention

2022-08-30 Thread Thomas Couch
I don't see where you define the quantity variable, should that be instance.quantity? Also, presumably you want to check if quantity is greater than or equal to qu rather than 0. Try changing `if quantity > 0` to `if instance.quantity >= qu` On Tuesday, August 30, 2022 at 3:44:51 PM UTC+1 Ryan

Re: Negative Stock Prevention

2022-08-30 Thread Ryan Nowakowski
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 =

Re: Negative Stock Prevention

2022-08-30 Thread Derek
As a start, the logic checks for the model should not be in views.py but rather with the model object (in models.py). You can extend the save() method, for example, and add the checks there. See: * https://docs.djangoproject.com/en/4.1/ref/models/instances/#saving-objects * https://docs.djang

Negative Stock Prevention

2022-08-29 Thread tech george
Hello, 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_l