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 Sep 26, 2023
1 parent ca3e702 commit d7c2bf3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion analytic_tag_dimension_enhanced/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["analytic_tag_dimension"],
"data": ["views/analytic_view.xml", "views/account_move_view.xml"],
"data": [
"security/ir.model.access.csv",
"views/analytic_view.xml",
"views/account_move_view.xml",
],
"installable": True,
}
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
10 changes: 9 additions & 1 deletion analytic_tag_dimension_enhanced/models/account_analytic_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,23 @@ def _check_required_dimension(self, record):
and record.move_id.move_type == "entry"
)
or ("display_type" in record and record.display_type)
or self._context.get("bypass_required_dimension")
):
return
Dimension = self.env["account.analytic.dimension"]
req_dimensions = Dimension.search([("required", "=", True)])
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")
_("Following analytic tag dimension(s) not selected: %s")
% ", ".join(missing.mapped("name"))
)
2 changes: 2 additions & 0 deletions analytic_tag_dimension_enhanced/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_ir_model_analytic_tags,access_ir_model_analytic_tags,base.model_ir_model,analytic.group_analytic_tags,1,0,0,0
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
6 changes: 6 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,12 @@
<field name="code" position="after">
<separator colspan="2" />
<field name="required" />
<field
name="exclude_required"
widget="many2many_tags"
attrs="{'invisible': [('required', '=', False)]}"
options="{'no_create_edit': True, 'no_create': True}"
/>
<label for="by_sequence" />
<div>
<field name="by_sequence" class="oe_inline" />
Expand Down

0 comments on commit d7c2bf3

Please sign in to comment.