diff --git a/mass_editing/README.rst b/mass_editing/README.rst index f498e34..8ad27d9 100644 --- a/mass_editing/README.rst +++ b/mass_editing/README.rst @@ -72,11 +72,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, -help us smashing it by providing a detailed and welcomed `feedback -`_. +help us smashing it by providing a detailed and welcomed feedback. Credits ======= diff --git a/mass_editing/__init__.py b/mass_editing/__init__.py index f232425..02cc628 100644 --- a/mass_editing/__init__.py +++ b/mass_editing/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) +# Copyright 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import models diff --git a/mass_editing/__openerp__.py b/mass_editing/__manifest__.py similarity index 83% rename from mass_editing/__openerp__.py rename to mass_editing/__manifest__.py index 2567679..a32598c 100644 --- a/mass_editing/__openerp__.py +++ b/mass_editing/__manifest__.py @@ -1,14 +1,16 @@ # -*- coding: utf-8 -*- -# © 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) +# Copyright 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + { 'name': 'Mass Editing', - 'version': '9.0.1.0.0', + 'version': '10.0.1.0.0', 'author': 'Serpent Consulting Services Pvt. Ltd., ' 'Odoo Community Association (OCA)', 'contributors': [ 'Oihane Crucelaegui ', 'Serpent Consulting Services Pvt. Ltd. ', + 'Jay Vora ' ], 'category': 'Tools', 'website': 'http://www.serpentcs.com', diff --git a/mass_editing/hooks.py b/mass_editing/hooks.py index 708c4e4..2460df7 100644 --- a/mass_editing/hooks.py +++ b/mass_editing/hooks.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# © 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# Copyright 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). def uninstall_hook(cr, registry): @@ -8,5 +8,5 @@ def uninstall_hook(cr, registry): 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_values WHERE value = %s", (value, )) return True diff --git a/mass_editing/models/__init__.py b/mass_editing/models/__init__.py index 28f986c..7bd9dc7 100644 --- a/mass_editing/models/__init__.py +++ b/mass_editing/models/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -# © 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) +# Copyright 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from . import ir_model_fields from . import mass_object diff --git a/mass_editing/models/ir_model_fields.py b/mass_editing/models/ir_model_fields.py deleted file mode 100644 index fd4f1f2..0000000 --- a/mass_editing/models/ir_model_fields.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from openerp import api, models - - -class IrModelFields(models.Model): - _inherit = 'ir.model.fields' - - @api.model - def search(self, args, offset=0, limit=0, order=None, count=False): - model_domain = [] - for domain in args: - if (len(domain) > 2 and domain[0] == 'model_id' and - isinstance(domain[2], basestring)): - model_domain += [('model_id', 'in', - map(int, domain[2][1:-1].split(',')))] - else: - model_domain.append(domain) - return super(IrModelFields, self).search(model_domain, offset=offset, - limit=limit, order=order, - count=count) diff --git a/mass_editing/models/mass_object.py b/mass_editing/models/mass_object.py index 880702b..0318a06 100644 --- a/mass_editing/models/mass_object.py +++ b/mass_editing/models/mass_object.py @@ -1,16 +1,15 @@ # -*- coding: utf-8 -*- -# © 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) +# Copyright 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp.exceptions import UserError -from openerp import api, fields, models, _ +from odoo import api, fields, models, _ 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=1) model_id = fields.Many2one('ir.model', 'Model', required=True, help="Model is used for Selecting Fields. " "This is editable until Sidebar menu " @@ -28,7 +27,8 @@ class MassObject(models.Model): readonly=True, help="Sidebar button to open " "the sidebar action.") - model_list = fields.Char('Model List') + model_ids = fields.Many2many('ir.model', 'mass_model_rel', + 'mass_id', 'model_id', 'Model List') _sql_constraints = [ ('name_uniq', 'unique (name)', _('Name must be unique!')), @@ -37,17 +37,17 @@ class MassObject(models.Model): @api.onchange('model_id') def _onchange_model_id(self): self.field_ids = [(6, 0, [])] - model_list = [] + model_ids = [] if self.model_id: model_obj = self.env['ir.model'] - model_list = [self.model_id.id] + model_ids = [self.model_id.id] active_model_obj = self.env[self.model_id.model] if active_model_obj._inherits: keys = active_model_obj._inherits.keys() - inherits_model_list = model_obj.search([('model', 'in', keys)]) - model_list.extend((inherits_model_list and - inherits_model_list.ids or [])) - self.model_list = model_list + inherits_model_ids = model_obj.search([('model', 'in', keys)]) + model_ids.extend((inherits_model_ids and + inherits_model_ids.ids or [])) + self.model_ids = [(6, 0, model_ids)] @api.multi def create_action(self): @@ -67,7 +67,9 @@ class MassObject(models.Model): 'target': 'new', 'auto_refresh': 1, }).id - vals['ref_ir_value_id'] = self.env['ir.values'].create({ + # We make sudo as any user with rights in this model should be able + # to create the action, not only admin + vals['ref_ir_value_id'] = self.env['ir.values'].sudo().create({ 'name': button_name, 'model': src_obj, 'key2': 'client_action_multi', @@ -79,14 +81,10 @@ class MassObject(models.Model): @api.multi def unlink_action(self): - for mass in self: - 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.")) + # We make sudo as any user with rights in this model should be able + # to delete the action, not only admin + self.mapped('ref_ir_act_window_id').sudo().unlink() + self.mapped('ref_ir_value_id').sudo().unlink() return True @api.multi @@ -94,6 +92,7 @@ class MassObject(models.Model): self.unlink_action() return super(MassObject, self).unlink() + @api.multi @api.returns('self', lambda value: value.id) def copy(self, default=None): if default is None: diff --git a/mass_editing/tests/__init__.py b/mass_editing/tests/__init__.py index 15099e1..de6c4ce 100644 --- a/mass_editing/tests/__init__.py +++ b/mass_editing/tests/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) +# Copyright 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import test_mass_editing diff --git a/mass_editing/tests/test_mass_editing.py b/mass_editing/tests/test_mass_editing.py index 518d6e2..0077b27 100644 --- a/mass_editing/tests/test_mass_editing.py +++ b/mass_editing/tests/test_mass_editing.py @@ -1,12 +1,10 @@ # -*- coding: utf-8 -*- -# © 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) +# Copyright 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -import ast - -from openerp.tests import common -from openerp.modules import registry -from openerp.addons.mass_editing.hooks import uninstall_hook +from odoo.tests import common +from odoo.modules import registry +from odoo.addons.mass_editing.hooks import uninstall_hook class TestMassEditing(common.TransactionCase): @@ -85,9 +83,8 @@ class TestMassEditing(common.TransactionCase): """Test whether onchange model_id returns model_id in list""" new_mass = self.mass_object_model.new({'model_id': self.user_model.id}) new_mass._onchange_model_id() - model_list = ast.literal_eval(new_mass.model_list) - self.assertTrue(self.user_model.id in model_list, - 'Onchange model list must contains model_id.') + self.assertTrue(self.user_model.id in new_mass.model_ids.ids, + 'Onchange model ids must contains model_id.') def test_mass_edit_email(self): """Test Case for MASS EDITING which will remove and after add diff --git a/mass_editing/views/mass_editing_view.xml b/mass_editing/views/mass_editing_view.xml index 119ca5a..fcb61c1 100644 --- a/mass_editing/views/mass_editing_view.xml +++ b/mass_editing/views/mass_editing_view.xml @@ -6,6 +6,23 @@ mass.object
+
+
- -
+ domain="[('ttype', 'not in', ['reference', 'function']), ('model_id', 'in', model_ids and model_ids[0][2] or [])]"/> diff --git a/mass_editing/wizard/__init__.py b/mass_editing/wizard/__init__.py index ecfaa57..2429cbd 100644 --- a/mass_editing/wizard/__init__.py +++ b/mass_editing/wizard/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) +# Copyright 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from . import mass_editing_wizard diff --git a/mass_editing/wizard/mass_editing_wizard.py b/mass_editing/wizard/mass_editing_wizard.py index 8456307..4062701 100644 --- a/mass_editing/wizard/mass_editing_wizard.py +++ b/mass_editing/wizard/mass_editing_wizard.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- -# © 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) +# Copyright 2016 Serpent Consulting Services Pvt. Ltd. (support@serpentcs.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from lxml import etree import openerp.tools as tools -from openerp import api, models +from odoo import api, models class MassEditingWizard(models.TransientModel):