Browse Source

[MIG] mass_editing: Migration to v10 (#598)

pull/741/head
Serpent Consulting Services Pvt Ltd 8 years ago
committed by Pedro M. Baeza
parent
commit
2d47eb47c4
  1. 6
      mass_editing/README.rst
  2. 2
      mass_editing/__init__.py
  3. 8
      mass_editing/__manifest__.py
  4. 6
      mass_editing/hooks.py
  5. 3
      mass_editing/models/__init__.py
  6. 23
      mass_editing/models/ir_model_fields.py
  7. 39
      mass_editing/models/mass_object.py
  8. 2
      mass_editing/tests/__init__.py
  9. 15
      mass_editing/tests/test_mass_editing.py
  10. 38
      mass_editing/views/mass_editing_view.xml
  11. 2
      mass_editing/wizard/__init__.py
  12. 4
      mass_editing/wizard/mass_editing_wizard.py

6
mass_editing/README.rst

@ -72,11 +72,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-tools/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
<https://github.com/OCA/
server-tools/issues/new?body=module:%20
server-tools%0Aversion:%20
9.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======

2
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

8
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 <oihanecrucelaegi@gmail.com>',
'Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>',
'Jay Vora <jay.vora@serpentcs.com>'
],
'category': 'Tools',
'website': 'http://www.serpentcs.com',
@ -20,7 +22,7 @@
'security/ir.model.access.csv',
'views/mass_editing_view.xml',
],
'installable': False,
'installable': True,
'application': False,
'auto_install': False,
}

6
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

3
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

23
mass_editing/models/ir_model_fields.py

@ -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)

39
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:

2
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

15
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

38
mass_editing/views/mass_editing_view.xml

@ -6,6 +6,23 @@
<field name="model">mass.object</field>
<field name="arch" type="xml">
<form string="Object">
<header>
<button name="create_action"
type="object"
string="Add Sidebar Button"
class="btn-link oe_highlight"
attrs="{'invisible':[('ref_ir_act_window_id','!=',False)]}"
icon="fa-plus"
help="Display a button in the sidebar of related documents to open a composition wizard"/>
<button name="unlink_action"
type="object"
string="Remove Sidebar Button"
class="btn-link oe_highlight" icon="fa-minus"
attrs="{'invisible':[('ref_ir_act_window_id','=',False)]}"
help="Remove the contextual action to use this template on related documents"
widget="statinfo"/>
<field name="ref_ir_act_window_id" invisible="1"/>
</header>
<sheet>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
@ -17,31 +34,18 @@
<field name="model_id" required="1" attrs="{'readonly':[('ref_ir_act_window_id','!=',False)]}"/>
</group>
<group>
<field name="model_list" invisible="1"/>
<field name="model_ids" invisible="1"/>
</group>
</group>
</div>
<div class="oe_right oe_button_box" name="buttons">
<field name="ref_ir_act_window_id" invisible="1"/>
<button name="create_action"
type="object"
string="Add Sidebar Button"
class="oe_inline oe_stat_button"
attrs="{'invisible':[('ref_ir_act_window_id','!=',False)]}"
icon="fa-plus"
help="Display a button in the sidebar of related documents to open a composition wizard"/>
<button name="unlink_action"
type="object"
string="Remove Sidebar Button"
class="oe_stat_button" icon="fa-minus"
attrs="{'invisible':[('ref_ir_act_window_id','=',False)]}"
help="Remove the contextual action to use this template on related documents"
widget="statinfo"/>
</div>
<notebook colspan="4">
<page string="Fields">
<field name="field_ids" colspan="4" nolabel="1"
domain="[('ttype', 'not in', ['refenrence', 'function']), ('model_id', 'in', model_list)]"/>
domain="[('ttype', 'not in', ['reference', 'function']), ('model_id', 'in', model_ids and model_ids[0][2] or [])]"/>
</page>
<page string="Advanced" attrs="{'invisible':[('ref_ir_act_window_id','=',False)]}">
<group colspan="2" col="2">

2
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

4
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):

Loading…
Cancel
Save