Ошибка Джанго: [] - PullRequest
       31

Ошибка Джанго: []

1 голос
/ 05 июня 2019

Я сделал следующий сигнал в моем проекте:

@receiver(pre_save, sender=group1)
@disable_for_loaddata
def total_closing_group1(sender,instance,*args,**kwargs):
    total_group_closing_deb_po = instance.master_group.filter(ledgergroups__Closing_balance__gte=0,balance_nature='Debit').aggregate(the_sum=Coalesce(Sum('ledgergroups__Closing_balance'), Value(0)))['the_sum']
    total_group_closing_deb_neg = instance.master_group.filter(ledgergroups__Closing_balance__lt=0,balance_nature='Debit').aggregate(the_sum=Coalesce(Sum('ledgergroups__Closing_balance'), Value(0)))['the_sum']
    total_group_closing_po_cre = instance.master_group.filter(ledgergroups__Closing_balance__gte=0,balance_nature='Credit').aggregate(the_sum=Coalesce(Sum('ledgergroups__Closing_balance'), Value(0)))['the_sum']
    total_group_closing_neg_cre = instance.master_group.filter(ledgergroups__Closing_balance__lt=0,balance_nature='Credit').aggregate(the_sum=Coalesce(Sum('ledgergroups__Closing_balance'), Value(0)))['the_sum']
    total_closing_deb_po = instance.ledgergroups.filter(Closing_balance__gte=0,group1_Name__balance_nature='Debit').aggregate(the_sum=Coalesce(Sum('Closing_balance'), Value(0)))['the_sum']
    total_closing_deb_ne = instance.ledgergroups.filter(Closing_balance__lt=0,group1_Name__balance_nature='Debit').aggregate(the_sum=Coalesce(Sum('Closing_balance'), Value(0)))['the_sum']
    total_closing_cre_po = instance.ledgergroups.filter(Closing_balance__gte=0,group1_Name__balance_nature='Credit').aggregate(the_sum=Coalesce(Sum('Closing_balance'), Value(0)))['the_sum']
    total_closing_cre_ne = instance.ledgergroups.filter(Closing_balance__lt=0,group1_Name__balance_nature='Credit').aggregate(the_sum=Coalesce(Sum('Closing_balance'), Value(0)))['the_sum']
    if total_group_closing_deb_po != None and total_group_closing_neg_cre != None and total_closing_deb_po != None and total_closing_cre_ne != None:
        instance.positive_closing = total_group_closing_deb_po + abs(total_group_closing_neg_cre) + total_closing_deb_po + abs(total_closing_cre_ne)
    if total_group_closing_po_cre != None and total_group_closing_deb_neg != None and total_closing_cre_po != None and total_closing_deb_ne != None:    
        instance.negative_closing = total_group_closing_po_cre + abs(total_group_closing_deb_neg) + total_closing_cre_po + abs(total_closing_deb_ne)

Мои модели:

class Group1(models.Model):   
    group_name = models.CharField(max_length=32)    
    master = models.ForeignKey("self",on_delete=models.CASCADE,related_name='master_group',null=True)    
    negative_closing = models.DecimalField(max_digits=10,default=0,decimal_places=2,null=True)    
    positive_closing = models.DecimalField(max_digits=10,default=0,decimal_places=2,null=True)


class Ledger1(models.Model):
    name            = models.CharField(max_length=32)
    group1_name     = models.ForeignKey(Group1,on_delete=models.CASCADE,null=True,related_name='ledgergroups')
    closing_balance = models.DecimalField(default=0.00,max_digits=10,decimal_places=2,blank=True)

Вначале все работало нормально, но внезапно я увеличивал нагрузку на базу данных, помещая данные в поля.

выдает ошибку [<class 'decimal.InvalidOperation'>].

Что означает эта ошибка?

Любая идея, кто угодно

Спасибо

...