[MIG] account_statement_import_file: Migration to 18.0

This commit is contained in:
Duy (Đỗ Anh)
2024-11-06 11:26:08 +07:00
parent 81a06ba769
commit a13a4afc7e
10 changed files with 82 additions and 46 deletions

View File

@@ -17,13 +17,13 @@ Import Statement Files
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github
:target: https://github.com/OCA/bank-statement-import/tree/17.0/account_statement_import_file
:target: https://github.com/OCA/bank-statement-import/tree/18.0/account_statement_import_file
:alt: OCA/bank-statement-import
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/bank-statement-import-17-0/bank-statement-import-17-0-account_statement_import_file
:target: https://translation.odoo-community.org/projects/bank-statement-import-18-0/bank-statement-import-18-0-account_statement_import_file
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&target_branch=18.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -81,7 +81,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-statement-import/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_file%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_file%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
@@ -98,10 +98,23 @@ Contributors
------------
- Odoo S.A.
- Alexis de Lattre <alexis.delattre@akretion.com>
- Tecnativa - Pedro M. Baeza
- Sygel - Manuel Regidor
- Trobz <https://www.trobz.com/>
- Do Anh Duy <duyda@trobz.com>
Other credits
-------------
The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.
Maintainers
-----------
@@ -123,6 +136,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-alexis-via|
This module is part of the `OCA/bank-statement-import <https://github.com/OCA/bank-statement-import/tree/17.0/account_statement_import_file>`_ project on GitHub.
This module is part of the `OCA/bank-statement-import <https://github.com/OCA/bank-statement-import/tree/18.0/account_statement_import_file>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -6,7 +6,7 @@
{
"name": "Import Statement Files",
"category": "Accounting",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"license": "LGPL-3",
"depends": ["account_statement_import_base"],
"author": "Odoo SA, Akretion, Odoo Community Association (OCA)",

View File

@@ -3,7 +3,7 @@
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
from odoo import _, api, models
from odoo import api, models
class AccountJournal(models.Model):
@@ -28,7 +28,7 @@ class AccountJournal(models.Model):
formats_list.sort()
import_formats_str = ", ".join(formats_list)
rslt.insert(
0, ("file_import_oca", _("Import") + "(" + import_formats_str + ")")
0, ("file_import_oca", self.env._(f"Import ({import_formats_str})"))
)
return rslt

View File

@@ -2,3 +2,6 @@
- Alexis de Lattre \<<alexis.delattre@akretion.com>\>
- Tecnativa - Pedro M. Baeza
- Sygel - Manuel Regidor
- Trobz \<<https://www.trobz.com/>\>
- Do Anh Duy \<<duyda@trobz.com>\>

View File

@@ -0,0 +1 @@
The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp.

View File

@@ -8,10 +8,11 @@
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
@@ -274,7 +275,7 @@ pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@ span.option {
span.pre {
white-space: pre }
span.problematic {
span.problematic, pre.problematic {
color: red }
span.section-subtitle {
@@ -368,7 +369,7 @@ ul.auto-toc {
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:617132b3a1943c54ccad25dfc759a97108915b2d1f9d78c4c4ed5682358fdc4d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Mature" src="https://img.shields.io/badge/maturity-Mature-brightgreen.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/bank-statement-import/tree/17.0/account_statement_import_file"><img alt="OCA/bank-statement-import" src="https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/bank-statement-import-17-0/bank-statement-import-17-0-account_statement_import_file"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Mature" src="https://img.shields.io/badge/maturity-Mature-brightgreen.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/bank-statement-import/tree/18.0/account_statement_import_file"><img alt="OCA/bank-statement-import" src="https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/bank-statement-import-18-0/bank-statement-import-18-0-account_statement_import_file"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module is the successor of the module
<strong>account_bank_statement_import</strong> that was part of Odoo Community until
Odoo v13 and was moved to Odoo Enterprise for Odoo v14 (cf <a class="reference external" href="https://github.com/odoo/odoo/commit/9ba8734f15e1a292ca27b1a026e8366a91b2a8c9">this
@@ -398,7 +399,8 @@ or, for the country-specific formats, in the OCA localization projects.</p>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-6">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
</ul>
</li>
</ul>
@@ -424,7 +426,7 @@ related statement lines.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/bank-statement-import/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_file%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_file%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
@@ -443,18 +445,29 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<li>Alexis de Lattre &lt;<a class="reference external" href="mailto:alexis.delattre&#64;akretion.com">alexis.delattre&#64;akretion.com</a>&gt;</li>
<li>Tecnativa - Pedro M. Baeza</li>
<li>Sygel - Manuel Regidor</li>
<li>Trobz &lt;<a class="reference external" href="https://www.trobz.com/">https://www.trobz.com/</a>&gt;<ul>
<li>Do Anh Duy &lt;<a class="reference external" href="mailto:duyda&#64;trobz.com">duyda&#64;trobz.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-6">Other credits</a></h2>
<p>The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/alexis-via"><img alt="alexis-via" src="https://github.com/alexis-via.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/bank-statement-import/tree/17.0/account_statement_import_file">OCA/bank-statement-import</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/bank-statement-import/tree/18.0/account_statement_import_file">OCA/bank-statement-import</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>

View File

@@ -12,9 +12,7 @@ class TestAccountStatementImportFile(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.eur_currency = cls.env["res.currency"].search(
[("name", "=", "EUR"), ("active", "=", False)], limit=1
)
cls.eur_currency = cls.env.ref("base.EUR")
cls.eur_currency.write({"active": True})
cls.bank_account = cls.env["res.partner.bank"].create(
{"acc_number": "1111111111", "partner_id": cls.env.company.partner_id.id}
@@ -38,7 +36,9 @@ class TestAccountStatementImportFile(common.TransactionCase):
"bank_account_id": cls.bank_account.id,
}
)
f_path = file_path("account_statement_import_file/tests/test_file.txt")
f_path = file_path(
"account_statement_import_file/tests/samples/test_statement_import.txt"
)
file = base64.b64encode(open(f_path, "rb").read())
cls.import_wizard = (
cls.env["account.statement.import"]

View File

@@ -4,7 +4,7 @@
import base64
import logging
from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import UserError
from odoo.addons.base.models.res_bank import sanitize_account_number
@@ -34,7 +34,7 @@ class AccountStatementImport(models.TransientModel):
logger.debug("result=%s", result)
if not result["statement_ids"]:
raise UserError(
_(
self.env._(
"You have already imported this file, or this file "
"only contains already imported transactions."
)
@@ -92,32 +92,36 @@ class AccountStatementImport(models.TransientModel):
self.statement_filename,
len(parsing_data),
)
i = 0
for single_statement_data in parsing_data:
i += 1
for idx, single_statement_data in enumerate(parsing_data, start=1):
logger.debug(
"account %d: single_statement_data=%s", i, single_statement_data
"account %d: single_statement_data=%s", idx, single_statement_data
)
self.import_single_statement(single_statement_data, result)
def import_single_statement(self, single_statement_data, result):
if not isinstance(single_statement_data, tuple):
raise UserError(
_("The parsing of the statement file returned an invalid result.")
self.env._(
"The parsing of the statement file returned an invalid result."
)
)
currency_code, account_number, stmts_vals = single_statement_data
# Check raw data
if not self._check_parsed_data(stmts_vals):
return False
if not currency_code:
raise UserError(_("Missing currency code in the bank statement file."))
raise UserError(
self.env._("Missing currency code in the bank statement file.")
)
# account_number can be None (example : QIF)
currency = self._match_currency(currency_code)
journal = self._match_journal(account_number, currency)
if not journal.default_account_id:
raise UserError(
_("The Bank Accounting Account is not set on the journal '%s'.")
% journal.display_name
self.env._(
"The Bank Accounting Account is not set on the journal '%s'.",
journal.display_name,
)
)
# Prepare statement data to be used for bank statements creation
stmts_vals = self._complete_stmts_vals(stmts_vals, journal, account_number)
@@ -161,7 +165,7 @@ class AccountStatementImport(models.TransientModel):
a list of triplets.
"""
raise UserError(
_(
self.env._(
"This bank statement file format is not supported.\n"
"Did you install the Odoo module to support this format?"
)
@@ -193,11 +197,11 @@ class AccountStatementImport(models.TransientModel):
)
if not currency:
raise UserError(
_(
self.env._(
"The bank statement file uses currency '%s' "
"but there is no such currency in Odoo."
"but there is no such currency in Odoo.",
currency_code,
)
% currency_code
)
return currency
@@ -208,7 +212,7 @@ class AccountStatementImport(models.TransientModel):
if not account_number: # exemple : QIF
if not self.env.context.get("journal_id"):
raise UserError(
_(
self.env._(
"The format of this bank statement file doesn't "
"contain the bank account number, so you must "
"start the wizard from the right bank journal "
@@ -234,7 +238,7 @@ class AccountStatementImport(models.TransientModel):
if journal and ctx_journal_id and journal.id != ctx_journal_id:
ctx_journal = journal_obj.browse(ctx_journal_id)
raise UserError(
_(
self.env._(
"The journal found for the file (%(journal_match)s) is"
" different from the selected journal "
"(%(journal_selected)s).",
@@ -252,7 +256,7 @@ class AccountStatementImport(models.TransientModel):
)
if bank_accounts:
raise UserError(
_(
self.env._(
"The bank account with number '%(account_number)s'"
" exists in Odoo but it is not set on any bank "
"journal. You should set it on the related bank "
@@ -263,7 +267,7 @@ class AccountStatementImport(models.TransientModel):
)
else:
raise UserError(
_(
self.env._(
"Could not find any bank account with number "
"'%(account_number)s' linked to partner '"
"%(partner_name)s'. You should create the bank "
@@ -281,7 +285,7 @@ class AccountStatementImport(models.TransientModel):
journal_currency = journal.currency_id or company.currency_id
if journal_currency != currency:
raise UserError(
_(
self.env._(
"The currency of the bank statement (%(currency_name)s) "
"is not the same as the currency of the journal "
"'%(journal_name)s' (%(journal_currency_name)s).",
@@ -303,7 +307,7 @@ class AccountStatementImport(models.TransientModel):
)
journal._statement_line_import_update_hook(lvals, speeddict)
if not lvals.get("payment_ref"):
raise UserError(_("Missing payment_ref on a transaction."))
raise UserError(self.env._("Missing payment_ref on a transaction."))
return stmts_vals
def _create_bank_statements(self, stmts_vals, result):
@@ -354,10 +358,12 @@ class AccountStatementImport(models.TransientModel):
num_ignored = len(existing_st_line_ids)
if num_ignored > 0:
if num_ignored == 1:
msg = _("1 transaction had already been imported and was ignored.")
msg = self.env._(
"1 transaction had already been imported and was ignored."
)
else:
msg = (
_("%d transactions had already been imported and were ignored.")
% num_ignored
msg = self.env._(
"%d transactions had already been imported and were ignored.",
num_ignored,
)
result["notifications"].append(msg)

View File

@@ -40,7 +40,7 @@
<record id="account_statement_import_menu" model="ir.ui.menu">
<field name="name">Import Statement</field>
<field name="parent_id" ref="account.menu_finance_entries_actions" />
<field name="parent_id" ref="account.menu_finance_entries" />
<field name="action" ref="account_statement_import_action" />
<field name="sequence" eval="70" />
</record>