Skip to content

Commit

Permalink
[IMP] account_analytic_distribution_manual: Add manual_distribution_i…
Browse files Browse the repository at this point in the history
…d field to analytic items

TT50751
  • Loading branch information
victoralmau committed Sep 9, 2024
1 parent b4497f2 commit f52bc5b
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 9 deletions.
3 changes: 2 additions & 1 deletion account_analytic_distribution_manual/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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": [
Expand Down
11 changes: 11 additions & 0 deletions account_analytic_distribution_manual/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 186 in account_analytic_distribution_manual/hooks.py

View check run for this annotation

Codecov / codecov/patch

account_analytic_distribution_manual/hooks.py#L186

Added line #L186 was not covered by tests
"""
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
""",
)
Original file line number Diff line number Diff line change
@@ -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
""",
)
2 changes: 2 additions & 0 deletions account_analytic_distribution_manual/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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",
)
14 changes: 14 additions & 0 deletions account_analytic_distribution_manual/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

/*
:Author: David Goodger ([email protected])
: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.
Expand Down Expand Up @@ -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 }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -434,9 +433,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<odoo>
<record id="view_account_analytic_line_tree" model="ir.ui.view">
<field name="name">account.analytic.line.tree</field>
<field name="model">account.analytic.line</field>
<field name="inherit_id" ref="analytic.view_account_analytic_line_tree" />
<field name="arch" type="xml">
<field name="amount" position="after">
<field name="manual_distribution_id" optional="hide" />
</field>
</field>
</record>
<record id="view_account_analytic_line_form" model="ir.ui.view">
<field name="name">account.analytic.line.form</field>
<field name="model">account.analytic.line</field>
<field name="inherit_id" ref="analytic.view_account_analytic_line_form" />
<field name="arch" type="xml">
<field name="account_id" position="after">
<field name="manual_distribution_id" />
</field>
</field>
</record>
</odoo>

0 comments on commit f52bc5b

Please sign in to comment.