Browse Source

fixup! [MIG] mass_editing: Migration to 12.0 Test coverage

pull/41/head
Hugo Adan 6 years ago
parent
commit
cb2a3d2af4
  1. 5
      mass_editing/__manifest__.py
  2. 3
      mass_editing/models/ir_model_fields.py
  3. 4
      mass_editing/readme/USAGE.rst
  4. 78
      mass_editing/tests/test_mass_editing.py
  5. 4
      mass_editing/views/mass_editing_view.xml
  6. 24
      mass_editing/wizard/mass_editing_wizard.py

5
mass_editing/__manifest__.py

@ -7,7 +7,7 @@
'Tecnativa, '
'Odoo Community Association (OCA)',
'category': 'Tools',
'website': 'http://www.serpentcs.com',
'website': 'https://github.com/OCA/server-ux',
'license': 'AGPL-3',
'summary': 'Mass Editing',
'uninstall_hook': 'uninstall_hook',
@ -16,7 +16,4 @@
'security/ir.model.access.csv',
'views/mass_editing_view.xml',
],
'installable': True,
'application': False,
'auto_install': False,
}

3
mass_editing/models/ir_model_fields.py

@ -15,7 +15,8 @@ class IrModelFields(models.Model):
isinstance(domain[2], str) and
list(domain[2][1:-1])):
model_domain += [('model_id', 'in',
list(map(int, domain[2][1:-1].split(','))))]
[int(x) for x in domain[2][1:-1].split(',')]
)]
else:
model_domain.append(domain)
return super(IrModelFields, self).search(model_domain, offset=offset,

4
mass_editing/readme/USAGE.rst

@ -1,9 +1,5 @@
This module allows to add, update or remove the values of more than one records on the fly at the same time.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/250/11.0
As shown in figure you have to configure the object and fields for mass editing.
* Select the object and add the fields of that object on which you want to apply mass editing.

78
mass_editing/tests/test_mass_editing.py

@ -9,50 +9,51 @@ from odoo.modules import registry
from ..hooks import uninstall_hook
class TestMassEditing(common.TransactionCase):
class TestMassEditing(common.SavepointCase):
at_install = False
post_install = True
def setUp(self):
super(TestMassEditing, self).setUp()
@classmethod
def setUpClass(cls):
super(TestMassEditing, cls).setUpClass()
# Model connections
model_obj = self.env['ir.model']
self.mass_wiz_obj = self.env['mass.editing.wizard']
self.mass_object_model = self.env['mass.object']
self.res_partner_model = self.env['res.partner']
self.ir_translation_model = self.env['ir.translation']
self.lang_model = self.env['res.lang']
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
model_obj = cls.env['ir.model']
cls.mass_wiz_obj = cls.env['mass.editing.wizard']
cls.mass_object_model = cls.env['mass.object']
cls.res_partner_model = cls.env['res.partner']
cls.ir_translation_model = cls.env['ir.translation']
cls.lang_model = cls.env['res.lang']
# Shared data for test methods
self.partner = self._create_partner()
self.partner_model = model_obj.\
cls.partner = cls._create_partner()
cls.partner_model = model_obj.\
search([('model', '=', 'res.partner')])
self.user_model = model_obj.search([('model', '=', 'res.users')])
self.fields_model = self.env['ir.model.fields'].\
search([('model_id', '=', self.partner_model.id),
cls.user_model = model_obj.search([('model', '=', 'res.users')])
cls.fields_model = cls.env['ir.model.fields'].\
search([('model_id', '=', cls.partner_model.id),
('name', 'in', ['email', 'phone', 'category_id', 'comment',
'country_id', 'customer', 'child_ids',
'title', 'company_type'])])
self.mass = self._create_mass_editing(self.partner_model,
self.fields_model,
'Partner')
self.copy_mass = self.mass.copy()
self.user = self._create_user()
self.res_partner_title_model = self.env['res.partner.title']
self.partner_title = self._create_partner_title()
self.partner_title_model = model_obj.search(
cls.mass = cls._create_mass_editing(
cls.partner_model, cls.fields_model, 'Partner')
cls.copy_mass = cls.mass.copy()
cls.user = cls._create_user()
cls.res_partner_title_model = cls.env['res.partner.title']
cls.partner_title = cls._create_partner_title()
cls.partner_title_model = model_obj.search(
[('model', '=', 'res.partner.title')])
self.fields_partner_title_model = self.env['ir.model.fields'].search(
[('model_id', '=', self.partner_title_model.id),
cls.fields_partner_title_model = cls.env['ir.model.fields'].search(
[('model_id', '=', cls.partner_title_model.id),
('name', 'in', ['abbreviation'])])
self.mass_partner_title = self._create_mass_editing(
self.partner_title_model,
self.fields_partner_title_model,
cls.mass_partner_title = cls._create_mass_editing(
cls.partner_title_model, cls.fields_partner_title_model,
'Partner Title')
def _create_partner(self):
@classmethod
def _create_partner(cls):
"""Create a Partner."""
categ_ids = self.env['res.partner.category'].search([]).ids
return self.res_partner_model.create({
categ_ids = cls.env['res.partner.category'].search([]).ids
return cls.res_partner_model.create({
'name': 'Test Partner',
'email': 'example@yourcompany.com',
'phone': 123456,
@ -60,12 +61,13 @@ class TestMassEditing(common.TransactionCase):
'notify_email': 'always'
})
def _create_partner_title(self):
@classmethod
def _create_partner_title(cls):
"""Create a Partner Title."""
# Loads German to work with translations
self.lang_model.load_lang('de_DE')
cls.lang_model.load_lang('de_DE')
# Creating the title in English
partner_title = self.res_partner_title_model.create({
partner_title = cls.res_partner_title_model.create({
'name': 'Ambassador',
'shortcut': 'Amb.',
})
@ -76,17 +78,19 @@ class TestMassEditing(common.TransactionCase):
'shortcut': 'Bots.'})
return partner_title
def _create_user(self):
return self.env['res.users'].create({
@classmethod
def _create_user(cls):
return cls.env['res.users'].create({
'name': 'Test User',
'login': 'test_login',
'email': 'test@test.com',
})
def _create_mass_editing(self, model, fields, model_name):
@classmethod
def _create_mass_editing(cls, model, fields, model_name):
"""Create a Mass Editing with Partner as model and
email field of partner."""
mass = self.mass_object_model.create({
mass = cls.mass_object_model.create({
'name': 'Mass Editing for {0}'.format(model_name),
'model_id': model.id,
'field_ids': [(6, 0, fields.ids)]

4
mass_editing/views/mass_editing_view.xml

@ -31,10 +31,10 @@
</h1>
</div>
<group>
<group>
<group name="model_id">
<field name="model_id" required="1" attrs="{'readonly':[('ref_ir_act_window_id','!=',False)]}"/>
</group>
<group>
<group name="model_list">
<field name="model_list" invisible="1"/>
</group>
</group>

24
mass_editing/wizard/mass_editing_wizard.py

@ -14,12 +14,10 @@ class MassEditingWizard(models.TransientModel):
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
submenu=False):
result =\
super(MassEditingWizard, self).fields_view_get(view_id=view_id,
view_type=view_type,
toolbar=toolbar,
result = super(MassEditingWizard, self).fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu)
context = self._context
context = self.env.context
if context.get('mass_editing_object'):
mass_obj = self.env['mass.object']
editing_data = mass_obj.browse(context.get('mass_editing_object'))
@ -234,9 +232,9 @@ class MassEditingWizard(models.TransientModel):
@api.model
def create(self, vals):
if (self._context.get('active_model') and
self._context.get('active_ids')):
model_obj = self.env[self._context.get('active_model')]
if (self.env.context.get('active_model') and
self.env.context.get('active_ids')):
model_obj = self.env[self.env.context.get('active_model')]
model_field_obj = self.env['ir.model.fields']
translation_obj = self.env['ir.translation']
@ -252,15 +250,16 @@ class MassEditingWizard(models.TransientModel):
# If field to remove is translatable,
# its translations have to be removed
model_field = model_field_obj.search([
('model', '=', self._context.get('active_model')),
('model', '=',
self.env.context.get('active_model')),
('name', '=', split_key)])
if model_field and model_field.translate:
translation_ids = translation_obj.search([
('res_id', 'in', self._context.get(
('res_id', 'in', self.env.context.get(
'active_ids')),
('type', '=', 'model'),
('name', '=', u"{0},{1}".format(
self._context.get('active_model'),
self.env.context.get('active_model'),
split_key))])
translation_ids.unlink()
@ -279,7 +278,8 @@ class MassEditingWizard(models.TransientModel):
m2m_list.append((4, m2m_id))
values.update({split_key: m2m_list})
if values:
model_obj.browse(self._context.get('active_ids')).write(values)
model_obj.browse(
self.env.context.get('active_ids')).write(values)
return super(MassEditingWizard, self).create({})
@api.multi

Loading…
Cancel
Save