[IMP] bi_sql_editor : add field context

This commit is contained in:
Sylvain LE GAL
2021-12-16 19:40:56 +01:00
committed by OCA-git-bot
parent edecab16a2
commit c55dc6f287
3 changed files with 36 additions and 4 deletions

View File

@@ -168,6 +168,12 @@ class BiSQLView(models.Model):
sequence = fields.Integer(string="sequence")
option_context_field = fields.Boolean(
string="Use Context Field",
help="Check this box if you want to add a context column in the field list view."
" Custom Context will be inserted in the created views.",
)
# Constrains Section
@api.constrains("is_materialized")
def _check_index_materialized(self):

View File

@@ -127,6 +127,12 @@ class BiSQLViewField(models.Model):
"to alter the behaviour, choose an alternate Group Operator",
)
field_context = fields.Char(
default="{}",
help="Context value that will be inserted for this field in all the views."
" Important note : please write a context with single quote.",
)
# Constrains Section
@api.constrains("is_index")
def _check_index_materialized(self):
@@ -231,22 +237,34 @@ class BiSQLViewField(models.Model):
elif self.tree_visibility == "optional_show":
visibility_text = 'option="show"'
return f"""<field name="{self.name}" {visibility_text}/>\n"""
return (
f"""<field name="{self.name}" {visibility_text} """
f""" context="{self.field_context}"/>\n"""
)
def _prepare_graph_field(self):
self.ensure_one()
if not self.graph_type:
return ""
return f"""<field name="{self.name}" type="{self.graph_type}" />\n"""
return (
f"""<field name="{self.name}" type="{self.graph_type}" """
f""" context="{self.field_context}"/>\n"""
)
def _prepare_pivot_field(self):
self.ensure_one()
graph_type_text = self.graph_type and f'type="{self.graph_type}"' or ""
return f"""<field name="{self.name}" {graph_type_text} />\n"""
return (
f"""<field name="{self.name}" {graph_type_text} """
f"""context="{self.field_context}"/>\n"""
)
def _prepare_search_field(self):
self.ensure_one()
return """<field name="{}"/>\n""".format(self.name)
return """<field name="{}" context="{}"/>\n""".format(
self.name,
self.field_context,
)
def _prepare_search_filter_field(self):
self.ensure_one()

View File

@@ -98,6 +98,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
name="cron_id"
attrs="{'invisible': ['|', ('state', 'in', ('draft', 'sql_valid')), ('is_materialized', '=', False)]}"
/>
<field name="option_context_field" />
</group>
</group>
<page name="page_sql" position="after">
@@ -160,6 +161,13 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
optional="hide"
attrs="{'invisible': [('field_description', '=', False)]}"
/>
<field
name="field_context"
attrs="{
'invisible': [('field_description', '=', False)],
'column_invisible': [('parent.option_context_field', '=', False)],
}"
/>
</tree>
</field>
</page>