Skip to content

Commit

Permalink
Merge pull request #89 from kmee/16.0-add-account_statement_import_of…
Browse files Browse the repository at this point in the history
…x_invert_type

[ADD] Addon: account_statement_import_ofx_invert_type
  • Loading branch information
mileo authored Dec 31, 2024
2 parents bfffe11 + 58c1e3e commit 003b6b6
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 0 deletions.
32 changes: 32 additions & 0 deletions account_statement_import_ofx_invert_type/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
========================================
Account Statement Import Ofx Invert Type
========================================

KMEE

Purpose
=======

This module does this and that...

Explain the use case.

Configuration
=============

To configure this module, you need to:

#. Go to ...

Usage
=====

To use this module, you need to:

#. Go to ...


How to test
===========

...
2 changes: 2 additions & 0 deletions account_statement_import_ofx_invert_type/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import wizards
from . import models
18 changes: 18 additions & 0 deletions account_statement_import_ofx_invert_type/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Account Statement Import Ofx Invert Type",
"summary": """KMEE""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "KMEE,Odoo Community Association (OCA)",
"website": "https://github.com/KMEE/kmee-odoo-addons",
"depends": [
"account_statement_import_ofx",
],
"data": [
"views/account_journal.xml",
],
"demo": [],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_journal
12 changes: 12 additions & 0 deletions account_statement_import_ofx_invert_type/models/account_journal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class AccountJournal(models.Model):

_inherit = "account.journal"

reverse_balance_of_entries_ofx = fields.Boolean()
ignore_ofx_balance = fields.Boolean()
19 changes: 19 additions & 0 deletions account_statement_import_ofx_invert_type/views/account_journal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 KMEE
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.ui.view" id="account_journal_form_view">
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form" />
<field name="arch" type="xml">
<field name="account_control_ids" position="after">
<field
name="reverse_balance_of_entries_ofx"
string="Reverse Balance Of Entries OFX"
/>
<field name="ignore_ofx_balance" string="Ignore OFX Balance" />
</field>
</field>
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_statement_import
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from decimal import Decimal

from odoo import api, models


class AccountStatementImport(models.TransientModel):

_inherit = "account.statement.import"

@api.model
def _check_ofx(self, data_file):
ofx = super()._check_ofx(data_file)
journal_id = self.env["account.journal"].browse(
self.env.context.get("journal_id")
)
reverse_balance_of_entries_ofx = journal_id.reverse_balance_of_entries_ofx
ignore_ofx_balance = journal_id.ignore_ofx_balance
if ofx and journal_id:
if ignore_ofx_balance:
last_statement = self.env["account.bank.statement"].search(
[("journal_id", "=", journal_id.id)], limit=1, order="date asc"
)
balance = Decimal(last_statement.balance_end_real)
for transaction in ofx.account.statement.transactions:
if reverse_balance_of_entries_ofx:
if transaction.type == "credit":
transaction.type = "debit"
elif transaction.type == "debit":
transaction.type = "credit"
transaction.amount = transaction.amount * (-1)
else:
pass

if ignore_ofx_balance:
balance += transaction.amount

if ignore_ofx_balance:
ofx.account.statement.balance = balance
if not last_statement:
ofx.account.statement.balance = False
return ofx
6 changes: 6 additions & 0 deletions setup/account_statement_import_ofx_invert_type/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 003b6b6

Please sign in to comment.