Commit 5b140199 authored by etienne.ferriere's avatar etienne.ferriere

A class for which copy is forbidden, must be authorized for copy by default in

the unit tests.
Updated the unit tests.
Updated the 'read-me' file.
Updated the change log.

--HG--
branch : 13.0
parent e9ba6a21c8c6
Pipeline #16191 passed with stages
in 6 minutes and 1 second
......@@ -2,6 +2,12 @@
Changes
=======
13.0.1.1.0
----------
* A class for which copy is forbidden, must be authorized for copy by default in
the unit tests.
13.0.1.0.0
----------
......
......@@ -12,6 +12,9 @@ No copy mixin
Odoo mixin to disallow object copying for a model by default. May be bypassed
(see below).
A class for which copy is forbidden, is authorized for copy by default in the
unit tests.
Use
---
......@@ -49,7 +52,13 @@ Allow copying
specific cases::
obj.with_context(base_allow_copy=True).copy()
- In unit tests, copy is always allowed. To force copy to be forbidden, to check
the code added by this module, the ``activate_copy`` context key must be
used::
with self.assertRaises():
obj.with_context(activate_copy=False).copy()
History / Rationale
-------------------
......
......@@ -80,7 +80,7 @@ UI changes
None for now.
""",
"version": "13.0.1.0",
"version": "13.0.1.1",
"category": "",
"author": "XCG Consulting",
"website": "http://odoo.consulting/",
......
......@@ -18,6 +18,7 @@
#
##############################################################################
import odoo.modules.module as odoo_module_manager
from odoo import _, exceptions, models
......@@ -41,6 +42,12 @@ class BaseNoCopyMixin(models.AbstractModel):
def copy(self, default=None):
"""Override to disallow copying."""
current_test = odoo_module_manager.current_test
if current_test is not None and self.env.context.get(
"activate_copy", True
):
self = self.with_context(base_allow_copy=True)
if self._base_allow_copy or self.env.context.get("base_allow_copy"):
return super(BaseNoCopyMixin, self).copy(default=default)
......
......@@ -20,6 +20,7 @@
import uuid
import odoo.api
import odoo.exceptions
import odoo.models
import odoo.tests
......@@ -125,6 +126,14 @@ class Test(odoo.tests.TransactionCase):
_module = False
_custom = True
@odoo.api.model_create_multi
@odoo.api.returns("self", lambda value: value.id)
def create(self, vals_list):
return super(
TestModel, self.with_context(activate_copy=False)
).create(vals_list)
if inherit_from_mixin:
TestModel._inherit = "base.no_copy_mixin"
if bypass_copy_block:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment