diff --git a/account_fix_statement_line_creation/README.rst b/account_fix_statement_line_creation/README.rst new file mode 100644 index 0000000000..eddace00cf --- /dev/null +++ b/account_fix_statement_line_creation/README.rst @@ -0,0 +1,80 @@ +======================================== +Account bank statement fix line creation +======================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:cba093a615bb7c4b03e5b56ce538c39d55ee98e27f1bcb744fddf04ba90a46b3 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-OCA%2Faccount--reconcile-lightgray.png?logo=github + :target: https://github.com/OCA/account-reconcile/tree/16.0/account_fix_statement_line_creation + :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-16-0/account-reconcile-16-0-account_fix_statement_line_creation + :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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + + +This module fix bug about creation of new statement line on statement that contain +lines. +The bug is reported in this issue https://github.com/odoo/odoo/issues/171077 + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* Mourad EL HADJ MIMOUNE + + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_fix_statement_line_creation/__init__.py b/account_fix_statement_line_creation/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/account_fix_statement_line_creation/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_fix_statement_line_creation/__manifest__.py b/account_fix_statement_line_creation/__manifest__.py new file mode 100644 index 0000000000..da3bb59a85 --- /dev/null +++ b/account_fix_statement_line_creation/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +{ + "name": "Account bank statement fix line creation", + "version": "16.0.1.0.0", + "author": "Akretion, Odoo Community Association (OCA)", + "maintainer": "Akretion", + "category": "Hidden/Dependency", + "depends": [ + "account", + ], + "website": "https://github.com/OCA/account-reconcile", + "installable": True, + "license": "AGPL-3", +} diff --git a/account_fix_statement_line_creation/models/__init__.py b/account_fix_statement_line_creation/models/__init__.py new file mode 100644 index 0000000000..0882dd26a7 --- /dev/null +++ b/account_fix_statement_line_creation/models/__init__.py @@ -0,0 +1 @@ +from . import account_bank_statement diff --git a/account_fix_statement_line_creation/models/account_bank_statement.py b/account_fix_statement_line_creation/models/account_bank_statement.py new file mode 100644 index 0000000000..c92dc82ef8 --- /dev/null +++ b/account_fix_statement_line_creation/models/account_bank_statement.py @@ -0,0 +1,28 @@ +# Copyright 2024 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + + +from odoo import api, models + + +class AccountBankStatement(models.Model): + _inherit = "account.bank.statement" + + # ------------------------------------------------------------------------- + # COMPUTE METHODS + # ------------------------------------------------------------------------- + @api.depends("line_ids.internal_index", "line_ids.state") + def _compute_date_index(self): + for stmt in self: + # When we create a new statement line for existing statement, + # internal_index field of line can be False + # And we can not sort str and bool type (python error) + # sort only line with internal_index != False to avoid bug when sort value from + # different type + sorted_lines = stmt.line_ids.filtered(lambda l: l.internal_index).sorted( + "internal_index" + ) + if not sorted_lines: + sorted_lines = stmt.line_ids + stmt.first_line_index = sorted_lines[:1].internal_index + stmt.date = sorted_lines.filtered(lambda l: l.state == "posted")[-1:].date diff --git a/account_fix_statement_line_creation/readme/CONTRIBUTORS.rst b/account_fix_statement_line_creation/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..f185b79226 --- /dev/null +++ b/account_fix_statement_line_creation/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Mourad EL HADJ MIMOUNE + diff --git a/account_fix_statement_line_creation/readme/DESCRIPTION.rst b/account_fix_statement_line_creation/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..1ad6acb592 --- /dev/null +++ b/account_fix_statement_line_creation/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ + +This module fix bug about creation of new statement line on statement that contain +lines. +The bug is reported in this issue https://github.com/odoo/odoo/issues/171077 diff --git a/account_fix_statement_line_creation/static/description/icon.png b/account_fix_statement_line_creation/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/account_fix_statement_line_creation/static/description/icon.png differ diff --git a/account_fix_statement_line_creation/tests/__init__.py b/account_fix_statement_line_creation/tests/__init__.py new file mode 100644 index 0000000000..46f68abe1e --- /dev/null +++ b/account_fix_statement_line_creation/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import statement_line_creation diff --git a/account_fix_statement_line_creation/tests/statement_line_creation.py b/account_fix_statement_line_creation/tests/statement_line_creation.py new file mode 100644 index 0000000000..fb73076b75 --- /dev/null +++ b/account_fix_statement_line_creation/tests/statement_line_creation.py @@ -0,0 +1,42 @@ +# Copyright 2024 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests import tagged + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + + +@tagged("post_install", "-at_install") +class TestAccountBankStatementLineCreation(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + + cls.bank_journal_1 = cls.company_data["default_journal_bank"] + cls.currency_1 = cls.company_data["currency"] + cls.statement = cls.env["account.bank.statement"].create( + { + "name": "test_statement", + "line_ids": [ + ( + 0, + 0, + { + "date": "2024-01-01", + "payment_ref": "line_1", + "journal_id": cls.bank_journal_1.id, + "amount": 1000.0, + }, + ), + ], + } + ) + cls.statement_line = cls.statement.line_ids + + def test_bank_statement_line_creation(self): + """ + Check that we can create a new statement. + """ + self.statement.line_ids.new() + self.statement._compute_date_index() + self.assertEqual(len(self.statement.line_ids), 2)