From e05983dbcdd6bf5d8fc7b010fdab66b4c67caf42 Mon Sep 17 00:00:00 2001 From: Andhitia Rama Date: Mon, 19 Aug 2024 15:09:58 +0700 Subject: [PATCH] [UPD] ssi_voucher_mixin * Memperbaiki perhitungan realized gain/loss --- .../models/voucher_line_mixin.py | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/ssi_voucher_mixin/models/voucher_line_mixin.py b/ssi_voucher_mixin/models/voucher_line_mixin.py index be683ee..5017aa7 100644 --- a/ssi_voucher_mixin/models/voucher_line_mixin.py +++ b/ssi_voucher_mixin/models/voucher_line_mixin.py @@ -173,10 +173,15 @@ def _compute_amount(self): def _get_debit_credit(self): self.ensure_one() debit = credit = 0.0 - if self.move_line_id: - amount = self.amount_company_currency_move_date - else: - amount = self.amount_company_currency_voucher_date + + # TODO: + # if self.move_line_id: + # amount = self.amount_company_currency_move_date + # else: + # amount = self.amount_company_currency_voucher_date + + amount = self.amount_company_currency_voucher_date + if self.type == "dr": if amount > 0: debit = abs(amount) @@ -194,18 +199,32 @@ def _get_currency_exchange_information(self): debit = credit = 0.0 amount = self.amount_diff_in_company_currency company = self.env.user.company_id - if (self.type == "dr" and amount > 0.0) or (self.type == "cr" and amount < 0.0): + if self.type == "dr" and amount > 0.0: + credit = abs(amount) + account_id = ( + company.expense_currency_exchange_account_id + and company.expense_currency_exchange_account_id.id + or False + ) + elif self.type == "dr" and amount < 0.0: debit = abs(amount) account_id = ( company.expense_currency_exchange_account_id and company.expense_currency_exchange_account_id.id or False ) - else: + elif self.type == "cr" and amount < 0.0: credit = abs(amount) account_id = ( - company.income_currency_exchange_account_id - and company.income_currency_exchange_account_id.id + company.expense_currency_exchange_account_id + and company.expense_currency_exchange_account_id.id + or False + ) + elif self.type == "cr" and amount > 0.0: + debit = abs(amount) + account_id = ( + company.expense_currency_exchange_account_id + and company.expense_currency_exchange_account_id.id or False ) return (debit, credit, account_id)