Skip to content

Commit

Permalink
Merge PR #824 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by simahawk
  • Loading branch information
OCA-git-bot committed Oct 4, 2023
2 parents 71ff30d + 91f71b8 commit e0e3d43
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
8 changes: 7 additions & 1 deletion edi_oca/models/edi_exchange_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EDIExchangeType(models.Model):
_name = "edi.exchange.type"
_description = "EDI Exchange Type"

active = fields.Boolean(default=True)
active = fields.Boolean(default=True, inverse="_inverse_active")
backend_id = fields.Many2one(
string="Backend",
comodel_name="edi.backend",
Expand Down Expand Up @@ -161,6 +161,12 @@ class EDIExchangeType(models.Model):
)
]

def _inverse_active(self):
for rec in self:
# Disable rules if type gets disabled
if not rec.active:
rec.rule_ids.active = False

@api.depends("advanced_settings_edit")
def _compute_advanced_settings(self):
for rec in self:
Expand Down
22 changes: 22 additions & 0 deletions edi_oca/tests/test_exchange_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,25 @@ def test_filename_pattern_settings(self):
date_pattern: '%Y-%m-%d-%H-%M'
"""
self._test_exchange_filename("Test-File-2022-04-28-10-37.csv")

def test_archive_rules(self):
exc_type = self.exchange_type_out
rule1 = exc_type.rule_ids.create(
{
"type_id": exc_type.id,
"name": "Fake partner rule",
"model_id": self.env["ir.model"]._get("res.partner").id,
}
)
rule2 = exc_type.rule_ids.create(
{
"type_id": exc_type.id,
"name": "Fake user rule",
"model_id": self.env["ir.model"]._get("res.users").id,
}
)
exc_type.active = False
rule1.invalidate_cache()
rule2.invalidate_cache()
self.assertFalse(rule1.active)
self.assertFalse(rule2.active)
11 changes: 9 additions & 2 deletions edi_oca/views/edi_exchange_type_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
context="{'default_type_id': active_id}"
>
<tree decoration-muted="(not active)">
<field name="active" invisible="1" />
<field name="active" widget="boolean_toggle" />
<field name="name" />
<field name="model_id" />
<field name="kind" />
Expand Down Expand Up @@ -168,7 +168,14 @@
<field name="view_mode">tree,form</field>
<field name="search_view_id" ref="edi_exchange_type_view_search" />
<field name="domain">[]</field>
<field name="context">{'search_default_filter_all': 1}</field>
<!--
`active_test` here is fundamental to see archived `rule_ids`.
Reason: when related fields are loaded with a `read`
the ctx that you could set at field level on the view is lost.
-->
<field
name="context"
>{'search_default_filter_all': 1, 'active_test': False}</field>
</record>
<record
model="ir.actions.act_window.view"
Expand Down

0 comments on commit e0e3d43

Please sign in to comment.