Merge pull request #1 from mvkashyap/fix_stat

Fix the total spend bug with prefix R-
This commit is contained in:
Rebecca J 2022-12-07 12:52:16 -05:00 committed by GitHub
commit fe4a3b084a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View file

@ -28,6 +28,7 @@ def upgrade():
"external_link", sa.UnicodeText(), autoincrement=False, nullable=True "external_link", sa.UnicodeText(), autoincrement=False, nullable=True
), ),
sa.Column("archive", sa.Integer(), autoincrement=False, nullable=True), sa.Column("archive", sa.Integer(), autoincrement=False, nullable=True),
sa.Column("is_reimbursement", sa.Boolean(), nullable=True),
sa.Column( sa.Column(
"transaction_id", sa.BigInteger(), autoincrement=False, nullable=False "transaction_id", sa.BigInteger(), autoincrement=False, nullable=False
), ),

View file

@ -49,6 +49,7 @@ def upgrade():
sa.Column("date", sa.Date(), nullable=True), sa.Column("date", sa.Date(), nullable=True),
sa.Column("what", sa.UnicodeText(), nullable=True), sa.Column("what", sa.UnicodeText(), nullable=True),
sa.Column("archive", sa.Integer(), nullable=True), sa.Column("archive", sa.Integer(), nullable=True),
sa.Column("is_reimbursement", sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(["archive"], ["archive.id"]), sa.ForeignKeyConstraint(["archive"], ["archive.id"]),
sa.ForeignKeyConstraint(["payer_id"], ["person.id"]), sa.ForeignKeyConstraint(["payer_id"], ["person.id"]),
sa.PrimaryKeyConstraint("id"), sa.PrimaryKeyConstraint("id"),

View file

@ -158,6 +158,8 @@ class Project(db.Model):
""" """
monthly = defaultdict(lambda: defaultdict(float)) monthly = defaultdict(lambda: defaultdict(float))
for bill in self.get_bills_unordered().all(): for bill in self.get_bills_unordered().all():
# if (bill.is_reimbursement == False):
if (not bill.what.startswith("R-")):
monthly[bill.date.year][bill.date.month] += bill.converted_amount monthly[bill.date.year][bill.date.month] += bill.converted_amount
return monthly return monthly
@ -677,6 +679,7 @@ class Bill(db.Model):
original_currency = db.Column(db.String(3)) original_currency = db.Column(db.String(3))
converted_amount = db.Column(db.Float) converted_amount = db.Column(db.Float)
is_reimbursement = db.Column(db.Boolean)
archive = db.Column(db.Integer, db.ForeignKey("archive.id")) archive = db.Column(db.Integer, db.ForeignKey("archive.id"))
@ -692,6 +695,7 @@ class Bill(db.Model):
payer_id: int = None, payer_id: int = None,
project_default_currency: str = "", project_default_currency: str = "",
what: str = "", what: str = "",
is_reimbursement:bool = False
): ):
super().__init__() super().__init__()
self.amount = amount self.amount = amount
@ -701,6 +705,7 @@ class Bill(db.Model):
self.owers = owers self.owers = owers
self.payer_id = payer_id self.payer_id = payer_id
self.what = what self.what = what
self.is_reimbursement = is_reimbursement
self.converted_amount = self.currency_helper.exchange_currency( self.converted_amount = self.currency_helper.exchange_currency(
self.amount, self.original_currency, project_default_currency self.amount, self.original_currency, project_default_currency
) )
@ -718,6 +723,7 @@ class Bill(db.Model):
"external_link": self.external_link, "external_link": self.external_link,
"original_currency": self.original_currency, "original_currency": self.original_currency,
"converted_amount": self.converted_amount, "converted_amount": self.converted_amount,
"is_reimbursement": self.is_reimbursement,
} }
def pay_each_default(self, amount): def pay_each_default(self, amount):