Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions account_statement_import_file/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import account_journal
from . import account_bank_statement_line
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from odoo import models


class AccountBankStatementLine(models.Model):
_inherit = "account.bank.statement.line"

def _get_amounts_with_currencies(self):
(
company_amount,
company_currency,
journal_amount,
journal_currency,
transaction_amount,
foreign_currency,
) = super()._get_amounts_with_currencies()
if self.env.context.get("from_stmt_import", False) and self.foreign_currency_id:
if self.foreign_currency_id == company_currency:
company_currency = self.journal_id.company_id.currency_id
journal_currency = self.journal_id.currency_id or company_currency
company_amount = self.amount_currency
foreign_currency = journal_currency
transaction_amount = self.amount
elif journal_currency == company_currency:
journal_amount = self.amount_currency
journal_currency = foreign_currency
return (
company_amount,
company_currency,
journal_amount,
journal_currency,
transaction_amount,
foreign_currency,
)
1 change: 1 addition & 0 deletions account_statement_import_file/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_account_statement_import_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from odoo.tests import tagged

from odoo.addons.account.tests.common import AccountTestInvoicingCommon


@tagged("post_install", "-at_install")
class TestAccountStatementImportFile(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.eur_currency = cls.env.ref("base.EUR")
cls.usd_currency = cls.env.ref("base.USD")
cls.company = cls.env.company
cls.bank_journal_eur = cls.env["account.journal"].create(
{
"name": "Bank EUR Test",
"type": "bank",
"code": "BNK_T",
"currency_id": cls.eur_currency.id,
}
)

def test_eur_journal_usd_foreign(self):
statement_line = (
self.env["account.bank.statement.line"]
.with_context(from_stmt_import=True)
.create(
{
"journal_id": self.bank_journal_eur.id,
"amount": 100.00,
"foreign_currency_id": self.usd_currency.id,
"amount_currency": 110.00,
}
)
)
move = statement_line.move_id
self.assertTrue(move)
bank_line = move.line_ids.filtered(
lambda line: line.account_id.account_type == "asset_cash"
)
counterpart_line = move.line_ids - bank_line
self.assertEqual(counterpart_line.credit, 110.0)
self.assertEqual(counterpart_line.amount_currency, -100.0)
self.assertEqual(bank_line.debit, 110.0)
self.assertEqual(bank_line.amount_currency, 100.0)
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def import_single_statement(self, single_statement_data, result):
# Prepare statement data to be used for bank statements creation
stmts_vals = self._complete_stmts_vals(stmts_vals, journal, account_number)
# Create the bank statements
self._create_bank_statements(stmts_vals, result)
self.with_context(from_stmt_import=True)._create_bank_statements(
stmts_vals, result
)
# Now that the import worked out, set it as the bank_statements_source
# of the journal
if journal.bank_statements_source != "file_import_oca":
Expand Down
1 change: 0 additions & 1 deletion account_statement_import_sheet_file/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

from . import account_statement_import_sheet_mapping
from . import account_statement_import_sheet_parser
from . import account_bank_statement_line
from . import account_statement_import
from . import account_journal

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,3 @@ def _create_bank_statements(self, stmts_vals, result):
amount = sum(statement.line_ids.mapped("amount"))
statement.balance_end_real = statement.balance_start + amount
return res

def import_single_statement(self, single_statement_data, result):
return super(
AccountStatementImport, self.with_context(from_stmt_import=True)
).import_single_statement(single_statement_data, result)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -780,64 +780,3 @@ def test_skip_empty_lines(self):
self.assertEqual(statement.balance_start, 0.0)
self.assertEqual(statement.balance_end_real, 2291.5)
self.assertEqual(statement.balance_end, 2291.5)

def test_eur_journal_usd_foreign(self):
statement_map = self.AccountStatementImportSheetMapping.create(
{
"name": "Test Only - Foreign Currency CSV Mapping",
"timestamp_format": "%Y-%m-%d",
"debit_value": "refund",
"credit_value": "charge",
"timestamp_column": "Payout Date",
"currency_column": "Presentment Currency",
"amount_type": "simple_value",
"amount_column": "Presentment Amount",
"original_currency_column": "Currency",
"original_amount_column": "Amount",
"description_column": "Checkout",
"reference_column": "Order",
"float_thousands_sep": "none",
"float_decimal_sep": "dot",
}
)
bank_journal_eur = self.AccountJournal.create(
{
"name": "Bank eur",
"type": "bank",
"code": "BNK_eur",
"currency_id": self.currency_eur.id,
"company_id": self.company.id,
}
)
file_name = "fixtures/statement_eur.csv"
file_data = self._data_file(file_name)
wizard = (
self.env["account.statement.import"]
.with_context(journal_id=bank_journal_eur.id)
.create(
{
"statement_file": file_data,
"statement_filename": "statement.csv",
"sheet_mapping_id": statement_map.id,
}
)
)
wizard.with_context(
account_statement_import_sheet_file_test=True
).import_file_button()
statement = self.env["account.bank.statement"].search(
[("journal_id", "=", bank_journal_eur.id)], limit=1
)
self.assertTrue(statement)
self.assertEqual(len(statement.line_ids), 1)
line = statement.line_ids
move = line.move_id
self.assertTrue(move)
bank_line = move.line_ids.filtered(
lambda line: line.account_id.account_type == "asset_cash"
)
counterpart_line = move.line_ids - bank_line
self.assertEqual(counterpart_line.credit, 100)
self.assertEqual(counterpart_line.amount_currency, -95.0)
self.assertEqual(bank_line.debit, 100.00)
self.assertEqual(bank_line.amount_currency, 95.0)