Browse Source

[IMP]mass_editing:Improved the module code for v11.

Vacha Trivedi 7 years ago
parent
commit
f256f725a1

+ 2 - 1
mass_editing/__manifest__.py

@@ -3,7 +3,7 @@
 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
 {
     'name': 'Mass Editing',
-    'version': '10.0.1.0.0',
+    'version': '11.0.1.0.0',
     'author': 'Serpent Consulting Services Pvt. Ltd., '
               'Odoo Community Association (OCA)',
     'contributors': [
@@ -22,6 +22,7 @@
     'data': [
         'security/ir.model.access.csv',
         'views/mass_editing_view.xml',
+        'views/template.xml'
     ],
     'installable': True,
     'application': False,

+ 1 - 5
mass_editing/hooks.py

@@ -4,9 +4,5 @@
 
 
 def uninstall_hook(cr, registry):
-    cr.execute("""SELECT id FROM ir_act_window
-               WHERE res_model = 'mass.editing.wizard'""")
-    for res in cr.dictfetchall():
-        value = 'ir.actions.act_window,%s' % res.get('id')
-        cr.execute("DELETE FROM ir_values WHERE value = '%s'" % value)
+    cr.execute("DELETE FROM ir_act_window WHERE res_model = 'mass.editing.wizard'")
     return True

+ 2 - 2
mass_editing/models/ir_model_fields.py

@@ -13,10 +13,10 @@ class IrModelFields(models.Model):
         model_domain = []
         for domain in args:
             if (len(domain) > 2 and domain[0] == 'model_id' and
-                    isinstance(domain[2], basestring) and
+                    isinstance(domain[2], str) and
                     list(domain[2][1:-1])):
                 model_domain += [('model_id', 'in',
-                                  map(int, domain[2][1:-1].split(',')))]
+                                  [int(domain[2][1:-1].split(',')[0])])]
             else:
                 model_domain.append(domain)
         return super(IrModelFields, self).search(model_domain, offset=offset,

+ 4 - 17
mass_editing/models/mass_object.py

@@ -10,7 +10,7 @@ class MassObject(models.Model):
     _name = "mass.object"
     _description = "Mass Editing Object"
 
-    name = fields.Char('Name', required=True, select=1)
+    name = fields.Char('Name', required=True, index=True)
     model_id = fields.Many2one('ir.model', 'Model', required=True,
                                help="Model is used for Selecting Fields. "
                                     "This is editable until Sidebar menu "
@@ -18,16 +18,12 @@ class MassObject(models.Model):
     field_ids = fields.Many2many('ir.model.fields', 'mass_field_rel',
                                  'mass_id', 'field_id', 'Fields')
     ref_ir_act_window_id = fields.Many2one('ir.actions.act_window',
-                                           'Sidebar action',
+                                           'Sidebar Action',
                                            readonly=True,
                                            help="Sidebar action to make this "
                                                 "template available on "
                                                 "records of the related "
                                                 "document model.")
-    ref_ir_value_id = fields.Many2one('ir.values', 'Sidebar button',
-                                      readonly=True,
-                                      help="Sidebar button to open "
-                                           "the sidebar action.")
     model_list = fields.Char('Model List')
 
     _sql_constraints = [
@@ -63,16 +59,9 @@ class MassObject(models.Model):
             'src_model': src_obj,
             'view_type': 'form',
             'context': "{'mass_editing_object' : %d}" % (self.id),
-            'view_mode': 'form, tree',
+            'view_mode': 'form',
             'target': 'new',
-            'auto_refresh': 1,
-        }).id
-        vals['ref_ir_value_id'] = self.env['ir.values'].create({
-            'name': button_name,
-            'model': src_obj,
-            'key2': 'client_action_multi',
-            'value': "ir.actions.act_window," +
-                     str(vals['ref_ir_act_window_id']),
+            'binding_model_id': self.model_id.id,
         }).id
         self.write(vals)
         return True
@@ -83,8 +72,6 @@ class MassObject(models.Model):
             try:
                 if mass.ref_ir_act_window_id:
                     mass.ref_ir_act_window_id.unlink()
-                if mass.ref_ir_value_id:
-                    mass.ref_ir_value_id.unlink()
             except:
                 raise UserError(_("Deletion of the action record failed."))
         return True

+ 1 - 1
mass_editing/static/description/index.html

@@ -21,7 +21,7 @@
               <p>The user can remove the action by clicking on the "Remove Sidebar Button".</p>
         </div>
         <div class="col-md-8 mt16">
-            <img class="img img-responsive" src="remove_button.png">
+            <img class="img img-responsive" src="remove_button2.png">
         </div>
     </div>
     

BIN
mass_editing/static/description/mass_editing-2.png


BIN
mass_editing/static/description/remove_button.png


BIN
mass_editing/static/description/remove_button2.png


+ 49 - 0
mass_editing/static/src/js/mass_editing.js

@@ -0,0 +1,49 @@
+odoo.define('mass_editing.mass_editing', function (require) {
+"use strict";
+
+    var BasicModel = require("web.BasicModel");
+
+    BasicModel.include({
+        /**
+         * parse the server values to javascript framwork
+         *
+         * @param {[string]} fieldNames
+         * @param {Object} element the dataPoint used as parent for the created
+         *   dataPoints
+         * @param {Object} data the server data to parse
+         */
+        _parseServerData: function (fieldNames, element, data) {
+            var self = this;
+            _.each(fieldNames, function (fieldName) {
+                var field = element.fields[fieldName];
+                var val = data[fieldName];
+                if (field.type === 'many2one') {
+                    // process many2one: split [id, nameget] and create corresponding record
+                    // For val = Null
+                    if (val && val !== false) {
+                        // the many2one value is of the form [id, display_name]
+                        var r = self._makeDataPoint({
+                            modelName: field.relation,
+                            fields: {
+                                display_name: {type: 'char'},
+                                id: {type: 'integer'},
+                            },
+                            data: {
+                                display_name: val[1],
+                                id: val[0],
+                            },
+                            parentID: element.id,
+                        });
+                        data[fieldName] = r.id;
+                    } else {
+                        // no value for the many2one
+                        data[fieldName] = false;
+                    }
+                } else {
+                    data[fieldName] = self._parseServerValue(field, val);
+                }
+            });
+        },
+    });
+
+});

+ 2 - 2
mass_editing/tests/test_mass_editing.py

@@ -142,11 +142,11 @@ class TestMassEditing(common.TransactionCase):
 
     def test_sidebar_action(self):
         """Test if Sidebar Action is added / removed to / from give object."""
-        action = self.mass.ref_ir_act_window_id and self.mass.ref_ir_value_id
+        action = self.mass.ref_ir_act_window_id
         self.assertTrue(action, 'Sidebar action must be exists.')
         # Remove the sidebar actions
         self.mass.unlink_action()
-        action = self.mass.ref_ir_act_window_id and self.mass.ref_ir_value_id
+        action = self.mass.ref_ir_act_window_id
         self.assertFalse(action, 'Sidebar action must be removed.')
 
     def test_unlink_mass(self):

+ 0 - 1
mass_editing/views/mass_editing_view.xml

@@ -47,7 +47,6 @@
                         <page string="Advanced" attrs="{'invisible':[('ref_ir_act_window_id','=',False)]}">
                             <group colspan="2" col="2">
                                 <field name="ref_ir_act_window_id"/>
-                                <field name="ref_ir_value_id"/>
                             </group>
                         </page>
                     </notebook>

+ 9 - 0
mass_editing/views/template.xml

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

+ 1 - 1
mass_editing/wizard/mass_editing_wizard.py

@@ -490,7 +490,7 @@ class MassEditingWizard(models.TransientModel):
                             data.write({split_key: tot_val})
             if values:
                 model_rec.write(values)
-        return super(MassEditingWizard, self).create({})
+        return super(MassEditingWizard, self).create(vals)
 
     @api.multi
     def action_apply(self):