Browse Source

[FIX][mass_editing] v9 Fixing error when removing value for fields being… (#848)

pull/1232/head
Raúl Martín 7 years ago
committed by Pedro M. Baeza
parent
commit
90754ab626
  1. 1
      mass_editing/README.rst
  2. 2
      mass_editing/__openerp__.py
  3. 2
      mass_editing/hooks.py
  4. 76
      mass_editing/tests/test_mass_editing.py
  5. 17
      mass_editing/wizard/mass_editing_wizard.py

1
mass_editing/README.rst

@ -91,6 +91,7 @@ Contributors
* Oihane Crucelaegui <oihanecrucelaegi@gmail.com> * Oihane Crucelaegui <oihanecrucelaegi@gmail.com>
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com> * Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
* Raul Martin <raul.martin@braintec-group.com>
Maintainer Maintainer
---------- ----------

2
mass_editing/__openerp__.py

@ -5,10 +5,12 @@
'name': 'Mass Editing', 'name': 'Mass Editing',
'version': '9.0.1.0.0', 'version': '9.0.1.0.0',
'author': 'Serpent Consulting Services Pvt. Ltd., ' 'author': 'Serpent Consulting Services Pvt. Ltd., '
'brain-tec AG, '
'Odoo Community Association (OCA)', 'Odoo Community Association (OCA)',
'contributors': [ 'contributors': [
'Oihane Crucelaegui <oihanecrucelaegi@gmail.com>', 'Oihane Crucelaegui <oihanecrucelaegi@gmail.com>',
'Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>', 'Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>',
'Raul Martin <raul.martin@braintec-group.com>',
], ],
'category': 'Tools', 'category': 'Tools',
'website': 'http://www.serpentcs.com', 'website': 'http://www.serpentcs.com',

2
mass_editing/hooks.py

@ -8,5 +8,5 @@ def uninstall_hook(cr, registry):
WHERE res_model = 'mass.editing.wizard'""") WHERE res_model = 'mass.editing.wizard'""")
for res in cr.dictfetchall(): for res in cr.dictfetchall():
value = 'ir.actions.act_window,%s' % res.get('id') 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 return True

76
mass_editing/tests/test_mass_editing.py

