Browse Source

[RFR] use odoorpc

pull/988/head
Holger Brunn 7 years ago
parent
commit
60cba35fbd
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  1. 1
      .travis.yml
  2. 2
      base_import_odoo/__openerp__.py
  3. 26
      base_import_odoo/models/import_odoo_database.py
  4. 34
      base_import_odoo/tests/test_base_import_odoo.py
  5. 1
      requirements.txt

1
.travis.yml

@ -33,7 +33,6 @@ install:
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly
- printf '[options]\n\nrunning_env = dev\n' > ${HOME}/.openerp_serverrc
- pip install erppeek
- ln -s ${TRAVIS_BUILD_DIR}/server_environment_files_sample ${TRAVIS_BUILD_DIR}/server_environment_files
script:
- travis_run_tests

2
base_import_odoo/__openerp__.py

@ -25,6 +25,6 @@
],
"installable": True,
"external_dependencies": {
"python": ['erppeek'],
"python": ['odoorpc'],
},
}

26
base_import_odoo/models/import_odoo_database.py

@ -3,11 +3,12 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
try:
from erppeek import Client
import odoorpc
except:
logging.debug('Unable to import erppeek')
logging.error('Unable to import odoorpc')
import psycopg2
import traceback
from urlparse import urlparse
from openerp import _, api, exceptions, fields, models, tools
from collections import namedtuple
@ -105,8 +106,8 @@ class ImportOdooDatabase(models.Model):
self.env.cr.commit()
for model_line in self.import_line_ids:
model = model_line.model_id
remote_ids[model.model] = remote.search(
model.model,
remote_ids[model.model] = remote.execute(
model.model, 'search',
tools.safe_eval(model_line.domain) if model_line.domain else []
)
remote_counts[model.model] = len(remote_ids[model.model])
@ -159,8 +160,8 @@ class ImportOdooDatabase(models.Model):
"""Import records of a configured model"""
model = self.env[context.model_line.model_id.model]
fields = self._run_import_model_get_fields(context)
for data in context.remote.read(
model._name, context.ids, fields.keys()
for data in context.remote.execute(
model._name, 'read', context.ids, fields.keys()
):
self._run_import_get_record(context, model, data)
if (model._name, data['id']) in context.idmap:
@ -449,7 +450,18 @@ class ImportOdooDatabase(models.Model):
def _get_connection(self):
self.ensure_one()
return Client(self.url, self.database, self.user, self.password)
url = urlparse(self.url)
hostport = url.netloc.split(':')
if len(hostport) == 1:
hostport.append('80')
host, port = hostport
remote = odoorpc.ODOO(
host,
protocol='jsonrpc+ssl' if url.scheme == 'https' else 'jsonrpc',
port=int(port),
)
remote.login(self.database, self.user, self.password)
return remote
@api.constrains('url', 'database', 'user', 'password')
@api.multi

34
base_import_odoo/tests/test_base_import_odoo.py

@ -8,28 +8,21 @@ from openerp.tests.common import TransactionCase, post_install, at_install
class TestBaseImportOdoo(TransactionCase):
@at_install(False)
@post_install(True)
@patch('erppeek.Client.__init__', side_effect=lambda *args: None)
def test_base_import_odoo(self, mock_client_init):
@patch(
'odoorpc.ODOO.__init__',
side_effect=lambda self, *args, **kwargs: None,
)
@patch('odoorpc.ODOO.login', side_effect=lambda *args: None)
def test_base_import_odoo(self, mock_client, mock_client_login):
# the mocked functions simply search/read in the current database
# the effect then should be that the models in question are duplicated,
# we just need to try not to be confused by the fact that local and
# remote ids are the same
def _mock_search(
model, domain, offset=0, limit=None, order=None, context=None,
):
return self.env[model].with_context(
**(context or self.env.context)
).search(
domain, offset=offset, limit=limit, order=order,
).ids
def _mock_read(
model, domain_or_ids, fields=None, offset=0, limit=None,
order=None, context=None,
):
return self.env[model].with_context(
**(context or self.env.context)
).browse(domain_or_ids).read(fields=fields)
def _mock_execute(model, method, *args):
if method == 'read':
return self.env[model].browse(args[0]).read(fields=args[1])
if method == 'search':
return self.env[model].search(args[0]).ids
group_count = self.env['res.groups'].search([], count=True)
user_count = self.env['res.users'].search([], count=True)
@ -39,9 +32,8 @@ class TestBaseImportOdoo(TransactionCase):
self.env.ref('base_import_odoo.demodb').write({
'password': 'admin',
})
with patch('erppeek.Client.search', side_effect=_mock_search):
with patch('erppeek.Client.read', side_effect=_mock_read):
self.env.ref('base_import_odoo.demodb')._run_import()
with patch('odoorpc.ODOO.execute', side_effect=_mock_execute):
self.env.ref('base_import_odoo.demodb')._run_import()
# here the actual test begins - check that we created new
# objects, check xmlids, check values, check if dummies are
# cleaned up/replaced

1
requirements.txt

@ -6,3 +6,4 @@
acme_tiny
IPy
python-json-logger
odoorpc
Loading…
Cancel
Save