Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] dms_field: Test compatibility #379

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions account_dms_field/tests/test_account_dms_field.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
from odoo.addons.base.tests.common import TransactionCase
from odoo.addons.base.tests.common import BaseCommon


class TestAccountDmsField(TransactionCase):
def setUp(self):
super(TestAccountDmsField, self).setUp()
self.template = self.env.ref("account_dms_field.field_template_account")
self.storage = self.template.storage_id
self.access_group = self.template.group_ids
self.account_model = self.env["account.move"]
self.partner = self.env.ref("base.res_partner_12")
self.test_directory = self.env["dms.directory"].create(
class TestAccountDmsField(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, test_dms_field=True))
cls.template = cls.env.ref("account_dms_field.field_template_account")
cls.storage = cls.template.storage_id
cls.access_group = cls.template.group_ids
cls.account_model = cls.env["account.move"]
cls.partner = cls.env.ref("base.res_partner_12")
cls.test_directory = cls.env["dms.directory"].create(
{
"name": "Test Directory",
"parent_id": self.template.dms_directory_ids[0].id,
"storage_id": self.template.storage_id.id,
"parent_id": cls.template.dms_directory_ids[0].id,
"storage_id": cls.template.storage_id.id,
}
)

Expand Down
13 changes: 11 additions & 2 deletions dms_field/models/dms_field_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, fields, models
from odoo.tools import config


class DMSFieldMixin(models.AbstractModel):
Expand Down Expand Up @@ -30,10 +31,18 @@ def models_to_track_dms_field_template(self):

@api.model_create_multi
def create(self, vals_list):
"""Create a dms directory when creating the record if exist a template."""
"""Create a dms directory when creating the record if exist a template.
We need to avoid applying a template except when testing functionality
with dms_field* modules to avoid the error that a directory with the same
name already exists (example: create partner).
"""
result = super().create(vals_list)
test_condition = not config["test_enable"] or self.env.context.get(
"test_dms_field"
)
if (
not self.env.context.get("skip_track_dms_field_template")
test_condition
and not self.env.context.get("skip_track_dms_field_template")
and self._name in self.models_to_track_dms_field_template()
):
template = self.env["dms.field.template"].with_context(res_model=self._name)
Expand Down
17 changes: 5 additions & 12 deletions dms_field/tests/test_dms_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,17 @@

from odoo import fields
from odoo.exceptions import UserError, ValidationError
from odoo.tests import TransactionCase, new_test_user
from odoo.tests import new_test_user
from odoo.tools import mute_logger

from odoo.addons.base.tests.common import BaseCommon

class TestDmsField(TransactionCase):

class TestDmsField(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
cls.env = cls.env(context=dict(cls.env.context, test_dms_field=True))
cls.user_a = new_test_user(cls.env, login="test-user-a")
cls.group = cls.env["res.groups"].create(
{"name": "Test group", "users": [(4, cls.user_a.id)]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TestDmsFieldAutoClassification(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, test_dms_field=True))
cls.template = cls.env.ref(
"dms_field_auto_classification.dms_classification_template_partners"
)
Expand Down
1 change: 1 addition & 0 deletions hr_dms_field/tests/test_hr_dms_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class TestHrDmsField(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, test_dms_field=True))
cls.template = cls.env.ref("hr_dms_field.field_template_employee")
cls.storage = cls.template.storage_id
cls.access_group = cls.template.group_ids
Expand Down
Loading