

@receiver(post_save, sender=StockRecord)
def update_stock_alerts(sender, instance, created, **kwargs):
    '\n    Update low-stock alerts\n    '
    if (created or kwargs.get('raw', False)):
        return
    stockrecord = instance
    try:
        alert = StockAlert.objects.get(stockrecord=stockrecord, status=StockAlert.OPEN)
    except StockAlert.DoesNotExist:
        alert = None
    if (alert.is_below_threshold and (not alert)):
        StockAlert.objects.create(stockrecord=stockrecord, threshold=stockrecord.low_stock_threshold)
    elif ((not stockrecord.is_below_threshold) and alert):
        alert.close()

dataset/ETHPy150Open django-oscar/django-oscar/src/oscar/apps/partner/receivers.py update_stock_alerts/VarMisuse@90/125 `stockrecord`->`alert`