Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update models.py #105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion accounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,45 @@ class CurrencyChoices(models.TextChoices):
USD = 'USD', 'USD'
IQD = 'IQD', 'IQD'


class Balance:
def __init__(self, balances):
balanceIQD = 0
balanceUSD = 0
for i in balances:
if i['currency'] == 'USD':
balanceUSD = i['sum']
if i['currency'] == 'IQD':
balanceIQD = i['sum']

self.balanceUSD = balanceUSD
self.balanceIQD = balanceIQD

def __add__(self, other):
self.balanceIQD += other.balanceIQD
self.balanceUSD += other.balanceUSD
return [{
'currency': 'IQD',
'sum': self.balanceIQD
}, {
'currency': 'USD',
'sum': self.balanceUSD
}]

def __gt__(self, other):
bIQD = self.balanceIQD > other.balanceIQD
bUSD = self.balanceUSD > other.balanceUSD
return bIQD, bUSD

def __lt__(self, other):
bIQD = self.balanceIQD < other.balanceIQD
bUSD = self.balanceUSD < other.balanceUSD
return bIQD, bUSD

def is_zero(self):
bIQD = True if self.balanceIQD == 0 else False
bUSD = True if self.balanceUSD == 0 else False
return bIQD, bUSD

class Account(models.Model):
parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.SET_NULL)
type = models.CharField(max_length=255, choices=AccountTypeChoices.choices)
Expand Down