Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_v_alphanumeric(self):
self.assertEqual(tools.v('7.0alpha'), [7, 0])
def setUp(self):
self.odoo = odoorpc.ODOO(
ARGS.server, protocol=ARGS.protocol, port=ARGS.port,
version=ARGS.version)
if v(self.odoo.version) < v('6.1'):
raise unittest.SkipTest(
"The targetted OpenERP server does not support the "
"'execute_kw()' method.")
self.user = self.odoo.login(ARGS.database, ARGS.user, ARGS.passwd)
The super administrator password is required to perform this method.
*Python 2:*
:return: `io.BytesIO`
:raise: :class:`odoorpc.error.RPCError` (access denied / wrong database)
:raise: `urllib2.URLError` (connection error)
*Python 3:*
:return: `io.BytesIO`
:raise: :class:`odoorpc.error.RPCError` (access denied / wrong database)
:raise: `urllib.error.URLError` (connection error)
"""
args = [password, db]
if v(self._odoo.version)[0] >= 9:
args.append(format_)
data = self._odoo.json(
'/jsonrpc', {'service': 'db', 'method': 'dump', 'args': args}
)
# Encode to bytes forced to be compatible with Python 3.2
# (its 'base64.standard_b64decode()' function only accepts bytes)
result = encode2bytes(data['result'])
content = base64.standard_b64decode(result)
return io.BytesIO(content)
The super administrator password is required to perform this method.
*Python 2:*
:return: `io.BytesIO`
:raise: :class:`odoorpc.error.RPCError` (access denied / wrong database)
:raise: `urllib2.URLError` (connection error)
*Python 3:*
:return: `io.BytesIO`
:raise: :class:`odoorpc.error.RPCError` (access denied / wrong database)
:raise: `urllib.error.URLError` (connection error)
"""
args = [password, db]
if v(self._odoo.version)[0] >= 9:
args.append(format_)
data = self._odoo.json(
'/jsonrpc',
{'service': 'db',
'method': 'dump',
'args': args})
# Encode to bytes forced to be compatible with Python 3.2
# (its 'base64.standard_b64decode()' function only accepts bytes)
result = encode2bytes(data['result'])
content = base64.standard_b64decode(result)
return io.BytesIO(content)
def _get_models_data(self, models, models_blacklist):
"""Returns a dictionary `{MODEL: DATA, ...}` of models corresponding to
`models - models_blacklist` patterns (whitelist substracted
by a blacklist).
"""
res = {}
# OpenERP v5 does not have the 'modules' field on 'ir.model' used to
# bound a data model and its related modules.
if v(self.oerp.version) <= v('6.0'):
return res
models_patterns = \
[pattern2oerp(model) for model in (models)]
models_blacklist_patterns = \
[pattern2oerp(model) for model in (models_blacklist)]
if models:
model_obj = self.oerp.get('ir.model')
args = [('model', '=ilike', model)
for model in models_patterns]
for _ in range(len(args) - 1):
args.insert(0, '|')
for model in models_blacklist_patterns:
args.append('!')
args.append(('model', '=ilike', model))
ids = model_obj.search(args)
for data in model_obj.read(ids, ['model', 'modules', 'osv_memory']):
def check_report(name):
report_model = 'ir.actions.report'
if v(self._odoo.version)[0] < 11:
report_model = 'ir.actions.report.xml'
IrReport = self._odoo.env[report_model]
report_ids = IrReport.search([('report_name', '=', name)])
report_id = report_ids and report_ids[0] or False
if not report_id:
raise ValueError("The report '%s' does not exist." % name)
return report_id
report_id = check_report(name)
# Odoo >= 11.0
if v(self._odoo.version)[0] >= 11:
IrReport = self._odoo.env['ir.actions.report']
report = IrReport.browse(report_id)
response = report.with_context(context).render(ids, data=datas)
content = response[0]
# On the server the result is a bytes string,
# but the RPC layer of Odoo returns it as a unicode string,
# so we encode it again as bytes
result = content.encode('latin1')
return io.BytesIO(result)
# Odoo < 11.0
else:
args_to_send = [
self._odoo.env.db,
self._odoo.env.uid,
self._odoo._password,
name,