From 6f3a389e003f5a5c89117f98725d1654c41b4d84 Mon Sep 17 00:00:00 2001 From: GingLuo Date: Tue, 6 Dec 2022 17:48:12 -0500 Subject: [PATCH] Fix the total spend bug with prefix R- --- ihatemoney/migrations/versions/2dcb0c0048dc_autologger.py | 1 + ihatemoney/migrations/versions/b9a10d5d63ce_.py | 1 + ihatemoney/models.py | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ihatemoney/migrations/versions/2dcb0c0048dc_autologger.py b/ihatemoney/migrations/versions/2dcb0c0048dc_autologger.py index b0b4f44c..366e94e2 100644 --- a/ihatemoney/migrations/versions/2dcb0c0048dc_autologger.py +++ b/ihatemoney/migrations/versions/2dcb0c0048dc_autologger.py @@ -28,6 +28,7 @@ def upgrade(): "external_link", sa.UnicodeText(), autoincrement=False, nullable=True ), sa.Column("archive", sa.Integer(), autoincrement=False, nullable=True), + sa.Column("is_reimbursement", sa.Boolean(), nullable=True), sa.Column( "transaction_id", sa.BigInteger(), autoincrement=False, nullable=False ), diff --git a/ihatemoney/migrations/versions/b9a10d5d63ce_.py b/ihatemoney/migrations/versions/b9a10d5d63ce_.py index 3c927804..3e0b4c1c 100644 --- a/ihatemoney/migrations/versions/b9a10d5d63ce_.py +++ b/ihatemoney/migrations/versions/b9a10d5d63ce_.py @@ -49,6 +49,7 @@ def upgrade(): sa.Column("date", sa.Date(), nullable=True), sa.Column("what", sa.UnicodeText(), nullable=True), sa.Column("archive", sa.Integer(), nullable=True), + sa.Column("is_reimbursement", sa.Boolean(), nullable=True), sa.ForeignKeyConstraint(["archive"], ["archive.id"]), sa.ForeignKeyConstraint(["payer_id"], ["person.id"]), sa.PrimaryKeyConstraint("id"), diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 10615d42..fc806118 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -158,7 +158,9 @@ class Project(db.Model): """ monthly = defaultdict(lambda: defaultdict(float)) for bill in self.get_bills_unordered().all(): - monthly[bill.date.year][bill.date.month] += bill.converted_amount + # if (bill.is_reimbursement == False): + if (not bill.what.startswith("R-")): + monthly[bill.date.year][bill.date.month] += bill.converted_amount return monthly @property @@ -677,6 +679,7 @@ class Bill(db.Model): original_currency = db.Column(db.String(3)) converted_amount = db.Column(db.Float) + is_reimbursement = db.Column(db.Boolean) archive = db.Column(db.Integer, db.ForeignKey("archive.id")) @@ -692,6 +695,7 @@ class Bill(db.Model): payer_id: int = None, project_default_currency: str = "", what: str = "", + is_reimbursement:bool = False ): super().__init__() self.amount = amount @@ -701,6 +705,7 @@ class Bill(db.Model): self.owers = owers self.payer_id = payer_id self.what = what + self.is_reimbursement = is_reimbursement self.converted_amount = self.currency_helper.exchange_currency( self.amount, self.original_currency, project_default_currency ) @@ -718,6 +723,7 @@ class Bill(db.Model): "external_link": self.external_link, "original_currency": self.original_currency, "converted_amount": self.converted_amount, + "is_reimbursement": self.is_reimbursement, } def pay_each_default(self, amount):