Hello, I want to calculate cashflow in my application. I have a cashflow
model shown below. My problem is with the save method. I want on clicking
save in the django admin, the list display should include all the different
amounts from invoices, receipts and expenses. However, for cases where
either a receipt or an invoice or an expense is not applicable, i.e, when
the field is None, such field should be instantiated to 0. However, the
save method doesn't work. Waht could be the problem.
class CashFlow(models.Model):
cashflow_number=models.CharField(max_length=25)
receipt_number=models.ForeignKey(Receipt,null=True,blank=True)
invoice_receipt_number=models.ForeignKey(ReceiptsForInvoice,null=True,blank=True)
expense_receipt_number=models.ForeignKey(Expense,null=True,blank=True)
date=models.DateTimeField()
amount_paid=models.IntegerField("Amount Paid From Receipts")
ir_amount_paid=models.FloatField("Amount Paid From Invoices")
amount=models.IntegerField("Expense Amounts")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering=['date']
@property
def rows(self):
return self.row_set.count()
@property
def name(self):
return "%s" %self.cashflow_number
def save(self,*args,**kwargs):
if (self.amount_paid==None and self.ir_amount_paid==None and
self.amount==None):
self.amount_paid=0
self.ir_amount_paid=0
self.amount=0
elif (self.amount_paid==None and self.ir_amount_paid!=None and
self.amount==None):
self.amount_paid=0
self.ir_amount_paid=self.invoice_receipt_number.ir_amount_paid
self.amount=0
elif (self.amount_paid==None and self.ir_amount_paid!=None and
self.amount!=None):
self.amount_paid=0
self.ir_amount_paid=self.invoice_receipt_number.ir_amount_paid
self.amount=self.expense_receipt_number.amount
elif (self.amount_paid==None and self.ir_amount_paid==None and
self.amount!=None):
self.amount_paid=0
self.ir_amount_paid=0
self.amount=self.expense_receipt_number.amount
elif (self.amount_paid!=None and self.ir_amount_paid==None and
self.amount==None):
self.amount_paid=self.receipt_number.amount_paid
self.ir_amount_paid=0
self.amount=0
elif (self.amount_paid!=None and self.ir_amount_paid!=None and
self.amount==None):
self.amount_paid=self.receipt_number.amount_paid
self.ir_amount_paid=self.invoice_receipt_number.ir_amount_paid
self.amount=0
elif (self.amount_paid!=None and self.ir_amount_paid!=None and
self.amount!=None):
self.amount_paid=self.receipt_number.amount_paid
self.ir_amount_paid=self.invoice_receipt_number.ir_amount_paid
self.amount=self.expense_receipt_number.amount
else:
self.amount_paid=self.receipt_number.amount_paid
self.ir_amount_paid=0
self.amount=self.expense_receipt_number.amount
super(CashFlow,self).save(*args,**kwargs)
def __unicode__(self):
return self.name
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.