Skip to content

Commit

Permalink
[FIX] base: consider multi_edit="1" views editable
Browse files Browse the repository at this point in the history
Since #95729

nodes with a `groups=` are completely removed from the views when
the user is not part of the group, instead of being made invisible.

In that PR, views have been adapted to add back fields, with invisible="1",
when they were required, for instance when they were used in a domain
of another field which was still there despite the user is not part
of the given group.

As `tree` views having `multi_edit="1"` where not considered
as editable views, the domain of fields in these views were not
validated:
- https://github.com/odoo/odoo/blob/1fb8fa16ab7dc298d54f089d7163fb556dbc5fcc/odoo/addons/base/models/ir_ui_view.py#L1460
- https://github.com/odoo/odoo/blob/1fb8fa16ab7dc298d54f089d7163fb556dbc5fcc/odoo/addons/base/models/ir_ui_view.py#L1321-L1322

while they are well required for the web client,
in `multi_edit="1"` this is possible to edit relational/many2one field,
and therefore it will do `name_search` calls using the domain of the
field, and therefore the fields used in these domains must always
be present in the views. Without it, a crash in the web client occurs
when attempting to edit the relational/many2one field.

This revision targets to consider the `multi_edit="1"` tree views
as editable, to make the field domains validated as they should be.

Hence, views are adapted to add back fields with `invisible="1"`
when they are required in domains of other fields.

Part-of: #103743
  • Loading branch information
FrancoisGe authored and beledouxdenis committed Oct 21, 2022
1 parent e08858e commit f974eeb
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions addons/analytic/views/analytic_account_views.xml
Expand Up @@ -52,6 +52,7 @@
<field eval="8" name="priority"/>
<field name="arch" type="xml">
<tree string="Analytic Accounts" multi_edit="1">
<field name="company_id" invisible="1"/>
<field name="name" string="Name"/>
<field name="code"/>
<field name="partner_id"/>
Expand Down
2 changes: 2 additions & 0 deletions addons/analytic/views/analytic_line_views.xml
Expand Up @@ -5,6 +5,8 @@
<field name="model">account.analytic.line</field>
<field name="arch" type="xml">
<tree string="Analytic Items" multi_edit="1">
<field name="company_id" invisible="1"/>
<field name="product_uom_category_id" invisible="1"/>
<field name="date" optional="show"/>
<field name="name"/>
<field name="account_id"/>
Expand Down
2 changes: 2 additions & 0 deletions addons/crm/views/crm_lead_views.xml
Expand Up @@ -362,6 +362,7 @@
<field name="priority">10</field>
<field name="arch" type="xml">
<tree string="Leads" sample="1" multi_edit="1">
<field name="company_id" invisible="1"/>
<field name="date_deadline" invisible="1"/>
<field name="create_date" optional="hide"/>
<field name="name" string="Lead" readonly="1"/>
Expand Down Expand Up @@ -763,6 +764,7 @@
<header>
<button name="%(crm.action_lead_mass_mail)d" type="action" string="Email" />
</header>
<field name="company_id" invisible="1"/>
<field name="date_deadline" invisible="1"/>
<field name="create_date" optional="hide"/>
<field name="name" string="Opportunity" readonly="1"/>
Expand Down
1 change: 1 addition & 0 deletions addons/hr_contract/views/hr_contract_views.xml
Expand Up @@ -227,6 +227,7 @@
<field name="model">hr.contract</field>
<field name="arch" type="xml">
<tree string="Contracts" multi_edit="1" sample="1" default_order='date_start ASC'>
<field name="company_id" invisible="1"/>
<field name="name" readonly="1"/>
<field name="employee_id" readonly="1" widget="many2one_avatar_employee"/>
<field name="job_id"/>
Expand Down
2 changes: 2 additions & 0 deletions addons/hr_expense/views/hr_expense_views.xml
Expand Up @@ -45,6 +45,7 @@
<field name="model">hr.expense</field>
<field name="arch" type="xml">
<tree string="Expenses" multi_edit="1" sample="1" js_class="hr_expense_tree" decoration-info="state == 'draft'">
<field name="company_id" invisible="1"/>
<field name="company_currency_id" invisible="1"/>
<field name="attachment_number" invisible="True"/>
<field name="date" optional="show"/>
Expand Down Expand Up @@ -613,6 +614,7 @@
<field name="model">hr.expense.sheet</field>
<field name="arch" type="xml">
<tree string="Expense Reports" multi_edit="1" js_class="hr_expense_tree" sample="1" decoration-info="state == 'draft'">
<field name="company_id" invisible="1"/>
<field name="product_ids" invisible="1"/>
<field name="employee_id" widget="many2one_avatar_employee"/>
<field name="accounting_date" optional="hide" groups="account.group_account_manager"/>
Expand Down
2 changes: 2 additions & 0 deletions addons/mrp/views/mrp_production_views.xml
Expand Up @@ -12,6 +12,8 @@
<button name="do_unreserve" type="object" string="Unreserve"/>
<button name="action_cancel" type="object" string="Cancel"/>
</header>
<field name="company_id" invisible="1"/>
<field name="product_uom_category_id" invisible="1"/>
<field name="priority" optional="show" widget="priority" nolabel="1"/>
<field name="message_needaction" invisible="1"/>
<field name="name" decoration-bf="1"/>
Expand Down
2 changes: 2 additions & 0 deletions addons/mrp/views/mrp_routing_views.xml
Expand Up @@ -7,6 +7,7 @@
<field name="model">mrp.routing.workcenter</field>
<field name="arch" type="xml">
<tree string="Routing Work Centers" multi_edit="1">
<field name="company_id" invisible="1"/>
<field name="name"/>
<field name="bom_id"/>
<field name="workcenter_id"/>
Expand Down Expand Up @@ -53,6 +54,7 @@
<xpath expr="//field[@name='blocked_by_operation_ids']" position="replace">
</xpath>
<xpath expr="//field[@name='name']" position="after">
<field name="bom_id" invisible="1"/>
<field name="blocked_by_operation_ids" widget="many2many_tags" optional="hide" attrs="{'column_invisible': [('parent.allow_operation_dependencies', '=', False)]}"/>
</xpath>
</field>
Expand Down
1 change: 1 addition & 0 deletions addons/mrp/views/mrp_workcenter_views.xml
Expand Up @@ -33,6 +33,7 @@
<field name="model">mrp.workcenter</field>
<field name="arch" type="xml">
<tree string="Work Center" multi_edit="1">
<field name="company_id" invisible="1"/>
<field name="sequence" widget="handle"/>
<field name="name" optional="show"/>
<field name="code" optional="show"/>
Expand Down
19 changes: 18 additions & 1 deletion addons/project/views/project_views.xml
Expand Up @@ -1526,11 +1526,28 @@
</field>
</record>

