Skip to content

Commit

Permalink
[MIG] mass_editing: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatiana Deribina committed Dec 20, 2021
1 parent fff4e32 commit d659680
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 151 deletions.
6 changes: 4 additions & 2 deletions mass_editing/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Mass Editing",
"version": "14.0.1.0.1",
"version": "15.0.1.0.0",
"author": "Serpent Consulting Services Pvt. Ltd., "
"Tecnativa, "
"GRAP, "
Expand All @@ -12,7 +12,9 @@
"website": "https://github.com/OCA/server-ux",
"license": "AGPL-3",
"summary": "Mass Editing",
"depends": ["base"],
"depends": [
"base",
],
"data": [
"security/ir.model.access.csv",
"views/ir_actions_server.xml",
Expand Down
34 changes: 0 additions & 34 deletions mass_editing/migrations/14.0.1.0.0/post-migrate.py

This file was deleted.

107 changes: 0 additions & 107 deletions mass_editing/migrations/14.0.1.0.0/pre-migrate.py

This file was deleted.

8 changes: 4 additions & 4 deletions mass_editing/models/mass_editing_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def _check_field_model(self):
@api.onchange("field_id")
def _onchange_field_id(self):
for rec in self:
widget_option = False
if rec.field_id.ttype == "many2many":
rec.widget_option = "many2many_tags"
widget_option = "many2many_tags"
elif rec.field_id.ttype == "binary":
if "image" in rec.field_id.name or "logo" in rec.field_id.name:
rec.widget_option = "image"
else:
rec.widget_option = False
widget_option = "image"
rec.widget_option = widget_option
1 change: 1 addition & 0 deletions mass_editing/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@

* Jairo Llopis
* Víctor Martínez
* Tatiana Deribina <[email protected]>
151 changes: 150 additions & 1 deletion mass_editing/tests/test_mass_editing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@
from odoo.exceptions import ValidationError
from odoo.tests import Form, common

from odoo.addons.base.models.ir_actions import IrActionsServer


def fake_onchange_model_id(self):
result = {
"warning": {
"title": "This is a fake onchange",
},
}
return result


@common.tagged("-at_install", "post_install")
class TestMassEditing(common.SavepointCase):
class TestMassEditing(common.TransactionCase):
def setUp(self):
super().setUp()

Expand Down Expand Up @@ -58,10 +69,71 @@ def _create_wizard_and_apply_values(self, server_action, items, vals):
wizard.button_apply()
return wizard

def test_wzd_default_get(self):
"""Test whether `operation_description_danger` is correct"""
wzd_obj = self.MassEditingWizard.with_context(
server_action_id=self.mass_editing_user.id,
active_ids=[1],
original_active_ids=[1],
)
result = wzd_obj.default_get(
fields=[],
)
self.assertEqual(
result["operation_description_info"],
"The treatment will be processed on the 1 selected record(s).",
)
self.assertFalse(
result["operation_description_warning"],
)
self.assertFalse(
result["operation_description_danger"],
)

result = wzd_obj.with_context(active_ids=[]).default_get(
fields=[],
)
self.assertFalse(
result["operation_description_info"],
)
self.assertEqual(
result["operation_description_warning"],
(
"You have selected 1 record(s) that can not be processed.\n"
"Only 0 record(s) will be processed."
),
)
self.assertFalse(
result["operation_description_danger"],
)

result = wzd_obj.with_context(original_active_ids=[]).default_get(
fields=[],
)
self.assertFalse(
result["operation_description_info"],
)
self.assertFalse(
result["operation_description_warning"],
)
self.assertEqual(
result["operation_description_danger"],
"None of the 1 record(s) you have selected can be processed.",
)

def test_wiz_fields_view_get(self):
"""Test whether fields_view_get method returns arch.
with dynamic fields.
"""
result = self.MassEditingWizard.with_context(
active_ids=[],
).fields_view_get()
arch = result.get("arch", "")
self.assertTrue(
"selection__email" not in arch,
"Fields view get must return architecture w/o fields" "created dynamicaly",
)

result = self.MassEditingWizard.with_context(
server_action_id=self.mass_editing_user.id,
active_ids=[],
Expand All @@ -72,6 +144,55 @@ def test_wiz_fields_view_get(self):
"Fields view get must return architecture with fields" "created dynamicaly",
)

def test_wzd_clean_check_company_field_domain(self):
"""
Test company field domain replacement
"""
model_name = "res.partner"
field_domain = [
("model", "=", model_name),
("name", "=", "company_id"),
]
field = self.env["ir.model.fields"].search(
field_domain,
)
field_info = {
"name": "company_id",
}
result = self.MassEditingWizard._clean_check_company_field_domain(
self.env[model_name],
field=field,
field_info=field_info,
)
self.assertDictEqual(
result,
field_info,
)

model_name = "res.partner"
field_name = "parent_id"
field_domain = [
("model", "=", model_name),
("name", "=", field_name),
]
field = self.env["ir.model.fields"].search(
field_domain,
)
field_info = {
"name": field_name,
}
model = self.env[model_name]
model._fields[field_name].check_company = True
result = self.MassEditingWizard._clean_check_company_field_domain(
model,
field=field,
field_info=field_info,
)
self.assertEqual(
result.get("domain"),
"[]",
)

def test_wiz_read_fields(self):
"""Test whether read method returns all fields or not."""
fields_view = self.MassEditingWizard.with_context(
Expand All @@ -90,6 +211,11 @@ def test_wiz_read_fields(self):
all([field in result for field in fields]), "Read must return all fields."
)

result = mass_wizard.read(fields=[])[0]
self.assertTrue(
"selection__email" not in result,
)

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
Expand Down Expand Up @@ -205,5 +331,28 @@ def test_onchanges(self):
"base.field_res_partner__image_1920"
)
self.assertEqual(mass_edit_line_form.widget_option, "image")
mass_edit_line_form.field_id = self.env.ref("base.field_res_company__logo")
self.assertEqual(mass_edit_line_form.widget_option, "image")
# binary
mass_edit_line_form.field_id = self.env.ref("base.field_res_company__favicon")
self.assertEqual(mass_edit_line_form.widget_option, False)

mass_edit_line_form.field_id = self.env.ref("base.field_res_users__country_id")
self.assertFalse(mass_edit_line_form.widget_option)

def test_onchange_model_id(self):
"""Test super call of `_onchange_model_id`"""

IrActionsServer._onchange_model_id = fake_onchange_model_id
result = self.env["ir.actions.server"]._onchange_model_id()
self.assertEqual(
result,
fake_onchange_model_id(self),
)

del IrActionsServer._onchange_model_id
result = self.env["ir.actions.server"]._onchange_model_id()
self.assertEqual(
result,
None,
)
8 changes: 5 additions & 3 deletions mass_editing/wizard/mass_editing_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ def default_get(self, fields, active_ids=None):
}
else:
operation_description_danger = _(
"None of the %d record(s) you have selected can be processed."
) % (len(active_ids))
"None of the %(amount)d record(s) you have selected can be processed."
) % {
"amount": len(active_ids),
}
# Set values
res.update(
{
Expand Down Expand Up @@ -158,7 +160,7 @@ def create(self, vals):
active_ids = self.env.context.get("active_ids", [])
if server_action and active_ids:
TargetModel = self.env[server_action.model_id.model]
IrModelFields = self.env["ir.model.fields"]
IrModelFields = self.env["ir.model.fields"].sudo()
IrTranslation = self.env["ir.translation"]

values = {}
Expand Down

0 comments on commit d659680

Please sign in to comment.