|
|
@@ -577,6 +577,28 @@ class HelpdeskTeamExtras(models.Model):
|
|
|
html_str = etree.tostring(field_el, encoding='unicode', pretty_print=True)
|
|
|
return html_str, field_id_counter
|
|
|
|
|
|
+ def _get_relation_domain(self, relation_model, env):
|
|
|
+ """Get domain for relation model, filtering by active=True if the model has an active field
|
|
|
+
|
|
|
+ Args:
|
|
|
+ relation_model: Model name (string)
|
|
|
+ env: Environment
|
|
|
+ Returns:
|
|
|
+ list: Domain list, e.g. [] or [('active', '=', True)]
|
|
|
+ """
|
|
|
+ if not relation_model:
|
|
|
+ return []
|
|
|
+
|
|
|
+ try:
|
|
|
+ model = env[relation_model]
|
|
|
+ # Check if model has an 'active' field
|
|
|
+ if 'active' in model._fields:
|
|
|
+ return [('active', '=', True)]
|
|
|
+ except (KeyError, AttributeError):
|
|
|
+ pass
|
|
|
+
|
|
|
+ return []
|
|
|
+
|
|
|
def _build_template_field_xml(self, template_field, field_id_counter=0, env_lang=None):
|
|
|
"""Build XML element for a template field exactly as Odoo's form builder does
|
|
|
|
|
|
@@ -1017,8 +1039,9 @@ class HelpdeskTeamExtras(models.Model):
|
|
|
relation = field.relation
|
|
|
if relation and relation != 'ir.attachment':
|
|
|
try:
|
|
|
+ domain = self._get_relation_domain(relation, env)
|
|
|
records = env[relation].sudo().search_read(
|
|
|
- [], ['display_name'], limit=1000
|
|
|
+ domain, ['display_name'], limit=1000
|
|
|
)
|
|
|
for record in records:
|
|
|
radio_div = etree.SubElement(radio_wrapper, 'div', {
|
|
|
@@ -1056,8 +1079,9 @@ class HelpdeskTeamExtras(models.Model):
|
|
|
relation = field.relation
|
|
|
if relation and relation != 'ir.attachment':
|
|
|
try:
|
|
|
+ domain = self._get_relation_domain(relation, env)
|
|
|
records = env[relation].sudo().search_read(
|
|
|
- [], ['display_name'], limit=1000
|
|
|
+ domain, ['display_name'], limit=1000
|
|
|
)
|
|
|
default_values = template_field.default_value.split(',') if template_field.default_value else []
|
|
|
for record in records:
|
|
|
@@ -1127,8 +1151,9 @@ class HelpdeskTeamExtras(models.Model):
|
|
|
if relation and relation != 'ir.attachment':
|
|
|
try:
|
|
|
# Try to get records from the relation model with language context
|
|
|
+ domain = self._get_relation_domain(relation, env)
|
|
|
records = env[relation].sudo().search_read(
|
|
|
- [], ['display_name'], limit=1000
|
|
|
+ domain, ['display_name'], limit=1000
|
|
|
)
|
|
|
for record in records:
|
|
|
option = etree.SubElement(input_el, 'option', {
|
|
|
@@ -1211,8 +1236,9 @@ class HelpdeskTeamExtras(models.Model):
|
|
|
relation = field.relation
|
|
|
if relation:
|
|
|
try:
|
|
|
+ domain = self._get_relation_domain(relation, env)
|
|
|
records = env[relation].sudo().search_read(
|
|
|
- [], ['display_name'], limit=100
|
|
|
+ domain, ['display_name'], limit=100
|
|
|
)
|
|
|
for record in records:
|
|
|
checkbox_div = etree.SubElement(multiple_div, 'div', {
|