浏览代码

[FIX]mass_editing:Fixed web issue of list property and remove all data from m2m issue.

Vacha Trivedi 6 年之前
父节点
当前提交
55caaadd08

+ 1 - 0
mass_editing/__openerp__.py

@@ -19,6 +19,7 @@
     'data': [
         'security/ir.model.access.csv',
         'views/mass_editing_view.xml',
+        'views/template.xml',
     ],
     'installable': True,
     'application': False,

+ 56 - 0
mass_editing/static/src/js/mass_edit.js

@@ -0,0 +1,56 @@
+odoo.define('mass_editing.mass_editing', function (require) {
+"use strict";
+
+var FormView = require('web.FormView');
+FormView.include({
+    _build_onchange_specs: function() {
+        var self = this;
+        var find = function(field_name, root) {
+            var fields = [root];
+            while (fields.length) {
+                var node = fields.pop();
+                if (!node) {
+                    continue;
+                }
+                if (node.tag === 'field' && node.attrs.name === field_name) {
+                    return node.attrs.on_change || "";
+                }
+                fields = _.union(fields, node.children);
+            }
+            return "";
+        };
+
+        self._onchange_fields = [];
+        self._onchange_specs = {};
+        _.each(this.fields, function(field, name) {
+            self._onchange_fields.push(name);
+            self._onchange_specs[name] = find(name, field.node);
+
+            // we get the list of first-level fields of x2many firstly by
+            // getting them from the field embedded views, then if no embedded
+            // view is present for a loaded view, we get them from the default
+            // view that has been loaded
+
+            // gather embedded view objects
+            var views = _.clone(field.field.views);
+            // also gather default view objects
+            if (field.viewmanager) {
+                _.each(field.viewmanager.views, function(view, view_type) {
+                    // add default view if it was not embedded and it is loaded
+                    var not_embedded = view.embedded_view === undefined; // ONLY FOR 9.0
+//                    Checked views only then check for view_type
+                    if (views && views[view_type] === undefined && view.controller && not_embedded) {
+                        views[view_type] = view.controller.fields_view;
+                    }
+                });
+            }
+            _.each(views, function(view) {
+                _.each(view.fields, function(_, subname) {
+                    self._onchange_specs[name + '.' + subname] = find(subname, view.arch);
+                });
+            });
+        });
+    },
+})
+
+});

+ 9 - 0
mass_editing/views/template.xml

@@ -0,0 +1,9 @@
+<openerp>
+    <data>
+        <template id="mass_edit_backend" name="mass_edit assets" inherit_id="web.assets_backend">
+            <xpath expr="." position="inside">
+               <script type="text/javascript" src="/mass_editing/static/src/js/mass_edit.js"></script>
+            </xpath>
+        </template>
+    </data>
+</openerp>

+ 6 - 3
mass_editing/wizard/mass_editing_wizard.py

@@ -268,13 +268,16 @@ class MassEditingWizard(models.TransientModel):
                         values.update({split_key: vals.get(split_key, False)})
                     elif val == 'remove':
                         values.update({split_key: False})
-                    elif val == 'remove_m2m':
+                    elif val in ['remove_m2m', 'remove_m2m_all']:
+                        m2m_list = []
                         if vals.get(split_key):
-                            m2m_list = []
                             for m2m_id in vals.get(split_key)[0][2]:
                                 m2m_list.append((3, m2m_id))
+                        if m2m_list:
                             values.update({split_key: m2m_list})
-                    elif val in ['remove_o2m', 'remove_m2m_all']:
+                        else:
+                            values.update({split_key: [(5, 0, [])]})
+                    elif val == 'remove_o2m':
                         # model_fieds will return the particular model
                         # in order to get the field of the model
                         # and its relation.