uptodate Account_balance

75 views
Skip to first unread message

MAurice

unread,
Oct 3, 2013, 3:09:06 AM10/3/13
to django...@googlegroups.com
Hello everyone was requesting for help on this micro-finance software am developing, needed to make the account balance reflect updated  amount/value on the database when deposits/withdraws are made on either the account or loan repayment

class Branch(models.Model):
    time_stamp     =models.DateTimeField(default=datetime.datetime.now(), editable=False)
    name         =models.CharField(max_length=200)
    physical_location=models.CharField(max_length=200)
    email        =models.EmailField()

class Account(models.Model):
    account_type        =models.CharField(max_length=200, choices=ACCTYPE)
    branch            =models.ForeignKey('Branch')
    first_name            =models.CharField(max_length=200)
    last_name               =models.CharField(max_length=200)
    account_number =models.SlugField(unique=True)  
    account_current_balance =models.FloatField(max_length=255,default=0)

class Account_holder(models.Model):

    id                 =models.IntegerField(primary_key=True,default=1)
    account_id         =models.ManyToManyField(Account)
   



class Loan(models.Model):

    id = models.AutoField(primary_key=True,default=1)
    branch_cod    =models.IntegerField(blank=True, null=True)
    time_years    =models.DecimalField(default=1.0, max_digits=10, decimal_places=4)
    loan_number     =models.SlugField(unique=True)
    account_name    =models.ForeignKey(Account)
    loan_amount    =models.DecimalField(default=0.0, max_digits=10, decimal_places=2)
    interest_rate    =models.DecimalField(default=0.0, max_digits=10, decimal_places=2)
    interest_charged = models.DecimalField(default=0.0, max_digits=10, decimal_places=2, editable=False)
    required_payement = models.DecimalField(default=1.0, max_digits=10, decimal_places=2)

class statement(models.Model):

    account_id =models.ForeignKey(Account)
     date = models.DateTimeField(default=datetime.datetime.now(), editable=False)
     deposit = models.PositiveIntegerField(null=True, default=0)
     withdraw = models.PositiveIntegerField(null=True, default=0)
     description =models.TextField(max_length=200)
     current_balance = models.FloatField(max_length=200, editable=False)
   
    def save(self, *args, **kwargs):
         self.current_balance =  self.account_id.average_balance + self.credit - self.debit
                 self.average_balance = self.account_id.average_balance + self.credit - self.debit -self.minimum_balance
         super(statement,self).save(*args, **kwargs)

 class Savant_user(models.Model):

      user =models.OneToOneField(User)
      branch =models.ManyToManyField('Branch')
    
             

      def create_Dashboard_user_callback(sender, instance, **kwargs):
          Dashboard, new = Savant_user.objects.get_or_create(user=instance)
          post_save.connect(create_Dashboard_user_callback, User)

Leonardo Giordani

unread,
Oct 3, 2013, 5:29:39 AM10/3/13
to django...@googlegroups.com
Maurice,

please remember not everyone on this ML knows finance and noone knows your application but you.
Moreover, people on ML cannot spend hours trying to figure out what is your problem: sometimes just solving the problem needs a lot of work, so make things easy.

You posted your models, but I think you are implementing some views or at least using them in some code.
Can you give some details about the procedure you are implementing and the exact issue tou are facing?

Cheers,

Leo

Leonardo Giordani
Author of The Digital Cat
My profile on About.me - My GitHub page - My Coderwall profile


2013/10/3 MAurice <mjos...@gmail.com>

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/585a5845-9111-492d-a0c9-10342ee2bfbc%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

MAurice

unread,
Oct 3, 2013, 10:42:48 AM10/3/13
to django...@googlegroups.com
Am creating this project in that a client has an account in a micro-finance and can also Take Loans which loan is credited onto this very account.
The problem is am trying to find a way of having an Account_balance which will be changing when deposits and withdrawals are made to the account
and also when loan payments are made. These are supposed to be reflected on the account statement. am having issues with this account_balance being updated
Thanks

C. Kirby

unread,
Oct 3, 2013, 1:42:12 PM10/3/13
to django...@googlegroups.com
Use signals:
 https://docs.djangoproject.com/en/dev/topics/signals/

post_save check the amount deposited or withdrawn and update the balance

Maurice J Elagu

unread,
Oct 7, 2013, 1:04:10 PM10/7/13
to django...@googlegroups.com
The signals are doin the notifications but not updating
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/_RIPOaIO6S8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a13ccfd8-d34d-42a2-88ea-54d687e806b9%40googlegroups.com.

Maurice J Elagu

unread,
Oct 7, 2013, 1:07:49 PM10/7/13
to django...@googlegroups.com
needed to no how to have a uniform account_balance figure(after
withdraw or deposit)

Daniel Roseman

unread,
Oct 7, 2013, 2:45:34 PM10/7/13
to django...@googlegroups.com
On Monday, 7 October 2013 18:07:49 UTC+1, MAurice wrote:
needed to no how to have a uniform account_balance figure(after
withdraw or deposit)

On 10/7/13, Maurice J Elagu <mjos...@gmail.com> wrote:
> The signals are doin the notifications but not updating


Please learn how to ask a question properly, and take some time to think about how you're asking it. Given just the information in the last two posts of yours, there is no way that anyone can help you at all. Please provide details of what you're experiencing, show some code and any errors, and explain how things are supposed to work.
--
DR.

Ovnicraft

unread,
Oct 7, 2013, 5:45:43 PM10/7/13
to django...@googlegroups.com
Hi Maurice, its very hard understood this but i give a try.

if your are working in finance-world you will need update de balance, so it implies fields 'depends' from others transactions, you named deposits/withdraws.

You can use aggregations[1] or update field 'manually'.

Regards,





--
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...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/groups/opt_out.



--
Cristian Salamea
@ovnicraft
Reply all
Reply to author
Forward
0 new messages