[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:
Dave Lasley
2017-10-20 14:17:13 -07:00
committed by Pedro M. Baeza
parent 21df00169e
commit c11c3cd251
4 changed files with 39 additions and 6 deletions

View File

@@ -112,10 +112,11 @@ class ExternalSystem(models.Model):
def create(self, vals):
"""Create the interface for the record and assign to ``interface``."""
record = super(ExternalSystem, self).create(vals)
interface = self.env[vals['system_type']].create({
'system_id': record.id,
})
record.interface = interface
if not self.env.context.get('no_create_interface'):
interface = self.env[vals['system_type']].create({
'system_id': record.id,
})
record.interface = interface
return record
@api.multi

View File

@@ -69,3 +69,13 @@ class ExternalSystemAdapter(models.AbstractModel):
odoo.exceptions.UserError: In the event of a good connection.
"""
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