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. 26
      mass_editing/wizard/mass_editing_wizard.py

5
mass_editing/__manifest__.py

@ -7,7 +7,7 @@
'Tecnativa, ' 'Tecnativa, '
'Odoo Community Association (OCA)', 'Odoo Community Association (OCA)',
'category': 'Tools', 'category': 'Tools',
'website': 'http://www.serpentcs.com',
'website': 'https://github.com/OCA/server-ux',
'license': 'AGPL-3', 'license': 'AGPL-3',
'summary': 'Mass Editing', 'summary': 'Mass Editing',
'uninstall_hook': 'uninstall_hook', 'uninstall_hook': 'uninstall_hook',
@ -16,7 +16,4 @@
'security/ir.model.access.csv', 'security/ir.model.access.csv',
'views/mass_editing_view.xml', '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 isinstance(domain[2], str) and
list(domain[2][1:-1])): list(domain[2][1:-1])):
model_domain += [('model_id', 'in', model_domain += [('model_id', 'in',
list(map(int, domain[2][1:-1].split(','))))]
[int(x) for x in domain[2][1:-1].split(',')]
)]
else: else:
model_domain.append(domain) model_domain.append(domain)
return super(IrModelFields, self).search(model_domain, offset=offset, 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. 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. 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. * 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 from ..hooks import uninstall_hook
class TestMassEditing(common.TransactionCase):
class TestMassEditing(common.SavepointCase):
at_install = False at_install = False
post_install = True post_install = True
def setUp(self):
super(TestMassEditing, self).setUp()
@classmethod
def setUpClass(cls):
super(TestMassEditing, cls).setUpClass()
# Model connections # 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 # 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')]) 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', ('name', 'in', ['email', 'phone', 'category_id', 'comment',
'country_id', 'customer', 'child_ids', 'country_id', 'customer', 'child_ids',
'title', 'company_type'])]) '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')]) [('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'])]) ('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') 'Partner Title')
def _create_partner(self):
@classmethod
def _create_partner(cls):
"""Create a Partner.""" """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', 'name': 'Test Partner',
'email': 'example@yourcompany.com', 'email': 'example@yourcompany.com',
'phone': 123456, 'phone': 123456,
@ -60,12 +61,13 @@ class TestMassEditing(common.TransactionCase):
'notify_email': 'always' 'notify_email': 'always'
}) })
def _create_partner_title(self):
@classmethod
def _create_partner_title(cls):
"""Create a Partner Title.""" """Create a Partner Title."""
# Loads German to work with translations # 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 # Creating the title in English
partner_title = self.res_partner_title_model.create({
partner_title = cls.res_partner_title_model.create({
'name': 'Ambassador', 'name': 'Ambassador',
'shortcut': 'Amb.', 'shortcut': 'Amb.',
}) })
@ -76,17 +78,19 @@ class TestMassEditing(common.TransactionCase):
'shortcut': 'Bots.'}) 'shortcut': 'Bots.'})
return partner_title 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', 'name': 'Test User',
'login': 'test_login', 'login': 'test_login',
'email': 'test@test.com', '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 """Create a Mass Editing with Partner as model and
email field of partner.""" email field of partner."""
mass = self.mass_object_model.create({
mass = cls.mass_object_model.create({
'name': 'Mass Editing for {0}'.format(model_name), 'name': 'Mass Editing for {0}'.format(model_name),
'model_id': model.id, 'model_id': model.id,
'field_ids': [(6, 0, fields.ids)] 'field_ids': [(6, 0, fields.ids)]

4
mass_editing/views/mass_editing_view.xml

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

26
mass_editing/wizard/mass_editing_wizard.py

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

Loading…
Cancel
Save