<!--
The below view is invalid since `multi_edit="1"` has been set on the tree
https://github.com/odoo/odoo/commit/972e097dbe7cdc7afdae722391692f9b3bf063b8#diff-db3b2f2e90f34ffef22194c3eac5a34b17af9b9a0a644d77da9e80738963931eL859
because `activity_type_id` uses in his domain a field `res_model`
which is not available in the view and not even in the model.
It has not been detected because:
- this view is unused / impossible to reach since Odoo 12.0,
and therefore nobody tried to edit the many2one field `activity_type_id` which would trigger the issue
- the field domains were not validated because `multi_edit="1"` tree views were not considered as editable,
and therefore their field domains were not validated in the views validation, as they should have been.
This view has been removed in master as it was no longer used,
through https://github.com/odoo/odoo/pull/103702.
We cannot remove it in 16.0 because it would require an upgrade script.
Hence we just remove the multi_edit="1" so the view is not validated
and the domain is not used in the web client.
-->
<record id="project_task_view_tree_activity" model="ir.ui.view">
<field name="name">project.task.tree.activity</field>
<field name="model">project.task</field>
<field name="arch" type="xml">
<tree string="Next Activities" decoration-danger="not is_closed and activity_date_deadline &lt; current_date" default_order="activity_date_deadline" multi_edit="1">
<tree string="Next Activities" decoration-danger="not is_closed and activity_date_deadline &lt; current_date" default_order="activity_date_deadline">
<field name="company_id" invisible="1"/>
<field name="is_closed"/>
<field name="name"/>
<field name="project_id" options="{'no_open': 1}"/>
Expand Down
1 change: 1 addition & 0 deletions addons/repair/views/repair_views.xml
Expand Up @@ -7,6 +7,7 @@
<field name="model">repair.order</field>
<field name="arch" type="xml">
<tree string="Repairs order" multi_edit="1" sample="1" decoration-info="state == 'draft'">
<field name="company_id" invisible="1"/>
<field name="priority" optional="show" widget="priority" nolabel="1"/>
<field name="name"/>
<field name="schedule_date" optional="show" widget="remaining_days"/>
Expand Down
1 change: 1 addition & 0 deletions addons/stock/views/stock_location_views.xml
Expand Up @@ -91,6 +91,7 @@
<field name="priority" eval="2"/>
<field name="arch" type="xml">
<tree string="Stock Location" decoration-info="usage=='view'" decoration-danger="usage=='internal'" multi_edit="1">
<field name="company_id" invisible="1"/>
<field name="active" invisible="1"/>
<field name="complete_name" string="Location"/>
<field name="usage"/>
Expand Down
1 change: 1 addition & 0 deletions addons/stock/views/stock_picking_views.xml
Expand Up @@ -65,6 +65,7 @@
<button name="do_unreserve" type="object" string="Unreserve"/>
<button name="action_assign" type="object" string="Check Availability"/>
</header>
<field name="company_id" invisible="1"/>
<field name="priority" optional="show" widget="priority" nolabel="1"/>
<field name="name" decoration-bf="1"/>
<field name="location_id" options="{'no_create': True}" string="From" groups="stock.group_stock_multi_locations" optional="show"/>
Expand Down
2 changes: 2 additions & 0 deletions addons/stock/views/stock_scrap_views.xml
Expand Up @@ -121,6 +121,8 @@
<field name="model">stock.scrap</field>
<field name="arch" type="xml">
<tree multi_edit="1" sample="1" decoration-info="state == 'draft'">
<field name="company_id" invisible="1"/>
<field name="product_uom_category_id" invisible="1"/>
<field name="name" decoration-bf="1"/>
<field name="date_done"/>
<field name="product_id" readonly="1"/>
Expand Down
Expand Up @@ -174,6 +174,7 @@
<field name="model">stock.picking.batch</field>
<field name="arch" type="xml">
<tree string="Stock Batch Transfer" multi_edit="1" sample="1">
<field name="company_id" invisible="1"/>
<field name="name" decoration-bf="1"/>
<field name="scheduled_date"/>
<field name="user_id" widget="many2one_avatar_user"/>
Expand Down
10 changes: 4 additions & 6 deletions addons/web/static/tests/helpers/mock_server.js
Expand Up @@ -286,7 +286,7 @@ export class MockServer {
}
const defaultValues = {};
const stateExceptions = {}; // what is this ?
(editableView && modifiersNames || ["invisible"]).forEach((attr) => {
((editableView && modifiersNames) || ["invisible"]).forEach((attr) => {
stateExceptions[attr] = [];
defaultValues[attr] = !!field[attr];
});
Expand Down Expand Up @@ -467,7 +467,7 @@ export class MockServer {
case "form":
return true;
case "tree":
return !!node.getAttribute("editable");
return node.getAttribute("editable") || node.getAttribute("multi_edit");
case "field": {
const fname = node.getAttribute("name");
const field = this.models[modelName].fields[fname];
Expand All @@ -489,11 +489,9 @@ export class MockServer {
_onchangeAbleView(node) {
if (node.tagName === "form") {
return true;
}
else if (node.tagName === "tree") {
} else if (node.tagName === "tree") {
return true;
}
else if (node.tagName === "kanban") {
} else if (node.tagName === "kanban") {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion odoo/addons/base/models/ir_ui_view.py
Expand Up @@ -1319,7 +1319,7 @@ def _editable_tag_form(self, node, name_manager):
return True

def _editable_tag_tree(self, node, name_manager):
return node.get('editable')
return node.get('editable') or node.get('multi_edit')

def _editable_tag_field(self, node, name_manager):
field = name_manager.model._fields.get(node.get('name'))
Expand Down

0 comments on commit f974eeb

Please sign in to comment.