Skip to content

Commit 6ae0372

Browse files
committed
[FIX] server_action_mass_edit : Fixed the wizard errors.
1 parent 88aaf44 commit 6ae0372

File tree

5 files changed

+76
-17
lines changed

5 files changed

+76
-17
lines changed

server_action_mass_edit/__manifest__.py

+6
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,11 @@
2020
"views/ir_actions_server.xml",
2121
"wizard/mass_editing_wizard.xml",
2222
],
23+
"assets": {
24+
"web.assets_backend": [
25+
"/server_action_mass_edit/static/src/js/record.esm.js",
26+
"/server_action_mass_edit/static/src/js/static_list.esm.js",
27+
]
28+
},
2329
"demo": ["demo/mass_editing.xml"],
2430
}

server_action_mass_edit/models/ir_actions_server_mass_edit_line.py

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class IrActionsServerMassEditLine(models.Model):
3333
("name", "not in", %s),
3434
("ttype", "not in", ["reference", "function"]),
3535
("model_id", "=", model_id),
36+
("readonly", "!=", True),
3637
]
3738
"""
3839
% str(MAGIC_FIELDS),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/** @odoo-module **/
2+
import {Record} from "@web/model/relational_model/record";
3+
import {patch} from "@web/core/utils/patch";
4+
5+
patch(Record.prototype, {
6+
_createStaticListDatapoint(data, fieldName) {
7+
const {related, limit, defaultOrderBy} = this.activeFields[fieldName];
8+
const config = {
9+
resModel: this.fields[fieldName].relation,
10+
activeFields: (related && related.activeFields) || {},
11+
fields: (related && related.fields) || {},
12+
relationField: this.fields[fieldName].relation_field || false,
13+
offset: 0,
14+
// To prevent the TypeError: data.map is not a function while set/remove/add
15+
// value in wizard
16+
resIds: Array.isArray(data) ? data.map((r) => r.id || null) : [],
17+
orderBy: defaultOrderBy || [],
18+
limit: limit || Number.MAX_SAFE_INTEGER,
19+
currentCompanyId: this.currentCompanyId,
20+
context: {},
21+
};
22+
const options = {
23+
onUpdate: ({withoutOnchange} = {}) =>
24+
this._update({[fieldName]: []}, {withoutOnchange}),
25+
parent: this,
26+
};
27+
return new this.model.constructor.StaticList(this.model, config, data, options);
28+
},
29+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/** @odoo-module **/
2+
import {StaticList} from "@web/model/relational_model/static_list";
3+
import {markRaw} from "@odoo/owl";
4+
import {patch} from "@web/core/utils/patch";
5+
6+
patch(StaticList.prototype, {
7+
setup(config, data, options = {}) {
8+
this._parent = options.parent;
9+
this._onUpdate = options.onUpdate;
10+
11+
this._cache = markRaw({});
12+
this._commands = [];
13+
this._savePoint = undefined;
14+
this._unknownRecordCommands = {};
15+
this._currentIds = [...this.resIds];
16+
this._needsReordering = false;
17+
this._tmpIncreaseLimit = 0;
18+
this._extendedRecords = new Set();
19+
// To prevent the TypeError: data.slice is not a function" while set/remove/add
20+
// value in wizard
21+
this.records = Array.isArray(data)
22+
? data
23+
.slice(this.offset, this.limit)
24+
.map((r) => this._createRecordDatapoint(r))
25+
: [];
26+
this.count = this.resIds.length;
27+
this.handleField = Object.keys(this.activeFields).find(
28+
(fieldName) => this.activeFields[fieldName].isHandle
29+
);
30+
},
31+
});

server_action_mass_edit/wizard/mass_editing_wizard.py

+9-17
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def default_get(self, fields):
2525
res = super().default_get(fields)
2626
server_action_id = self.env.context.get("server_action_id")
2727
server_action = self.env["ir.actions.server"].sudo().browse(server_action_id)
28+
active_ids = self.env.context.get("active_ids")
2829

2930
if not server_action:
3031
return res
3132

32-
active_ids = self.env.context.get("active_ids") or self.env["ir.actions.server"]
3333
original_active_ids = self.env.context.get("original_active_ids", active_ids)
3434
operation_description_info = False
3535
operation_description_warning = False
@@ -121,7 +121,7 @@ def _prepare_fields(self, line, field, field_info):
121121
if field.ttype == "many2many":
122122
selection = [
123123
("ignore", _("Don't touch")),
124-
("set", _("Set")),
124+
("set_m2m", _("Set")),
125125
("remove_m2m", _("Remove")),
126126
("add", _("Add")),
127127
]
@@ -181,9 +181,9 @@ def _insert_field_in_arch(self, line, field, main_xml_group):
181181
dummy, tree_view = comodel._get_view(view_type="tree")
182182
field_context = {}
183183
if form_view:
184-
field_context["form_view_ref"] = form_view.id
184+
field_context["form_view_ref"] = form_view.xml_id
185185
if tree_view:
186-
field_context["tree_view_ref"] = tree_view.id
186+
field_context["tree_view_ref"] = tree_view.xml_id
187187
if field_context:
188188
field_element.attrib["context"] = json.dumps(field_context)
189189
else:
@@ -204,9 +204,7 @@ def _insert_field_in_arch(self, line, field, main_xml_group):
204204
def _get_field_options(self, field):
205205
return {
206206
"name": field.name,
207-
"modifiers": '{"invisible": "\
208-
"[["selection__%s", "in", ["ignore", "remove"]]]}'
209-
% field.name,
207+
"invisible": 'selection__%s in ["ignore", "remove", False]' % field.name,
210208
"class": "w-75",
211209
}
212210

@@ -284,11 +282,9 @@ def create(self, vals_list):
284282
if key.startswith("selection_"):
285283
split_key = key.split("__", 1)[1]
286284
if val == "set" or val == "add_o2m":
287-
if val == "set":
288-
vals[split_key] = vals[split_key][0][1:]
289285
values.update({split_key: vals.get(split_key, False)})
290286

291-
elif val == "set_o2m":
287+
elif val == "set_o2m" or val == "set_m2m":
292288
values.update(
293289
{split_key: [(6, 0, [])] + vals.get(split_key, [])}
294290
)
@@ -299,19 +295,15 @@ def create(self, vals_list):
299295
elif val == "remove_m2m":
300296
m2m_list = []
301297
if vals.get(split_key):
302-
vals[split_key][0] = vals[split_key][0][1:]
303-
for m2m_id in vals.get(split_key, False)[0]:
304-
m2m_list.append((3, m2m_id))
298+
for m2m_id in vals.get(split_key, False):
299+
m2m_list.append((3, m2m_id[1]))
305300
if m2m_list:
306301
values.update({split_key: m2m_list})
307302
else:
308303
values.update({split_key: [(5, 0, [])]})
309304

310305
elif val == "add":
311-
m2m_list = []
312-
for m2m_id in vals.get(split_key, False):
313-
m2m_list.append(m2m_id)
314-
values.update({split_key: m2m_list})
306+
values.update({split_key: vals.get(split_key, False)})
315307

316308
if values:
317309
self.env[server_action.model_id.model].browse(

0 commit comments

Comments
 (0)