From b240f53bc730f7ca47da05937a131536f7040559 Mon Sep 17 00:00:00 2001 From: Ilia Konnov Date: Mon, 30 Dec 2024 00:29:02 +0700 Subject: [PATCH] Preserve transactions' currency code --- lunchable_splitlunch/lunchmoney_splitwise.py | 10 ++++++++-- lunchable_splitlunch/models.py | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lunchable_splitlunch/lunchmoney_splitwise.py b/lunchable_splitlunch/lunchmoney_splitwise.py index 83b8075..32a55ec 100644 --- a/lunchable_splitlunch/lunchmoney_splitwise.py +++ b/lunchable_splitlunch/lunchmoney_splitwise.py @@ -203,7 +203,7 @@ def split_a_transaction(cls, amount: Union[float, int]) -> Tuple[float, ...]: return amounts_due def create_self_paid_expense( - self, amount: float, description: str, date: datetime.date + self, amount: float, currency_code: str, description: str, date: datetime.date ) -> SplitLunchExpense: """ Create and Submit a Splitwise Expense @@ -230,6 +230,7 @@ def create_self_paid_expense( amount=amount ) new_expense.setCost(cost=amount) + new_expense.setCurrencyCode(currency_code=currency_code) # CONFIGURE PRIMARY USER primary_user = splitwise.user.ExpenseUser() primary_user.setId(id=self.current_user.id) @@ -255,7 +256,7 @@ def create_self_paid_expense( return pydantic_response def create_expense_on_behalf_of_partner( - self, amount: float, description: str, date: datetime.date + self, amount: float, currency_code: str, description: str, date: datetime.date ) -> SplitLunchExpense: """ Create and Submit a Splitwise Expense on behalf of your financial partner. @@ -281,6 +282,7 @@ def create_expense_on_behalf_of_partner( new_expense.setGroupId(self.financial_group) # GET AND SET AMOUNTS OWED new_expense.setCost(cost=amount) + new_expense.setCurrencyCode(currency_code=currency_code) # CONFIGURE PRIMARY USER primary_user = splitwise.user.ExpenseUser() primary_user.setId(id=self.current_user.id) @@ -450,6 +452,7 @@ def splitwise_to_pydantic(self, expense: splitwise.Expense) -> SplitLunchExpense splitwise_id=expense.id, original_amount=expense.cost, financial_impact=financial_impact, + currency_code=expense.currency_code, self_paid=self_paid, description=expense.description, category=expense.category.name, @@ -795,6 +798,7 @@ def make_splitlunch_import( description = f"{transaction.payee} - {transaction.notes}" new_transaction = self.create_self_paid_expense( amount=transaction.amount, + currency_code=transaction.currency.upper(), description=description, date=transaction.date, ) @@ -881,6 +885,7 @@ def make_splitlunch_direct_import( description = f"{transaction.payee} - {transaction.notes}" new_transaction = self.create_expense_on_behalf_of_partner( amount=transaction.amount, + currency_code=transaction.currency.upper(), description=description, date=transaction.date, ) @@ -957,6 +962,7 @@ def splitwise_to_lunchmoney( date=new_date, payee=splitwise_transaction.description, amount=splitwise_transaction.financial_impact, + currency=splitwise_transaction.currency_code.lower(), asset_id=self.splitwise_asset.id, external_id=str(splitwise_transaction.splitwise_id), ) diff --git a/lunchable_splitlunch/models.py b/lunchable_splitlunch/models.py index 3c32691..d07b60a 100644 --- a/lunchable_splitlunch/models.py +++ b/lunchable_splitlunch/models.py @@ -17,6 +17,7 @@ class SplitLunchExpense(LunchableModel): original_amount: float self_paid: bool financial_impact: float + currency_code: str description: str category: str details: Optional[str] = None