[FIX] base: consider multi_edit="1" views editable

Since odoo/odoo#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: odoo/odoo#103790
This commit is contained in:
FrancoisGe
2022-10-23 12:30:03 +02:00
committed by Denis Ledoux
parent f255306e56
commit c998fdd77b
15 changed files with 24 additions and 7 deletions
@@ -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"/>
@@ -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"/>
+2
View File
@@ -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"/>
@@ -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"/>
@@ -239,6 +239,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"/>
@@ -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"/>
@@ -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"/>
@@ -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"/>
+2
View File
@@ -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"/>
@@ -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>
@@ -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"/>
+1
View File
@@ -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"/>
@@ -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"/>
@@ -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"/>
+2
View File
@@ -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"/>
@@ -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"/>
@@ -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];
});
@@ -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];
@@ -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;
}
}
+1 -1
View File
@@ -1319,7 +1319,7 @@ actual arch.
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'))