diff --git a/account_analytic_document_date/README.rst b/account_analytic_document_date/README.rst new file mode 100644 index 0000000000..34b1ac3150 --- /dev/null +++ b/account_analytic_document_date/README.rst @@ -0,0 +1,120 @@ +============================== +Account Analytic Document Date +============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:a744d1489a8640283abcaacbc6366a24199f447d5d46ba66ad30beefcebf542b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--analytic-lightgray.png?logo=github + :target: https://github.com/OCA/account-analytic/tree/16.0/account_analytic_document_date + :alt: OCA/account-analytic +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-analytic-16-0/account-analytic-16-0-account_analytic_document_date + :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-analytic&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +The module introduces a new field in the accounting records to specify +the "Accrual Date" for income and expenses. This field is crucial for +accurately tracking when the revenue or expense is earned or incurred, +regardless of the invoice creation date. + +For instance, if an invoice is created in December but refers to sales +made in November, the Accrual Date allows us to reflect this correctly +in our accounting records. This ensures compliance with accrual-based +accounting principles and provides better insights into the financial +period to which transactions belong. + +This feature is particularly valuable for businesses that need to +differentiate between the accounting period of transaction occurrence +and the timing of document issuance. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. **Set Document Date on Invoice:** + + - Navigate to the invoice and set the analytic document date. + - If the analytic document date is not set, it will automatically be + assigned the invoice date upon confirmation. + +2. **Analytic Line Generation:** + + - If any line has analytic information, the generated analytic entry + will inherit the analytic document date. + +3. **Setting Document Date in Reconcile View:** + + - You can also set the analytic document date from the + reconciliation view, but this option is available only during + manual reconciliation. + +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 +------- + +* APSL-Nagarro + +Contributors +------------ + +- ``APSL - Nagarro ``\ \_\_: + + - Miquel Pascual + - Bernat Obrador + +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. + +.. |maintainer-mpascual, BernatObrador| image:: https://github.com/mpascual, BernatObrador.png?size=40px + :target: https://github.com/mpascual, BernatObrador + :alt: mpascual, BernatObrador + +Current `maintainer `__: + +|maintainer-mpascual, BernatObrador| + +This module is part of the `OCA/account-analytic `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_analytic_document_date/__init__.py b/account_analytic_document_date/__init__.py new file mode 100644 index 0000000000..cc6b6354ad --- /dev/null +++ b/account_analytic_document_date/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import post_init_hook diff --git a/account_analytic_document_date/__manifest__.py b/account_analytic_document_date/__manifest__.py new file mode 100644 index 0000000000..54cdece22f --- /dev/null +++ b/account_analytic_document_date/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2024 (APSL - Nagarro) Miquel Pascual, Bernat Obrador +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Account Analytic Document Date", + "summary": "Account Analytic Document Date", + "version": "16.0.1.0.0", + "website": "https://github.com/OCA/account-analytic", + "author": "APSL-Nagarro, Odoo Community Association (OCA)", + "maintainers": ["mpascual, BernatObrador"], + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["account", "account_reconcile_oca"], + "data": [ + "views/account_analytic_line_views.xml", + "views/account_bank_statement_line_views.xml", + "views/account_move.xml", + ], + "post_init_hook": "post_init_hook", +} diff --git a/account_analytic_document_date/hooks.py b/account_analytic_document_date/hooks.py new file mode 100644 index 0000000000..99c36c16c4 --- /dev/null +++ b/account_analytic_document_date/hooks.py @@ -0,0 +1,12 @@ +# Copyright 2024 (APSL - Nagarro) Miquel Pascual, Bernat Obrador +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +def post_init_hook(cr, registry): + cr.execute( + """ + UPDATE account_move + SET analytic_document_date = invoice_date + WHERE analytic_document_date IS NULL + """ + ) diff --git a/account_analytic_document_date/i18n/ca.po b/account_analytic_document_date/i18n/ca.po new file mode 100644 index 0000000000..eb803cb9d7 --- /dev/null +++ b/account_analytic_document_date/i18n/ca.po @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_analytic_document_date +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-12-27 08:52+0000\n" +"PO-Revision-Date: 2024-12-27 08:52+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_analytic_document_date +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_bank_statement_line__analytic_document_date +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_move__analytic_document_date +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_payment__analytic_document_date +msgid "Analytic Document Date" +msgstr "Data del Document Analític" + +#. module: account_analytic_document_date +#: model:ir.model,name:account_analytic_document_date.model_account_analytic_line +msgid "Analytic Line" +msgstr "Línia analítica" + +#. module: account_analytic_document_date +#: model:ir.model,name:account_analytic_document_date.model_account_bank_statement_line +msgid "Bank Statement Line" +msgstr "Línea d'extracte bancari" + +#. module: account_analytic_document_date +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_analytic_line__document_date +msgid "Document Date" +msgstr "Data del Document" + +#. module: account_analytic_document_date +#: model:ir.model,name:account_analytic_document_date.model_account_move +msgid "Journal Entry" +msgstr "Assentament comptable" + +#. module: account_analytic_document_date +#: model:ir.model,name:account_analytic_document_date.model_account_move_line +msgid "Journal Item" +msgstr "Element del diari" \ No newline at end of file diff --git a/account_analytic_document_date/i18n/es.po b/account_analytic_document_date/i18n/es.po new file mode 100644 index 0000000000..4f35f23a0c --- /dev/null +++ b/account_analytic_document_date/i18n/es.po @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_analytic_document_date +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-12-27 08:53+0000\n" +"PO-Revision-Date: 2024-12-27 08:53+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_analytic_document_date +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_bank_statement_line__analytic_document_date +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_move__analytic_document_date +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_payment__analytic_document_date +msgid "Analytic Document Date" +msgstr "Fecha del Documento Analítico" + +#. module: account_analytic_document_date +#: model:ir.model,name:account_analytic_document_date.model_account_analytic_line +msgid "Analytic Line" +msgstr "Línea analítica" + +#. module: account_analytic_document_date +#: model:ir.model,name:account_analytic_document_date.model_account_bank_statement_line +msgid "Bank Statement Line" +msgstr "Línea de extracto bancario" + +#. module: account_analytic_document_date +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_analytic_line__document_date +msgid "Document Date" +msgstr "Fecha del Documento" + +#. module: account_analytic_document_date +#: model:ir.model,name:account_analytic_document_date.model_account_move +msgid "Journal Entry" +msgstr "Asiento contable" + +#. module: account_analytic_document_date +#: model:ir.model,name:account_analytic_document_date.model_account_move_line +msgid "Journal Item" +msgstr "Apunte contable" \ No newline at end of file diff --git a/account_analytic_document_date/models/__init__.py b/account_analytic_document_date/models/__init__.py new file mode 100644 index 0000000000..6c668354c1 --- /dev/null +++ b/account_analytic_document_date/models/__init__.py @@ -0,0 +1,4 @@ +from . import account_move_line +from . import account_analytic_line +from . import account_move +from . import account_bank_statement_line diff --git a/account_analytic_document_date/models/account_analytic_line.py b/account_analytic_document_date/models/account_analytic_line.py new file mode 100644 index 0000000000..41cac08ebf --- /dev/null +++ b/account_analytic_document_date/models/account_analytic_line.py @@ -0,0 +1,9 @@ +# Copyright 2024 (APSL - Nagarro) Miquel Pascual, Bernat Obrador +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class AccountAnalyticLine(models.Model): + _inherit = "account.analytic.line" + + document_date = fields.Date() diff --git a/account_analytic_document_date/models/account_bank_statement_line.py b/account_analytic_document_date/models/account_bank_statement_line.py new file mode 100644 index 0000000000..7898f72adb --- /dev/null +++ b/account_analytic_document_date/models/account_bank_statement_line.py @@ -0,0 +1,19 @@ +# Copyright 2024 (APSL - Nagarro) Miquel Pascual, Bernat Obrador +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class AccountBankStatementLine(models.Model): + _inherit = "account.bank.statement.line" + + analytic_document_date = fields.Date( + "Analytic Document Date", + related="move_id.analytic_document_date", + readonly=False, + ) + + def reconcile_bank_line(self): + self.ensure_one() + res = super().reconcile_bank_line() + self.move_id.analytic_document_date = self.analytic_document_date + return res diff --git a/account_analytic_document_date/models/account_move.py b/account_analytic_document_date/models/account_move.py new file mode 100644 index 0000000000..e96ab03266 --- /dev/null +++ b/account_analytic_document_date/models/account_move.py @@ -0,0 +1,22 @@ +# Copyright 2024 (APSL - Nagarro) Miquel Pascual, Bernat Obrador +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + analytic_document_date = fields.Date() + + @api.onchange("invoice_date") + def _onchange_invoice_date(self): + for record in self: + if not record.analytic_document_date: + record.analytic_document_date = record.invoice_date + + def action_post(self): + res = super().action_post() + for record in self: + if not record.analytic_document_date: + record.analytic_document_date = record.invoice_date + return res diff --git a/account_analytic_document_date/models/account_move_line.py b/account_analytic_document_date/models/account_move_line.py new file mode 100644 index 0000000000..653ac4be43 --- /dev/null +++ b/account_analytic_document_date/models/account_move_line.py @@ -0,0 +1,16 @@ +# Copyright 2024 (APSL - Nagarro) Miquel Pascual, Bernat Obrador +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + def _prepare_analytic_lines(self): + vals = super()._prepare_analytic_lines() + for val in vals: + if self.move_id.analytic_document_date: + val.update({"document_date": self.move_id.analytic_document_date}) + else: + val.update({"document_date": self.move_id.invoice_date}) + return vals diff --git a/account_analytic_document_date/readme/CONTRIBUTORS.md b/account_analytic_document_date/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..470a586b45 --- /dev/null +++ b/account_analytic_document_date/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- `APSL - Nagarro `__: + + - Miquel Pascual + - Bernat Obrador \ No newline at end of file diff --git a/account_analytic_document_date/readme/DESCRIPTION.md b/account_analytic_document_date/readme/DESCRIPTION.md new file mode 100644 index 0000000000..6ff7c5be4f --- /dev/null +++ b/account_analytic_document_date/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +The module introduces a new field in the accounting records to specify the "Accrual Date" for income and expenses. This field is crucial for accurately tracking when the revenue or expense is earned or incurred, regardless of the invoice creation date. + +For instance, if an invoice is created in December but refers to sales made in November, the Accrual Date allows us to reflect this correctly in our accounting records. This ensures compliance with accrual-based accounting principles and provides better insights into the financial period to which transactions belong. + +This feature is particularly valuable for businesses that need to differentiate between the accounting period of transaction occurrence and the timing of document issuance. \ No newline at end of file diff --git a/account_analytic_document_date/readme/USAGE.md b/account_analytic_document_date/readme/USAGE.md new file mode 100644 index 0000000000..4f74734f7d --- /dev/null +++ b/account_analytic_document_date/readme/USAGE.md @@ -0,0 +1,9 @@ +1. **Set Document Date on Invoice:** + - Navigate to the invoice and set the analytic document date. + - If the analytic document date is not set, it will automatically be assigned the invoice date upon confirmation. + +2. **Analytic Line Generation:** + - If any line has analytic information, the generated analytic entry will inherit the analytic document date. + +3. **Setting Document Date in Reconcile View:** + - You can also set the analytic document date from the reconciliation view, but this option is available only during manual reconciliation. \ No newline at end of file diff --git a/account_analytic_document_date/static/description/icon.png b/account_analytic_document_date/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/account_analytic_document_date/static/description/icon.png differ diff --git a/account_analytic_document_date/static/description/index.html b/account_analytic_document_date/static/description/index.html new file mode 100644 index 0000000000..65a0af56af --- /dev/null +++ b/account_analytic_document_date/static/description/index.html @@ -0,0 +1,463 @@ + + + + + +Account Analytic Document Date + + + +
+

