Skip to content

Commit

Permalink
[ADD] Addon: account_statement_import_ofx_invert_type
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiago370 committed Dec 26, 2024
1 parent bfffe11 commit 6555bdb
Show file tree
Hide file tree
Showing 10 changed files with 163 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",
"website": "https://github.com/KMEE/kmee-odoo-addons",
"depends": [
"account_statement_import_ofx",
],
"data": [
"views/res_config_settings.xml",
],
"demo": [],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_config_settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):

_inherit = "res.config.settings"

flip_transactions_ofx = fields.Boolean(
string="Enable Transaction Flip",
help="""Enable or disable the feature to flip credit/debit
transaction types during OFX import.""",
)

def set_values(self):
super().set_values()
self.env["ir.config_parameter"].sudo().set_param(
"account_statement_import_ofx_invert_type.flip_transactions_ofx",
str(self.flip_transactions_ofx),
)

def get_values(self):
res = super(ResConfigSettings, self).get_values()
res.update(
flip_transactions_ofx=self.env["ir.config_parameter"]
.sudo()
.get_param(
"account_statement_import_ofx_invert_type.flip_transactions_ofx",
default="False",
)
== "True"
)
return res
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 KMEE
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="view_account_statement_import_config" model="ir.ui.view">
<field
name="name"
>res.config.settings.view.form.inherit.account_statement_import</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="account.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath
expr="//div[div[field[@name='module_account_bank_statement_import_ofx']]]"
position="after"
>
<div class="col-12 col-lg-6 o_setting_box" title="">
<div class="o_setting_left_pane">
<field name="flip_transactions_ofx" />
</div>
<div class="o_setting_right_pane">
<label
for="flip_transactions_ofx"
string="Flip Transactions OFX"
/>
<div class="text-muted">
Flip transactions statements in OFX
</div>
</div>
</div>
</xpath>
</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,34 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

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)
flip_transactions_ofx = (
self.env["ir.config_parameter"]
.sudo()
.get_param(
"account_statement_import_ofx_invert_type.flip_transactions_ofx",
default="False",
)
== "True"
)
if ofx and flip_transactions_ofx:
for transaction in ofx.account.statement.transactions:
if transaction.type == "credit":
transaction.type = "debit"
transaction.amount = transaction.amount * (-1)
elif transaction.type == "debit":
transaction.type = "credit"
transaction.amount = transaction.amount * (-1)
else:
pass

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 6555bdb

Please sign in to comment.