diff --git a/account_analytic_document_date.zip b/account_analytic_document_date.zip new file mode 100644 index 000000000..f3e240b7c Binary files /dev/null and b/account_analytic_document_date.zip differ diff --git a/account_analytic_document_date/README.rst b/account_analytic_document_date/README.rst new file mode 100644 index 000000000..f23ce03fc --- /dev/null +++ b/account_analytic_document_date/README.rst @@ -0,0 +1,109 @@ +============================== +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| + +This module adds an other date to the account.move for analytics +proposits + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. **Set Document Date on Invoice:** + + - Navigate to the invoice and set the document date. + - If the 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 document date. + +3. **Setting Document Date in Reconcile View:** + + - You can also set the 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 +------- + +* (Nagarro - APSL) +* Miquel Pascual +* Bernat Obrador + +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@apsl.net, bobrador@apsl.net| image:: https://github.com/mpascual@apsl.net, bobrador@apsl.net.png?size=40px + :target: https://github.com/mpascual@apsl.net, bobrador@apsl.net + :alt: mpascual@apsl.net, bobrador@apsl.net + +Current `maintainer `__: + +|maintainer-mpascual@apsl.net, bobrador@apsl.net| + +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 000000000..cc6b6354a --- /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 000000000..e642bd03f --- /dev/null +++ b/account_analytic_document_date/__manifest__.py @@ -0,0 +1,23 @@ +# 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": ( + "(Nagarro - APSL), Miquel Pascual, Bernat Obrador," + "Odoo Community Association (OCA)" + ), + "maintainers": ["mpascual@apsl.net, bobrador@apsl.net"], + "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 000000000..e7551dec4 --- /dev/null +++ b/account_analytic_document_date/hooks.py @@ -0,0 +1,13 @@ +# Copyright 2024 (APSL - Nagarro) Miquel Pascual, Bernat Obrador +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import SUPERUSER_ID, api + + +def post_init_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + + moves = env["account.move"].search([]) + + for move in moves: + if not move.document_date: + move.write({"document_date": move.invoice_date}) diff --git a/account_analytic_document_date/i18n/ca_ES.po b/account_analytic_document_date/i18n/ca_ES.po new file mode 100644 index 000000000..6ae284666 --- /dev/null +++ b/account_analytic_document_date/i18n/ca_ES.po @@ -0,0 +1,44 @@ +# 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-09-27 10:33+0000\n" +"PO-Revision-Date: 2024-09-27 10:33+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,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 +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_bank_statement_line__document_date +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_move__document_date +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_payment__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" diff --git a/account_analytic_document_date/i18n/es.po b/account_analytic_document_date/i18n/es.po new file mode 100644 index 000000000..a4661a4df --- /dev/null +++ b/account_analytic_document_date/i18n/es.po @@ -0,0 +1,44 @@ +# 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-09-27 10:29+0000\n" +"PO-Revision-Date: 2024-09-27 10:29+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,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 +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_bank_statement_line__document_date +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_move__document_date +#: model:ir.model.fields,field_description:account_analytic_document_date.field_account_payment__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" diff --git a/account_analytic_document_date/models/__init__.py b/account_analytic_document_date/models/__init__.py new file mode 100644 index 000000000..6c668354c --- /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 000000000..41cac08eb --- /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 000000000..de501ef9a --- /dev/null +++ b/account_analytic_document_date/models/account_bank_statement_line.py @@ -0,0 +1,17 @@ +# 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" + + document_date = fields.Date( + "Document Date", related="move_id.document_date", readonly=False + ) + + def reconcile_bank_line(self): + self.ensure_one() + res = super().reconcile_bank_line() + self.move_id.document_date = self.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 000000000..9a14fd8e9 --- /dev/null +++ b/account_analytic_document_date/models/account_move.py @@ -0,0 +1,21 @@ +# 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" + + document_date = fields.Date() + + @api.onchange("invoice_date") + def _onchange_invoice_date(self): + for record in self: + if not record.document_date: + record.document_date = record.invoice_date + + def action_post(self): + res = super().action_post() + if not self.document_date: + self.document_date = self.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 000000000..dbb569100 --- /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.document_date: + val.update({"document_date": self.move_id.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 000000000..470a586b4 --- /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 000000000..7ef9b2e06 --- /dev/null +++ b/account_analytic_document_date/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module adds an other date to the account.move for analytics proposits \ 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 000000000..f6865426c --- /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 document date. + - If the 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 document date. + +3. **Setting Document Date in Reconcile View:** + - You can also set the 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 000000000..3a0328b51 Binary files /dev/null and b/account_analytic_document_date/static/description/icon.png differ diff --git a/account_analytic_document_date/static/description/icon.svg b/account_analytic_document_date/static/description/icon.svg new file mode 100644 index 000000000..a7a26d093 --- /dev/null +++ b/account_analytic_document_date/static/description/icon.svg @@ -0,0 +1,79 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + 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 000000000..ff05d616a --- /dev/null +++ b/account_analytic_document_date/static/description/index.html @@ -0,0 +1,454 @@ + + + + + +Account Analytic Document Date + + + +
+

Account Analytic Document Date

+ + +

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

+

This module adds an other date to the account.move for analytics +proposits

+

Table of contents

+ +
+

Usage

+
    +
  1. Set Document Date on Invoice:
      +
    • Navigate to the invoice and set the document date.
    • +
    • If the 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 document date.
    • +
    +
  4. +
  5. Setting Document Date in Reconcile View:
      +
    • You can also set the 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

+
    +
  • (Nagarro - APSL)
  • +
  • Miquel Pascual
  • +
  • Bernat Obrador
  • +
+
+
+

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@apsl.net, bobrador@apsl.net

+

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 000000000..9320b69a5 --- /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 000000000..66aa3227c --- /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.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.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}, + }, + ) + ], + "document_date": document_date, + } + ) + + invoice.action_post() + + self.assertEqual(invoice.document_date, document_date) + self.assertNotEqual(invoice.invoice_date, invoice.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.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 000000000..8cc55ef65 --- /dev/null +++ b/account_analytic_document_date/views/account_analytic_line_views.xml @@ -0,0 +1,25 @@ + + + + + account.analytic.line.tree + account.analytic.line + + + + + + + + + account.analytic.line.form + 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 000000000..dbda42c7b --- /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 000000000..512efec90 --- /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 000000000..ef642625e --- /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 000000000..28c57bb64 --- /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, +)