Skip to content

Commit

Permalink
Merge pull request #70 from Escodoo/14.0-add-account_reconciliation_w…
Browse files Browse the repository at this point in the history
…idget_order_by_desc

[14.0][ADD] account_reconciliation_widget_order_by_desc: add new module
  • Loading branch information
marcelsavegnago authored May 8, 2024
2 parents d6e4fa8 + 61c44c9 commit 7c83e72
Show file tree
Hide file tree
Showing 12 changed files with 598 additions and 0 deletions.
63 changes: 63 additions & 0 deletions account_reconciliation_widget_order_by_desc/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
===========================================
Account Reconciliation Widget Order By DESC
===========================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:060ba4ce6777edbb103f9b6bd8dd636450ae964c677c50355a918a1c26890925
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-Escodoo%2Faccount--addons-lightgray.png?logo=github
:target: https://github.com/Escodoo/account-addons/tree/14.0/account_reconciliation_widget_order_by_desc
:alt: Escodoo/account-addons

|badge1| |badge2| |badge3|

This module contains a modification in the bank statement reconciliation logic, rewriting the function to return accounting move lines formatted for the bank statement reconciliation widget. The order of the fields 'date_maturity' and 'id' is altered to DESC, moving 'date_maturity' to the first position and '{amout}' to the second.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/Escodoo/account-addons/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/Escodoo/account-addons/issues/new?body=module:%20account_reconciliation_widget_order_by_desc%0Aversion:%2014.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.

Credits
=======

Authors
~~~~~~~

* Escodoo

Contributors
~~~~~~~~~~~~

* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <marcel.savegnago@escodoo.com.br>
* Kaynnan Lemes <kaynnan.lemes@escodoo.com.br>

Maintainers
~~~~~~~~~~~

This module is part of the `Escodoo/account-addons <https://github.com/Escodoo/account-addons/tree/14.0/account_reconciliation_widget_order_by_desc>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions account_reconciliation_widget_order_by_desc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
11 changes: 11 additions & 0 deletions account_reconciliation_widget_order_by_desc/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2024 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Account Reconciliation Widget Order By DESC",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo",
"website": "https://github.com/Escodoo/account-addons",
"depends": ["account_reconciliation_widget"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import reconciliation_widget
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright 2024 - TODAY, Kaynnan Lemes <kaynnan.lemes@escodoo.com.br>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from psycopg2 import sql

from odoo import api, models


class AccountReconciliation(models.AbstractModel):

_inherit = "account.reconciliation.widget"

@api.model
def get_move_lines_for_bank_statement_line(
self,
st_line_id,
partner_id=None,
excluded_ids=None,
search_str=False,
offset=0,
limit=None,
mode=None,
):
"""
Rewrite of the function to return move lines for the
Bank statement reconciliation widget.
Modifies the order of fields 'date_maturity' and 'id' to DESC,
moving 'date_maturity' to the first position and '{amout}' to the second.
"""
st_line = self.env["account.bank.statement.line"].browse(st_line_id)

# Blue lines = payment on bank account not assigned to a statement yet
aml_accounts = [
st_line.journal_id.default_account_id.id,
]

if partner_id is None:
partner_id = st_line.partner_id.id

domain = self._domain_move_lines_for_reconciliation(
st_line,
aml_accounts,
partner_id,
excluded_ids=excluded_ids,
search_str=search_str,
mode=mode,
)

from_clause, where_clause, where_clause_params = (
self.env["account.move.line"]._where_calc(domain).get_sql()
)

query_str = sql.SQL(
"""
SELECT "account_move_line".id, COUNT(*) OVER() FROM {from_clause}
{where_str}
ORDER BY "account_move_line".date_maturity DESC,
("account_move_line".debit -
"account_move_line".credit) = {amount} DESC,
"account_move_line".id DESC
{limit_str}
""".format(
from_clause=from_clause,
where_str=where_clause and (" WHERE %s" % where_clause) or "",
amount=st_line.amount,
limit_str=limit and " LIMIT %s" or "",
)
)
params = where_clause_params + (limit and [limit] or [])
self.env["account.move"].flush()
self.env["account.move.line"].flush()
self.env["account.bank.statement"].flush()
self._cr.execute(query_str, params)
res = self._cr.fetchall()
try:
# All records will have the same count value, just get the 1st one
recs_count = res[0][1]
except IndexError:
recs_count = 0
aml_recs = self.env["account.move.line"].browse([i[0] for i in res])
target_currency = (
st_line.foreign_currency_id
or st_line.journal_id.currency_id
or st_line.journal_id.company_id.currency_id
)
return self._prepare_move_lines(
aml_recs,
target_currency=target_currency,
target_date=st_line.date,
recs_count=recs_count,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <marcel.savegnago@escodoo.com.br>
* Kaynnan Lemes <kaynnan.lemes@escodoo.com.br>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module contains a modification in the bank statement reconciliation logic, rewriting the function to return accounting move lines formatted for the bank statement reconciliation widget. The order of the fields 'date_maturity' and 'id' is altered to DESC, moving 'date_maturity' to the first position and '{amout}' to the second.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7c83e72

Please sign in to comment.