diff --git a/account_analytic_distribution_manual/__manifest__.py b/account_analytic_distribution_manual/__manifest__.py index aeb4970554..b7fc4285d4 100644 --- a/account_analytic_distribution_manual/__manifest__.py +++ b/account_analytic_distribution_manual/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Account analytic distribution manual", "summary": "Account analytic distribution manual", - "version": "16.0.2.2.0", + "version": "16.0.2.3.0", "license": "AGPL-3", "website": "https://github.com/OCA/account-analytic", "author": "Tecnativa, Odoo Community Association (OCA)", @@ -13,6 +13,7 @@ "security/analytic_security.xml", "security/ir.model.access.csv", "views/account_analytic_distribution_manual_views.xml", + "views/account_analytic_line_views.xml", ], "assets": { "web.assets_backend": [ diff --git a/account_analytic_distribution_manual/hooks.py b/account_analytic_distribution_manual/hooks.py index e7b8184cba..ac4596f6b6 100644 --- a/account_analytic_distribution_manual/hooks.py +++ b/account_analytic_distribution_manual/hooks.py @@ -182,3 +182,14 @@ def post_init_hook(cr, registry): """, (distribution_map[tag_id].id, res_id), ) + # Define the value of manual_distribution_id in the line items + env.cr.execute( + """ + UPDATE account_analytic_line AS aal + SET manual_distribution_id = aml.manual_distribution_id + FROM account_move_line AS aml + WHERE aal.move_line_id = aml.id + AND aml.manual_distribution_id IS NOT NULL + AND aal.manual_distribution_id IS NULL + """, + ) diff --git a/account_analytic_distribution_manual/migrations/16.0.2.3.0/post-migration.py b/account_analytic_distribution_manual/migrations/16.0.2.3.0/post-migration.py new file mode 100644 index 0000000000..c564a8b3d7 --- /dev/null +++ b/account_analytic_distribution_manual/migrations/16.0.2.3.0/post-migration.py @@ -0,0 +1,19 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.logged_query( + env.cr, + """ + UPDATE account_analytic_line AS aal + SET manual_distribution_id = aml.manual_distribution_id + FROM account_move_line AS aml + WHERE aal.move_line_id = aml.id + AND aml.manual_distribution_id IS NOT NULL + AND aal.manual_distribution_id IS NULL + """, + ) diff --git a/account_analytic_distribution_manual/models/__init__.py b/account_analytic_distribution_manual/models/__init__.py index 1b1cb07792..acc328512d 100644 --- a/account_analytic_distribution_manual/models/__init__.py +++ b/account_analytic_distribution_manual/models/__init__.py @@ -1,3 +1,5 @@ from . import account_analytic_distribution_manual +from . import account_analytic_line +from . import account_move_line from . import analytic_mixin from . import base diff --git a/account_analytic_distribution_manual/models/account_analytic_line.py b/account_analytic_distribution_manual/models/account_analytic_line.py new file mode 100644 index 0000000000..d42ed82304 --- /dev/null +++ b/account_analytic_distribution_manual/models/account_analytic_line.py @@ -0,0 +1,12 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# 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" + + manual_distribution_id = fields.Many2one( + comodel_name="account.analytic.distribution.manual", + string="Analytic distribution manual", + ) diff --git a/account_analytic_distribution_manual/models/account_move_line.py b/account_analytic_distribution_manual/models/account_move_line.py new file mode 100644 index 0000000000..d287baa4e7 --- /dev/null +++ b/account_analytic_distribution_manual/models/account_move_line.py @@ -0,0 +1,14 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# 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() + if self.manual_distribution_id: + for val in vals: + val.update({"manual_distribution_id": self.manual_distribution_id.id}) + return vals diff --git a/account_analytic_distribution_manual/static/description/index.html b/account_analytic_distribution_manual/static/description/index.html index a1a3ec7a12..5ae20af3f1 100644 --- a/account_analytic_distribution_manual/static/description/index.html +++ b/account_analytic_distribution_manual/static/description/index.html @@ -8,11 +8,10 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ +:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z 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. @@ -275,7 +274,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: gray; } /* line numbers */ +pre.code .ln { color: grey; } /* 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 } @@ -301,7 +300,7 @@ span.pre { white-space: pre } -span.problematic, pre.problematic { +span.problematic { color: red } span.section-subtitle { @@ -434,9 +433,7 @@

Contributors

Maintainers

This module is maintained by the OCA.

- -Odoo Community Association - +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.

diff --git a/account_analytic_distribution_manual/tests/test_analytic_distribution_manual.py b/account_analytic_distribution_manual/tests/test_analytic_distribution_manual.py index ba062b1d6b..137e77ee75 100644 --- a/account_analytic_distribution_manual/tests/test_analytic_distribution_manual.py +++ b/account_analytic_distribution_manual/tests/test_analytic_distribution_manual.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) from psycopg2.errors import UniqueViolation -from odoo.tests import tagged +from odoo.tests import Form, tagged from odoo.tools import mute_logger from odoo.addons.account_analytic_distribution_manual.tests.common import ( @@ -26,6 +26,24 @@ def test_copy_manual_distribution(self): } ) + def test_manual_distribution_analytic_distribution_process(self): + invoice_form = Form( + self.env["account.move"].with_context(default_move_type="out_invoice") + ) + invoice_form.partner_id = self.partner_a + with invoice_form.invoice_line_ids.new() as line_form: + line_form.product_id = self.product_a + line_form.manual_distribution_id = self.distribution_1 + invoice = invoice_form.save() + invoice_line = invoice.invoice_line_ids + invoice_line.analytic_distribution = self.distribution_1.analytic_distribution + invoice.action_post() + self.assertTrue(len(invoice_line.analytic_line_ids), 2) + self.assertEqual( + invoice_line.analytic_line_ids.mapped("manual_distribution_id"), + self.distribution_1, + ) + def test_manual_distribution_analytic_distribution_text(self): self.analytic_account_a1.name = "test-1" aa_1 = self.analytic_account_a1 diff --git a/account_analytic_distribution_manual/views/account_analytic_line_views.xml b/account_analytic_distribution_manual/views/account_analytic_line_views.xml new file mode 100644 index 0000000000..7dad33c2df --- /dev/null +++ b/account_analytic_distribution_manual/views/account_analytic_line_views.xml @@ -0,0 +1,22 @@ + + + account.analytic.line.tree + account.analytic.line + + + + + + + + + account.analytic.line.form + account.analytic.line + + + + + + + +