Skip to content

Commit

Permalink
[ENH] analytic_tag_dimension_enhanced: add exclude required module
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed May 12, 2023
1 parent 3e9a3b9 commit 8fdc74b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions analytic_tag_dimension/tests/test_analytic_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.exceptions import ValidationError
from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase

from ..hooks import uninstall_hook


class TestAnalyticDimensionBase(SavepointCase):
class TestAnalyticDimensionBase(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class AccountAnalyticDimension(models.Model):
default=False,
help="If required, this dimension needed to be selected in working document",
)
exclude_required = fields.Many2many(
comodel_name="ir.model",
string="Exclude Module Required",
)
by_sequence = fields.Boolean(
default=False,
help="If checked, this dimemsion's tags will be available "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def _check_required_dimension(self, record):
tags_dimension = self.filtered("analytic_dimension_id.required")
dimensions = tags_dimension.mapped("analytic_dimension_id")
missing = req_dimensions - dimensions
# Check record in exclude required, it will skip it
if (
req_dimensions
and req_dimensions.exclude_required
and record._name in req_dimensions.exclude_required.mapped("model")
):
missing = False
if missing:
raise ValidationError(
_("Following dimension(s) not selected: %s")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_invoice_line_dimension_required(self):
"""
self.dimension_1.required = True
self.dimension_2.required = True
model = self.env["ir.model"].search([("model", "=", "account.move.line")])

values = {
"name": "test",
Expand All @@ -54,6 +55,12 @@ def test_invoice_line_dimension_required(self):
# Error if missing required dimension
with self.assertRaises(ValidationError):
invoice_line_obj.create(values)

# Exclude required dimension (for some model)
self.dimension_1.exclude_required = model
line = invoice_line_obj.create(values)
self.assertTrue(line.x_dimension_test_dim_1.id == self.analytic_tag_1a.id)

self.invoice.invoice_line_ids.unlink()
values["analytic_tag_ids"] = [
(6, 0, [self.analytic_tag_1a.id, self.analytic_tag_2a.id])
Expand Down
5 changes: 5 additions & 0 deletions analytic_tag_dimension_enhanced/views/analytic_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<field name="code" position="after">
<separator colspan="2" />
<field name="required" />
<field
name="exclude_required"
widget="many2many_tags"
attrs="{'invisible': [('required', '=', False)]}"
/>
<label for="by_sequence" />
<div>
<field name="by_sequence" class="oe_inline" />
Expand Down

0 comments on commit 8fdc74b

Please sign in to comment.