mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[IMP] : black, isort, prettier
This commit is contained in:
@@ -3,94 +3,89 @@
|
||||
|
||||
from contextlib import contextmanager
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class ExternalSystem(models.Model):
|
||||
|
||||
_name = 'external.system'
|
||||
_description = 'External System'
|
||||
_name = "external.system"
|
||||
_description = "External System"
|
||||
|
||||
name = fields.Char(
|
||||
required=True,
|
||||
help='This is the canonical (humanized) name for the system.',
|
||||
required=True, help="This is the canonical (humanized) name for the system.",
|
||||
)
|
||||
host = fields.Char(
|
||||
help='This is the domain or IP address that the system can be reached '
|
||||
'at.',
|
||||
help="This is the domain or IP address that the system can be reached " "at.",
|
||||
)
|
||||
port = fields.Integer(
|
||||
help='This is the port number that the system is listening on.',
|
||||
help="This is the port number that the system is listening on.",
|
||||
)
|
||||
username = fields.Char(
|
||||
help='This is the username that is used for authenticating to this '
|
||||
'system, if applicable.',
|
||||
help="This is the username that is used for authenticating to this "
|
||||
"system, if applicable.",
|
||||
)
|
||||
password = fields.Char(
|
||||
help='This is the password that is used for authenticating to this '
|
||||
'system, if applicable.',
|
||||
help="This is the password that is used for authenticating to this "
|
||||
"system, if applicable.",
|
||||
)
|
||||
private_key = fields.Text(
|
||||
help='This is the private key that is used for authenticating to '
|
||||
'this system, if applicable.',
|
||||
help="This is the private key that is used for authenticating to "
|
||||
"this system, if applicable.",
|
||||
)
|
||||
private_key_password = fields.Text(
|
||||
help='This is the password to unlock the private key that was '
|
||||
'provided for this sytem.',
|
||||
help="This is the password to unlock the private key that was "
|
||||
"provided for this sytem.",
|
||||
)
|
||||
fingerprint = fields.Text(
|
||||
help='This is the fingerprint that is advertised by this system in '
|
||||
'order to validate its identity.',
|
||||
help="This is the fingerprint that is advertised by this system in "
|
||||
"order to validate its identity.",
|
||||
)
|
||||
ignore_fingerprint = fields.Boolean(
|
||||
default=True,
|
||||
help='Set this to `True` in order to ignore an invalid/unknown '
|
||||
'fingerprint from the system.',
|
||||
help="Set this to `True` in order to ignore an invalid/unknown "
|
||||
"fingerprint from the system.",
|
||||
)
|
||||
remote_path = fields.Char(
|
||||
help='Restrict to this directory path on the remote, if applicable.',
|
||||
help="Restrict to this directory path on the remote, if applicable.",
|
||||
)
|
||||
company_ids = fields.Many2many(
|
||||
string='Companies',
|
||||
comodel_name='res.company',
|
||||
string="Companies",
|
||||
comodel_name="res.company",
|
||||
required=True,
|
||||
default=lambda s: [(6, 0, s.env.user.company_id.ids)],
|
||||
help='Access to this system is restricted to these companies.',
|
||||
)
|
||||
system_type = fields.Selection(
|
||||
selection='_get_system_types',
|
||||
required=True,
|
||||
help="Access to this system is restricted to these companies.",
|
||||
)
|
||||
system_type = fields.Selection(selection="_get_system_types", required=True,)
|
||||
interface = fields.Reference(
|
||||
selection='_get_system_types',
|
||||
selection="_get_system_types",
|
||||
readonly=True,
|
||||
help='This is the interface that this system represents. It is '
|
||||
'created automatically upon creation of the external system.',
|
||||
help="This is the interface that this system represents. It is "
|
||||
"created automatically upon creation of the external system.",
|
||||
)
|
||||
|
||||
_sql_constraints = [
|
||||
('name_uniq', 'UNIQUE(name)', 'Connection name must be unique.'),
|
||||
("name_uniq", "UNIQUE(name)", "Connection name must be unique."),
|
||||
]
|
||||
|
||||
@api.model
|
||||
def _get_system_types(self):
|
||||
"""Return the adapter interface models that are installed."""
|
||||
adapter = self.env['external.system.adapter']
|
||||
return [
|
||||
(m, self.env[m]._description) for m in adapter._inherit_children
|
||||
]
|
||||
adapter = self.env["external.system.adapter"]
|
||||
return [(m, self.env[m]._description) for m in adapter._inherit_children]
|
||||
|
||||
@api.multi
|
||||
@api.constrains('fingerprint', 'ignore_fingerprint')
|
||||
@api.constrains("fingerprint", "ignore_fingerprint")
|
||||
def check_fingerprint_ignore_fingerprint(self):
|
||||
"""Do not allow a blank fingerprint if not set to ignore."""
|
||||
for record in self:
|
||||
if not record.ignore_fingerprint and not record.fingerprint:
|
||||
raise ValidationError(_(
|
||||
'Fingerprint cannot be empty when Ignore Fingerprint is '
|
||||
'not checked.',
|
||||
))
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Fingerprint cannot be empty when Ignore Fingerprint is "
|
||||
"not checked.",
|
||||
)
|
||||
)
|
||||
|
||||
@api.multi
|
||||
@contextmanager
|
||||
@@ -111,10 +106,8 @@ class ExternalSystem(models.Model):
|
||||
def create(self, vals):
|
||||
"""Create the interface for the record and assign to ``interface``."""
|
||||
record = super(ExternalSystem, self).create(vals)
|
||||
if not self.env.context.get('no_create_interface'):
|
||||
interface = self.env[vals['system_type']].create({
|
||||
'system_id': record.id,
|
||||
})
|
||||
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
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
from contextlib import contextmanager
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
@@ -13,15 +13,15 @@ class ExternalSystemAdapter(models.AbstractModel):
|
||||
Methods provided are prefixed with ``external_`` in order to keep from
|
||||
"""
|
||||
|
||||
_name = 'external.system.adapter'
|
||||
_description = 'External System Adapter'
|
||||
_inherits = {'external.system': 'system_id'}
|
||||
_name = "external.system.adapter"
|
||||
_description = "External System Adapter"
|
||||
_inherits = {"external.system": "system_id"}
|
||||
|
||||
system_id = fields.Many2one(
|
||||
string='System',
|
||||
comodel_name='external.system',
|
||||
string="System",
|
||||
comodel_name="external.system",
|
||||
required=True,
|
||||
ondelete='cascade',
|
||||
ondelete="cascade",
|
||||
)
|
||||
|
||||
@api.multi
|
||||
@@ -67,14 +67,14 @@ class ExternalSystemAdapter(models.AbstractModel):
|
||||
Raises:
|
||||
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,
|
||||
})
|
||||
vals.update(
|
||||
{"system_type": self._name,}
|
||||
)
|
||||
record = super(ExternalSystemAdapter, context_self).create(vals)
|
||||
record.system_id.interface = record
|
||||
return record
|
||||
|
||||
@@ -13,9 +13,9 @@ class ExternalSystemOs(models.Model):
|
||||
system interface. This is still a fully usable implementation, however.
|
||||
"""
|
||||
|
||||
_name = 'external.system.os'
|
||||
_inherit = 'external.system.adapter'
|
||||
_description = 'External System OS'
|
||||
_name = "external.system.os"
|
||||
_inherit = "external.system.adapter"
|
||||
_description = "External System OS"
|
||||
|
||||
previous_dir = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user