Skip to content

Commit

Permalink
[MIG] account_reconcile_model_oca: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviedoanhduy committed Nov 12, 2024
1 parent 5e65992 commit ab10b31
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 78 deletions.
20 changes: 15 additions & 5 deletions account_reconcile_model_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Account Reconcile Model Oca
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github
:target: https://github.com/OCA/account-reconcile/tree/17.0/account_reconcile_model_oca
:target: https://github.com/OCA/account-reconcile/tree/18.0/account_reconcile_model_oca
:alt: OCA/account-reconcile
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-reconcile-17-0/account-reconcile-17-0-account_reconcile_model_oca
:target: https://translation.odoo-community.org/projects/account-reconcile-18-0/account-reconcile-18-0-account_reconcile_model_oca
: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/account-reconcile&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-reconcile&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -42,7 +42,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-reconcile/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/account-reconcile/issues/new?body=module:%20account_reconcile_model_oca%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_reconcile_model_oca%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.

Expand All @@ -62,6 +62,16 @@ Contributors

- Enric Tobella

- Trobz <https://www.trobz.com/>

- Do Anh Duy <[email protected]>

Other credits
-------------

The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.

Maintainers
-----------

Expand All @@ -75,6 +85,6 @@ 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.

This module is part of the `OCA/account-reconcile <https://github.com/OCA/account-reconcile/tree/17.0/account_reconcile_model_oca>`_ project on GitHub.
This module is part of the `OCA/account-reconcile <https://github.com/OCA/account-reconcile/tree/18.0/account_reconcile_model_oca>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion account_reconcile_model_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Account Reconcile Model Oca",
"summary": """
This includes the logic moved from Odoo Community to Odoo Enterprise""",
"version": "17.0.1.0.1",
"version": "18.0.1.0.0",
"license": "LGPL-3",
"author": "Dixmit,Odoo,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-reconcile",
Expand Down
59 changes: 34 additions & 25 deletions account_reconcile_model_oca/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models
from odoo.osv.expression import get_unaccent_wrapper
from odoo.tools import html2plaintext
from odoo.tools import SQL, html2plaintext

from odoo.addons.base.models.res_bank import sanitize_account_number


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

def _retrieve_partner(self):
self.ensure_one()
Expand Down Expand Up @@ -55,7 +54,7 @@ def _retrieve_partner(self):

# Retrieve the partner from statement line text values.
st_line_text_values = self._get_st_line_strings_for_matching()
unaccent = get_unaccent_wrapper(self._cr)
unaccent = self.env.registry.unaccent
sub_queries = []
params = []
for text_value in st_line_text_values:
Expand All @@ -66,35 +65,45 @@ def _retrieve_partner(self):
# Take care a partner could contain some special characters in its name that
# needs to be escaped.
sub_queries.append(
rf"""
{unaccent("%s")} ~* ('^' || (
SELECT STRING_AGG(CONCAT('(?=.*\m', chunk[1], '\M)'), '')
FROM regexp_matches({unaccent('partner.name')}, '\w{{3,}}', 'g')
AS chunk
))
"""
SQL(
rf"""
{unaccent("%s")} ~* ('^' || (
SELECT STRING_AGG(CONCAT('(?=.*\m', chunk[1], '\M)'), '')
FROM regexp_matches({unaccent('partner.name')}, '\w{{3,}}', 'g')
AS chunk
))
""",
text_value,
)
)
params.append(text_value)

if sub_queries:
self.env["res.partner"].flush_model(["company_id", "name"])
self.env["account.move.line"].flush_model(["partner_id", "company_id"])
self._cr.execute(
query = SQL("""
SELECT aml.partner_id
FROM account_move_line aml
JOIN res_partner partner ON
aml.partner_id = partner.id
AND partner.name IS NOT NULL
AND partner.active
AND (
""")
query_parts = SQL(") OR (").join(sub_queries)
final_query = SQL(
"""
SELECT aml.partner_id
FROM account_move_line aml
JOIN res_partner partner ON
aml.partner_id = partner.id
AND partner.name IS NOT NULL
AND partner.active
AND (("""
+ ") OR (".join(sub_queries)
+ """))
WHERE aml.company_id = %s
LIMIT 1
""",
params + [self.company_id.id],
%s
%s
)
WHERE aml.company_id = %s
LIMIT 1
""",
query,
query_parts,
self.company_id.id,
)
self._cr.execute(final_query)
row = self._cr.fetchone()
if row:
return self.env["res.partner"].browse(row[0])
Expand Down
17 changes: 11 additions & 6 deletions account_reconcile_model_oca/models/account_reconcile_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,21 @@ def _get_invoice_matching_amls_candidates(self, st_line, partner):

aml_domain = self._get_invoice_matching_amls_domain(st_line, partner)
query = self.env["account.move.line"]._where_calc(aml_domain)
tables, where_clause, where_params = query.get_sql()
from_string, from_params = query.from_clause
where_string, where_params = query.where_clause
from_clause = from_string
where_clause = where_string
query_params = from_params + where_params

tokens = self._get_invoice_matching_st_line_tokens(st_line)
if tokens:
sub_queries = []
for table_alias, field in (
search_fields = [
("account_move_line", "name"),
("account_move_line__move_id", "name"),
("account_move_line__move_id", "ref"),
):
]
sub_queries = []
for table_alias, field in search_fields:
sub_queries.append(
rf"""
SELECT
Expand All @@ -400,7 +405,7 @@ def _get_invoice_matching_amls_candidates(self, st_line, partner):
'\s+'
)
) AS token
FROM {tables}
FROM {from_clause}
JOIN account_move account_move_line__move_id
ON account_move_line__move_id.id = account_move_line.move_id
WHERE {where_clause} AND {table_alias}.{field} IS NOT NULL
Expand All @@ -422,7 +427,7 @@ def _get_invoice_matching_amls_candidates(self, st_line, partner):
+ order_by
+ """
""",
(where_params * 3) + [tuple(tokens)],
(query_params * 3) + [tuple(tokens)],
)
candidate_ids = [r[0] for r in self._cr.fetchall()]
if candidate_ids:
Expand Down
3 changes: 3 additions & 0 deletions account_reconcile_model_oca/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- Dixmit

- Enric Tobella

- Trobz \<<https://www.trobz.com/>\>
- Do Anh Duy \<<[email protected]>\>
1 change: 1 addition & 0 deletions account_reconcile_model_oca/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp.
31 changes: 22 additions & 9 deletions account_reconcile_model_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
: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.
Expand Down Expand Up @@ -274,7 +275,7 @@
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 }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -368,7 +369,7 @@ <h1 class="title">Account Reconcile Model Oca</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:cead010f67ccc5d4b9700540c9d8d0b4fb20d497a38d36cea80cf6f78563a756
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.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/account-reconcile/tree/17.0/account_reconcile_model_oca"><img alt="OCA/account-reconcile" src="https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-reconcile-17-0/account-reconcile-17-0-account_reconcile_model_oca"><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/account-reconcile&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="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.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/account-reconcile/tree/18.0/account_reconcile_model_oca"><img alt="OCA/account-reconcile" src="https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-reconcile-18-0/account-reconcile-18-0-account_reconcile_model_oca"><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/account-reconcile&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 restores account reconciliation models functions moved from
Odoo community to enterpise in V. 17.0</p>
<p><strong>Table of contents</strong></p>
Expand All @@ -378,7 +379,8 @@ <h1 class="title">Account Reconcile Model Oca</h1>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-5">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
</ul>
</li>
</ul>
Expand All @@ -388,7 +390,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-reconcile/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/account-reconcile/issues/new?body=module:%20account_reconcile_model_oca%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/account-reconcile/issues/new?body=module:%20account_reconcile_model_oca%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">
Expand All @@ -407,16 +409,27 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<li>Enric Tobella</li>
</ul>
</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-5">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-5">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">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>This module is part of the <a class="reference external" href="https://github.com/OCA/account-reconcile/tree/17.0/account_reconcile_model_oca">OCA/account-reconcile</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-reconcile/tree/18.0/account_reconcile_model_oca">OCA/account-reconcile</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>
Expand Down
12 changes: 6 additions & 6 deletions account_reconcile_model_oca/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class TestAccountReconciliationCommon(AccountTestInvoicingCommon):
"""

@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
def setUpClass(cls):
super().setUpClass()

cls.company = cls.company_data["company"]
cls.company.currency_id = cls.env.ref("base.EUR")
Expand Down Expand Up @@ -69,7 +69,7 @@ def setUpClass(cls, chart_template_ref=None):
"code": "TWAIT",
"account_type": "liability_current",
"reconcile": True,
"company_id": cls.company.id,
"company_ids": cls.company.ids,
}
)
# cash basis final account
Expand All @@ -78,15 +78,15 @@ def setUpClass(cls, chart_template_ref=None):
"name": "TAX_TO_DEDUCT",
"code": "TDEDUCT",
"account_type": "asset_current",
"company_id": cls.company.id,
"company_ids": cls.company.ids,
}
)
cls.tax_base_amount_account = cls.env["account.account"].create(
{
"name": "TAX_BASE",
"code": "TBASE",
"account_type": "asset_current",
"company_id": cls.company.id,
"company_ids": cls.company.ids,
}
)
cls.company.account_cash_basis_base_account_id = cls.tax_base_amount_account.id
Expand Down Expand Up @@ -190,7 +190,7 @@ def _create_invoice(
0,
0,
{
"name": "product that cost %s" % invoice_amount,
"name": f"product that cost {invoice_amount}",
"quantity": 1,
"price_unit": invoice_amount,
"tax_ids": [Command.set([])],
Expand Down
Loading

0 comments on commit ab10b31

Please sign in to comment.