Account Analytic Document Date

+ + +

Beta License: AGPL-3 OCA/account-analytic Translate me on Weblate Try me on Runboat

+

The module introduces a new field in the accounting records to specify +the “Accrual Date” for income and expenses. This field is crucial for +accurately tracking when the revenue or expense is earned or incurred, +regardless of the invoice creation date.

+

For instance, if an invoice is created in December but refers to sales +made in November, the Accrual Date allows us to reflect this correctly +in our accounting records. This ensures compliance with accrual-based +accounting principles and provides better insights into the financial +period to which transactions belong.

+

This feature is particularly valuable for businesses that need to +differentiate between the accounting period of transaction occurrence +and the timing of document issuance.

+

Table of contents

+ +
+

Usage

+
    +
  1. Set Document Date on Invoice:
      +
    • Navigate to the invoice and set the analytic document date.
    • +
    • If the analytic document date is not set, it will automatically be +assigned the invoice date upon confirmation.
    • +
    +
  2. +
  3. Analytic Line Generation:
      +
    • If any line has analytic information, the generated analytic entry +will inherit the analytic document date.
    • +
    +
  4. +
  5. Setting Document Date in Reconcile View:
      +
    • You can also set the analytic document date from the +reconciliation view, but this option is available only during +manual reconciliation.
    • +
    +
  6. +
