예제 #1
0
    def remove(cls, name, rc_file='~/.odoorpcrc'):
        """Remove the session identified by `name` from the `rc_file` file:

        .. doctest::
            :options: +SKIP

            >>> import odoorpc
            >>> odoorpc.ODOO.remove('foo')
            True

        *Python 2:*

        :raise: `ValueError` (if the session does not exist)
        :raise: `IOError`

        *Python 3:*

        :raise: `ValueError` (if the session does not exist)
        :raise: `PermissionError`
        :raise: `FileNotFoundError`
        """
        data = session.get(name, rc_file)
        if data.get('type') != cls.__name__:
            raise error.InternalError(
                "'{0}' session is not of type '{1}'".format(
                    name, cls.__name__))
        return session.remove(name, rc_file)
예제 #2
0
 def __init__(
     self,
     host='localhost',
     protocol='jsonrpc',
     port=8069,
     timeout=120,
     version=None,
     opener=None,
 ):
     if protocol not in ['jsonrpc', 'jsonrpc+ssl']:
         txt = (
             "The protocol '{0}' is not supported by the ODOO class. "
             "Please choose a protocol among these ones: {1}"
         )
         txt = txt.format(protocol, ['jsonrpc', 'jsonrpc+ssl'])
         raise ValueError(txt)
     try:
         port = int(port)
     except (ValueError, TypeError):
         raise ValueError("The port must be an integer")
     try:
         if timeout is not None:
             timeout = float(timeout)
     except (ValueError, TypeError):
         raise ValueError("The timeout must be a float")
     self._host = host
     self._port = port
     self._protocol = protocol
     self._env = None
     self._login = None
     self._password = None
     self._db = DB(self)
     self._report = Report(self)
     # Instanciate the server connector
     try:
         self._connector = rpc.PROTOCOLS[protocol](
             self._host, self._port, timeout, version, opener=opener
         )
     except rpc.error.ConnectorError as exc:
         raise error.InternalError(exc.message)
     # Dictionary of configuration options
     self._config = tools.Config(
         self,
         {'auto_commit': True, 'auto_context': True, 'timeout': timeout},
     )
예제 #3
0
    def restore(self, password, db, dump, copy=False):
        """Restore the `dump` database into the new `db` database.
        The `dump` file object can be obtained with the
        :func:`dump <DB.dump>` method.
        If `copy` is set to `True`, the restored database will have a new UUID.

        >>> odoo.db.restore('super_admin_passwd', 'test', dump_file) # doctest: +SKIP

        If you get a timeout error, increase this one before performing the
        request:

        >>> timeout_backup = odoo.config['timeout']
        >>> odoo.config['timeout'] = 7200   # Timeout set to 2 hours
        >>> odoo.db.restore('super_admin_passwd', 'test', dump_file) # doctest: +SKIP
        >>> odoo.config['timeout'] = timeout_backup

        The super administrator password is required to perform this method.

        *Python 2:*

        :raise: :class:`odoorpc.error.RPCError`
                (access denied / database already exists)
        :raise: :class:`odoorpc.error.InternalError` (dump file closed)
        :raise: `urllib2.URLError` (connection error)

        *Python 3:*

        :raise: :class:`odoorpc.error.RPCError`
                (access denied / database already exists)
        :raise: :class:`odoorpc.error.InternalError` (dump file closed)
        :raise: `urllib.error.URLError` (connection error)
        """
        if dump.closed:
            raise error.InternalError("Dump file closed")
        b64_data = base64.standard_b64encode(dump.read()).decode()
        self._odoo.json(
            '/jsonrpc',
            {
                'service': 'db',
                'method': 'restore',
                'args': [password, db, b64_data, copy],
            },
        )
예제 #4
0
파일: models.py 프로젝트: denis-souza/odoo
 def __isub__(self, records):
     if not self._from_record:
         raise error.InternalError("No parent record to update")
     try:
         list(records)
     except TypeError:
         records = [records]
     parent = self._from_record[0]
     field = self._from_record[1]
     updated_values = parent._values_to_write[field.name]
     values = []
     if updated_values.get(parent.id):
         values = updated_values[parent.id][:]  # Copy
     from odoorpc import fields
     for id_ in fields.records2ids(records):
         if (4, id_) in values:
             values.remove((4, id_))
         if (3, id_) not in values:
             values.append((3, id_))
     return values
예제 #5
0
    def load(cls, name, rc_file='~/.odoorpcrc'):
        """Return a connected :class:`ODOO` session identified by `name`:

        .. doctest::
            :options: +SKIP

            >>> import odoorpc
            >>> odoo = odoorpc.ODOO.load('foo')

        Such sessions are stored with the
        :func:`save <odoorpc.ODOO.save>` method.

        *Python 2:*

        :raise: :class:`odoorpc.error.RPCError`
        :raise: `urllib2.URLError` (connection error)

        *Python 3:*

        :raise: :class:`odoorpc.error.RPCError`
        :raise: `urllib.error.URLError` (connection error)
        """
        data = session.get(name, rc_file)
        if data.get('type') != cls.__name__:
            raise error.InternalError(
                "'{0}' session is not of type '{1}'".format(
                    name, cls.__name__))
        odoo = cls(
            host=data['host'],
            protocol=data['protocol'],
            port=data['port'],
            timeout=data['timeout'],
        )
        odoo.login(db=data['database'],
                   login=data['user'],
                   password=data['passwd'])
        return odoo
예제 #6
0
 def _check_logged_user(self):
     """Check if a user is logged. Otherwise, an error is raised."""
     if not self._env or not self._password or not self._login:
         raise error.InternalError("Login required")