mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[IMP] base_external_system: Add create bypass
* In cases of deep inheritance, it may be required to create an adapter directly. Add an override in the create via the env context to support this. * Add default system type if creating from an interface * Fix interface assignment during creation in adapter
This commit is contained in:
committed by
Alexandre Díaz
parent
50c6ee968a
commit
4a22c8764b
@@ -5,7 +5,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Base External System",
|
"name": "Base External System",
|
||||||
"summary": "Data models allowing for connection to external systems.",
|
"summary": "Data models allowing for connection to external systems.",
|
||||||
"version": "10.0.1.0.0",
|
"version": "10.0.1.0.1",
|
||||||
"category": "Base",
|
"category": "Base",
|
||||||
"website": "https://laslabs.com/",
|
"website": "https://laslabs.com/",
|
||||||
"author": "LasLabs, Odoo Community Association (OCA)",
|
"author": "LasLabs, Odoo Community Association (OCA)",
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ class ExternalSystem(models.Model):
|
|||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
"""Create the interface for the record and assign to ``interface``."""
|
"""Create the interface for the record and assign to ``interface``."""
|
||||||
record = super(ExternalSystem, self).create(vals)
|
record = super(ExternalSystem, self).create(vals)
|
||||||
|
if not self.env.context.get('no_create_interface'):
|
||||||
interface = self.env[vals['system_type']].create({
|
interface = self.env[vals['system_type']].create({
|
||||||
'system_id': record.id,
|
'system_id': record.id,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -69,3 +69,13 @@ class ExternalSystemAdapter(models.AbstractModel):
|
|||||||
odoo.exceptions.UserError: In the event of a good connection.
|
odoo.exceptions.UserError: In the event of a good connection.
|
||||||
"""
|
"""
|
||||||
raise UserError(_('The connection was a success.'))
|
raise UserError(_('The connection was a success.'))
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def create(self, vals):
|
||||||
|
context_self = self.with_context(no_create_interface=True)
|
||||||
|
vals.update({
|
||||||
|
'system_type': self._name,
|
||||||
|
})
|
||||||
|
record = super(ExternalSystemAdapter, context_self).create(vals)
|
||||||
|
record.system_id.interface = record
|
||||||
|
return record
|
||||||
|
|||||||
@@ -44,11 +44,33 @@ class TestExternalSystem(Common):
|
|||||||
|
|
||||||
def test_create_creates_and_assigns_interface(self):
|
def test_create_creates_and_assigns_interface(self):
|
||||||
"""It should create and assign the interface on record create."""
|
"""It should create and assign the interface on record create."""
|
||||||
|
record = self.env['external.system'].create({
|
||||||
|
'name': 'Test',
|
||||||
|
'system_type': 'external.system.os',
|
||||||
|
})
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.record.interface._name, 'external.system.os',
|
record.interface._name, 'external.system.os',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_create_context_override(self):
|
||||||
|
"""It should allow for interface create override with context."""
|
||||||
|
model = self.env['external.system'].with_context(
|
||||||
|
no_create_interface=True,
|
||||||
|
)
|
||||||
|
record = model.create({
|
||||||
|
'name': 'Test',
|
||||||
|
'system_type': 'external.system.os',
|
||||||
|
})
|
||||||
|
self.assertFalse(record.interface)
|
||||||
|
|
||||||
def test_action_test_connection(self):
|
def test_action_test_connection(self):
|
||||||
"""It should proxy to the interface connection tester."""
|
"""It should proxy to the interface connection tester."""
|
||||||
with self.assertRaises(UserError):
|
with self.assertRaises(UserError):
|
||||||
self.record.system_id.action_test_connection()
|
self.record.system_id.action_test_connection()
|
||||||
|
|
||||||
|
def test_unlink_deletes_interface(self):
|
||||||
|
"""It should delete the interface when the system is deleted."""
|
||||||
|
interface = self.record.interface
|
||||||
|
self.assertTrue(interface.exists())
|
||||||
|
self.record.unlink()
|
||||||
|
self.assertFalse(interface.exists())
|
||||||
|
|||||||
Reference in New Issue
Block a user