+
+
+

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

+
    +
  • APSL-Nagarro
  • +
+
+
+

Contributors

+
    +
  • APSL - Nagarro <https://apsl.tech>__:
      +
    • Miquel Pascual
    • +
    • Bernat Obrador
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainer:

+

mpascual, BernatObrador

+

This module is part of the OCA/account-analytic project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_analytic_document_date/tests/__init__.py b/account_analytic_document_date/tests/__init__.py new file mode 100644 index 0000000000..9320b69a50 --- /dev/null +++ b/account_analytic_document_date/tests/__init__.py @@ -0,0 +1 @@ +from . import test_document_date diff --git a/account_analytic_document_date/tests/test_document_date.py b/account_analytic_document_date/tests/test_document_date.py new file mode 100644 index 0000000000..d90c3ea01d --- /dev/null +++ b/account_analytic_document_date/tests/test_document_date.py @@ -0,0 +1,101 @@ +# Copyright 2024 (APSL - Nagarro) Miquel Pascual, Bernat Obrador +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from datetime import datetime, timedelta + +from odoo.tests import TransactionCase + + +class TestAccountMoveDocumentDate(TransactionCase): + @classmethod + def setUpClass(cls): + super(TestAccountMoveDocumentDate, cls).setUpClass() + cls.account_move_model = cls.env["account.move"] + + cls.partner = cls.env["res.partner"].create( + { + "name": "Test Partner", + "email": "test@partner.com", + "phone": "123456789", + } + ) + + cls.analytic_plan_1 = cls.env["account.analytic.plan"].create( + { + "name": "Plan 1", + "default_applicability": "unavailable", + "company_id": False, + } + ) + + cls.analytic_account_1 = cls.env["account.analytic.account"].create( + {"name": "Account 1", "plan_id": cls.analytic_plan_1.id} + ) + + def test_create_invoice_without_document_date(self): + invoice = self.account_move_model.create( + { + "move_type": "out_invoice", + "partner_id": self.partner.id, + "invoice_line_ids": [ + ( + 0, + 0, + { + "name": "Test Product", + "quantity": 1, + "price_unit": 100.0, + "tax_ids": [ + (6, 0, [self.env["account.tax"].search([], limit=1).id]) + ], + "analytic_distribution": {self.analytic_account_1.id: 100}, + }, + ) + ], + } + ) + + invoice.action_post() + + self.assertEqual(invoice.analytic_document_date, invoice.invoice_date) + + # Confirms that the analytic line has the same document_date as the account.move + analytic_line = self.env["account.analytic.line"].search( + [("move_line_id", "in", invoice.line_ids.ids)], limit=1 + ) + self.assertEqual(invoice.analytic_document_date, analytic_line.document_date) + + def test_create_invoice_with_document_date(self): + document_date = datetime.now().date() + timedelta(days=1) + invoice = self.account_move_model.create( + { + "move_type": "out_invoice", + "partner_id": self.partner.id, + "invoice_line_ids": [ + ( + 0, + 0, + { + "name": "Test Product", + "quantity": 1, + "price_unit": 100.0, + "tax_ids": [ + (6, 0, [self.env["account.tax"].search([], limit=1).id]) + ], + "analytic_distribution": {self.analytic_account_1.id: 100}, + }, + ) + ], + "analytic_document_date": document_date, + } + ) + + invoice.action_post() + + self.assertEqual(invoice.analytic_document_date, document_date) + self.assertNotEqual(invoice.invoice_date, invoice.analytic_document_date) + + # Confirms that the analytic line has the same document_date as the account.move + analytic_line = self.env["account.analytic.line"].search( + [("move_line_id", "in", invoice.line_ids.ids)], limit=1 + ) + self.assertEqual(invoice.analytic_document_date, analytic_line.document_date) diff --git a/account_analytic_document_date/views/account_analytic_line_views.xml b/account_analytic_document_date/views/account_analytic_line_views.xml new file mode 100644 index 0000000000..28365bc5cf --- /dev/null +++ b/account_analytic_document_date/views/account_analytic_line_views.xml @@ -0,0 +1,48 @@ + + + + + account.analytic.line.tree + account.analytic.line + + + + + + + + + account.analytic.line.form + account.analytic.line + + + + + + + + + + Analytic Document Date Search + account.analytic.line + + + + + + + + + + + + + + diff --git a/account_analytic_document_date/views/account_bank_statement_line_views.xml b/account_analytic_document_date/views/account_bank_statement_line_views.xml new file mode 100644 index 0000000000..1e66894dd0 --- /dev/null +++ b/account_analytic_document_date/views/account_bank_statement_line_views.xml @@ -0,0 +1,23 @@ + + + + + bank_statement_line_form_reconcile_view.inherit + account.bank.statement.line + + + + + + + + diff --git a/account_analytic_document_date/views/account_move.xml b/account_analytic_document_date/views/account_move.xml new file mode 100644 index 0000000000..551e802085 --- /dev/null +++ b/account_analytic_document_date/views/account_move.xml @@ -0,0 +1,19 @@ + + + + + account_move_view_form_inherit + account.move + + + + + + + + diff --git a/setup/account_analytic_document_date/odoo/addons/account_analytic_document_date b/setup/account_analytic_document_date/odoo/addons/account_analytic_document_date new file mode 120000 index 0000000000..ef642625e4 --- /dev/null +++ b/setup/account_analytic_document_date/odoo/addons/account_analytic_document_date @@ -0,0 +1 @@ +../../../../account_analytic_document_date \ No newline at end of file diff --git a/setup/account_analytic_document_date/setup.py b/setup/account_analytic_document_date/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/account_analytic_document_date/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)