@ -6,7 +6,7 @@ import ast
from openerp.tests import common from openerp.tests import common
from openerp.modules import registry from openerp.modules import registry
from openerp.addons.mass_editing.hooks import uninstall_hook
from ..hooks import uninstall_hook
class TestMassEditing(common.TransactionCase): class TestMassEditing(common.TransactionCase):
@ -17,6 +17,9 @@ class TestMassEditing(common.TransactionCase):
self.mass_wiz_obj = self.env['mass.editing.wizard'] self.mass_wiz_obj = self.env['mass.editing.wizard']
self.mass_object_model = self.env['mass.object'] self.mass_object_model = self.env['mass.object']
self.res_partner_model = self.env['res.partner'] self.res_partner_model = self.env['res.partner']
self.ir_translation_model = self.env['ir.translation']
self.lang_model = self.env['res.lang']
self.partner = self._create_partner() self.partner = self._create_partner()
self.partner_model = model_obj.\ self.partner_model = model_obj.\
search([('model', '=', 'res.partner')]) search([('model', '=', 'res.partner')])
@ -27,10 +30,22 @@ class TestMassEditing(common.TransactionCase):
'country_id', 'customer', 'child_ids', 'country_id', 'customer', 'child_ids',
'title'])]) 'title'])])
self.mass = self._create_mass_editing(self.partner_model, self.mass = self._create_mass_editing(self.partner_model,
self.fields_model)
self.fields_model,
'Partner')
self.copy_mass = self.mass.copy() self.copy_mass = self.mass.copy()
self.user = self._create_user() 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([('model', '=', 'res.partner.title')])
self.fields_partner_title_model = self.env['ir.model.fields']. \
search([('model_id', '=', self.partner_title_model.id),
('name', 'in', ['abbreviation'])])
self.mass_partner_title = self._create_mass_editing(
self.partner_title_model, self.fields_partner_title_model,
'Partner Title')
def _create_partner(self): def _create_partner(self):
"""Create a Partner.""" """Create a Partner."""
categ_ids = self.env['res.partner.category'].search([]).ids categ_ids = self.env['res.partner.category'].search([]).ids
@ -39,7 +54,23 @@ class TestMassEditing(common.TransactionCase):
'email': 'example@yourcompany.com', 'email': 'example@yourcompany.com',
'phone': 123456, 'phone': 123456,
'category_id': [(6, 0, categ_ids)], 'category_id': [(6, 0, categ_ids)],
'notify_email': 'always'
})
def _create_partner_title(self):
"""Create a Partner Title."""
# Loads German to work with translations
self.lang_model.load_lang('de_DE')
partner_title = self.res_partner_title_model.create({
'name': 'Ambassador',
'shortcut': 'Amb.',
}) })
# Adding translated terms
ctx = {'lang': 'de_DE'}
partner_title.with_context(ctx).write({'name': 'Botschafter',
'shortcut': 'Bots.'})
return partner_title
def _create_user(self): def _create_user(self):
return self.env['res.users'].create({ return self.env['res.users'].create({
@ -48,24 +79,24 @@ class TestMassEditing(common.TransactionCase):
'email': 'test@test.com', 'email': 'test@test.com',
}) })
def _create_mass_editing(self, model, fields):
def _create_mass_editing(self, 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 = self.mass_object_model.create({
'name': 'Mass Editing for Partner',
'name': u'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)]
}) })
mass.create_action() mass.create_action()
return mass return mass
def _apply_action(self, partner, vals):
def _apply_action(self, obj, vals):
"""Create Wizard object to perform mass editing to """Create Wizard object to perform mass editing to
REMOVE field's value.""" REMOVE field's value."""
ctx = { ctx = {
'active_id': partner.id,
'active_ids': partner.ids,
'active_model': 'res.partner',
'active_id': obj.id,
'active_ids': obj.ids,
'active_model': obj._name,
} }
return self.mass_wiz_obj.with_context(ctx).create(vals) return self.mass_wiz_obj.with_context(ctx).create(vals)
@ -93,6 +124,35 @@ class TestMassEditing(common.TransactionCase):
self.assertTrue(self.user_model.id in model_list, self.assertTrue(self.user_model.id in model_list,
'Onchange model list must contains model_id.') 'Onchange model list must contains model_id.')
def test_mass_edit_partner_title(self):
"""Test Case for MASS EDITING which will check if translation
was loaded for new partner title, and if they are removed
as well as the value for the abbreviation for the partner title."""
search_domain = [('res_id', '=', self.partner_title.id),
('type', '=', 'model'),
('name', '=', 'res.partner.title,shortcut'),
('lang', '=', 'de_DE')]
translation_ids = self.ir_translation_model.search(search_domain)
self.assertEqual(len(translation_ids), 1,
'Translation for Partner Title\'s Abbreviation '
'was not loaded properly.')
vals = {
'selection__shortcut': 'remove',
}
self._apply_action(self.partner_title, vals)
self.assertEqual(self.partner_title.shortcut, False,
'Partner Title\'s Abbreviation should be removed.')
translation_ids = self.ir_translation_model.search(search_domain)
self.assertEqual(len(translation_ids), 0,
'Translation for Partner Title\'s Abbreviation '
'was not removed properly.')
def test_mass_edit_email(self): def test_mass_edit_email(self):
"""Test Case for MASS EDITING which will remove and after add """Test Case for MASS EDITING which will remove and after add
Partner's email and will assert the same.""" Partner's email and will assert the same."""

17
mass_editing/wizard/mass_editing_wizard.py

@ -237,6 +237,8 @@ class MassEditingWizard(models.TransientModel):
if (self._context.get('active_model') and if (self._context.get('active_model') and
self._context.get('active_ids')): self._context.get('active_ids')):
model_obj = self.env[self._context.get('active_model')] model_obj = self.env[self._context.get('active_model')]
model_field_obj = self.env['ir.model.fields']
translation_obj = self.env['ir.translation']
values = {} values = {}
for key, val in vals.items(): for key, val in vals.items():
if key.startswith('selection_'): if key.startswith('selection_'):
@ -245,6 +247,21 @@ class MassEditingWizard(models.TransientModel):
values.update({split_key: vals.get(split_key, False)}) values.update({split_key: vals.get(split_key, False)})
elif val == 'remove': elif val == 'remove':
values.update({split_key: False}) values.update({split_key: False})
# If field to remove is translatable,
# its translations have to be removed
model_field = model_field_obj.search([
('model', '=', self._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('active_ids')),
('type', '=', 'model'),
('name', '=', u"{0},{1}".format(
self._context.get('active_model'),
split_key))])
translation_ids.unlink()
elif val == 'remove_m2m': elif val == 'remove_m2m':
values.update({split_key: [(5, 0, [])]}) values.update({split_key: [(5, 0, [])]})
elif val == 'add': elif val == 'add':

Loading…
Cancel
Save