This commit is contained in:
Cédric Krier committed 2012-10-10 11:03:16 +02:00
commit 36fc7e0fb3
12 files changed
+96 -33

No files matched your search

-4
View File
@@ -68,10 +68,6 @@ jsonrpc = localhost:8000
# Configure the session timeout (inactivity of the client in sec)
#session_timeout = 600
# Enable psyco module
# Need to have psyco installed http://psyco.sourceforge.net/
#psyco = False
# Enable auto-reload of modules if changed
#auto_reload = True
-1
View File
@@ -72,7 +72,6 @@ class ConfigManager(object):
'data_path': '/var/lib/trytond',
'multi_server': False,
'session_timeout': 600,
'psyco': False,
'auto_reload': True,
'prevent_dblist': False,
'init': {},
+8 -17
View File
@@ -685,7 +685,7 @@ class ModelGraph(Report):
])
if not action_report_ids:
raise Exception('Error', 'Report (%s) not find!' % cls.__name__)
action_report = ActionReport.browse(action_report_ids[0])
action_report = ActionReport(action_report_ids[0])
models = Model.browse(ids)
@@ -725,7 +725,7 @@ class ModelGraph(Report):
for model in models:
if filter and re.search(filter, model.model):
continue
label = '{' + model.model + '\\n'
label = '"{' + model.model + '\\n'
if model.fields:
label += '|'
for field in model.fields:
@@ -736,32 +736,23 @@ class ModelGraph(Report):
if field.relation:
label += ' ' + field.relation
label += '\l'
label += '}'
if pydot.__version__ == '1.0.2':
# version 1.0.2 doesn't quote correctly label on Node object
label = '"' + label + '"'
node = pydot.Node(str(model.model), shape='record', label=label)
label += '}"'
node_name = '"%s"' % model.model
node = pydot.Node(node_name, shape='record', label=label)
graph.add_node(node)
for field in model.fields:
if field.name in ('create_uid', 'write_uid'):
continue
if field.relation:
node_name = field.relation
if pydot.__version__ == '1.0.2':
# version 1.0.2 doesn't quote correctly node name
node_name = '"' + node_name + '"'
node_name = '"%s"' % field.relation
if not graph.get_node(node_name):
continue
args = {}
tail = model.model
head = field.relation
edge_model_name = model.model
edge_relation_name = field.relation
if pydot.__version__ == '1.0.2':
# version 1.0.2 doesn't quote correctly edge name
edge_model_name = '"' + edge_model_name + '"'
edge_relation_name = '"' + edge_relation_name + '"'
edge_model_name = '"%s"' % model.model
edge_relation_name = '"%s"' % field.relation
if field.ttype == 'many2one':
edge = graph.get_edge(edge_model_name,
edge_relation_name)
+3 -2
View File
@@ -347,7 +347,7 @@ class ModelSQL(ModelStorage):
if field.required and \
not hasattr(field, 'set') and \
field_name not in ('create_uid', 'create_date'):
if not values.get(field_name):
if values.get(field_name) is None:
cls.raise_user_error('required_field',
error_args=cls._get_error_args(
field_name))
@@ -1047,7 +1047,8 @@ class ModelSQL(ModelStorage):
if rowcount == -1 or rowcount is None:
rowcount = len(cursor.fetchall())
if not rowcount == len({}.fromkeys(sub_ids)):
cls.raise_user_error('access_error', cls._description)
cls.raise_user_error('access_error',
cls.__doc__.splitlines()[0])
cls.trigger_delete(records)
+3 -3
View File
@@ -254,7 +254,7 @@ class ModelStorage(Model):
if field_name in default:
data[field_name] = default[field_name]
elif ftype == 'function':
elif isinstance(cls._fields[field_name], fields.Function):
del data[field_name]
elif ftype in ('many2one', 'one2one'):
try:
@@ -592,7 +592,7 @@ class ModelStorage(Model):
warn('too_many_relations_found', value, relation)
res = None
else:
res = '%s,%s' % (relation, str(res[0]))
res = '%s,%s' % (relation, res[0].id)
return res
def get_by_id(value):
@@ -1362,7 +1362,7 @@ class EvalEnvironment(dict):
value = getattr(self._record, item)
if isinstance(value, Model):
return value.id
elif isinstance(value, list):
elif isinstance(value, (list, tuple)):
return [r.id for r in value]
else:
return value
+1 -1
View File
@@ -107,7 +107,7 @@ def dispatch(host, port, protocol, database_name, user, session, object_type,
res = []
for type in ('model', 'wizard', 'report'):
for object_name, obj in pool.iterobject(type=type):
for method in obj._rpc:
for method in obj.__rpc__:
res.append(type + '.' + object_name + '.' + method)
return res
elif method == 'methodSignature':
-4
View File
@@ -93,10 +93,6 @@ class TrytonServer(object):
with open(CONFIG['pidfile'], 'w') as fd_pid:
fd_pid.write("%d" % (os.getpid()))
if CONFIG['psyco']:
import psyco
psyco.full()
if not CONFIG["db_name"] \
and bool(CONFIG['init'] or CONFIG['update']):
raise Exception('Missing database option!')
+1
View File
@@ -89,6 +89,7 @@ def register():
ModelInheritsSubSubModel,
ModelInheritsSubSubSubModel,
ModelInheritsOverriddenFieldModel,
ModelSQLRequiredField,
MPTT,
ImportDataBoolean,
ImportDataInteger,
+9 -1
View File
@@ -5,7 +5,7 @@ from trytond.model import ModelSingleton, ModelSQL, fields
__all__ = [
'Singleton', 'URLObject', 'ModelInherits', 'ModelInheritsSubModel',
'ModelInheritsSubSubModel', 'ModelInheritsSubSubSubModel',
'ModelInheritsOverriddenFieldModel',
'ModelInheritsOverriddenFieldModel', 'ModelSQLRequiredField'
]
@@ -70,3 +70,11 @@ class ModelInheritsOverriddenFieldModel(ModelSQL):
subfield = fields.Integer('Overridden field')
parent_model = fields.Many2One('test.subsubmodel', 'Parent model',
required=True)
class ModelSQLRequiredField(ModelSQL):
'model with a required field'
__name__ = 'test.modelsql'
integer = fields.Integer(string="integer", required=True)
desc = fields.Char(string="desc", required=True)
+15
View File
@@ -364,19 +364,34 @@ class ImportDataTestCase(unittest.TestCase):
self.assertEqual(self.reference.import_data(['reference'],
[['test.import_data.reference.selection,Test']]),
(1, 0, 0, 0))
reference, = self.reference.search([])
self.assertEqual(reference.reference.__name__,
'test.import_data.reference.selection')
transaction.cursor.rollback()
self.assertEqual(self.reference.import_data(['reference:id'],
[['test.import_data.reference.selection,'
'test.import_data_reference_selection_test']]),
(1, 0, 0, 0))
reference, = self.reference.search([])
self.assertEqual(reference.reference.__name__,
'test.import_data.reference.selection')
transaction.cursor.rollback()
self.assertEqual(self.reference.import_data(['reference'],
[['']]), (1, 0, 0, 0))
reference, = self.reference.search([])
self.assertEqual(reference.reference, None)
transaction.cursor.rollback()
self.assertEqual(self.reference.import_data(['reference'],
[['test.import_data.reference.selection,Test'],
['test.import_data.reference.selection,Test']]),
(2, 0, 0, 0))
for reference in self.reference.search([]):
self.assertEqual(reference.reference.__name__,
'test.import_data.reference.selection')
transaction.cursor.rollback()
self.assertEqual(self.reference.import_data(['reference'],
[['test.import_data.reference.selection,foo']])[0], -1)
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of Tryton. The COPYRIGHT file at the top level of this
# repository contains the full copyright notices and license terms.
import unittest
from trytond.config import CONFIG
from trytond.exceptions import UserError
from trytond.transaction import Transaction
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT, \
install_module
class ModelSQLTestCase(unittest.TestCase):
'''
Test ModelSQL
'''
def setUp(self):
install_module('test')
self.modelsql = POOL.get('test.modelsql')
def test0010required_field_missing(self):
'''
Test error message when a required field is missing.
'''
if CONFIG['db_type'] not in ('postgresql', 'mysql'):
# SQLite not concerned because tryton don't set "NOT NULL"
# constraint: 'ALTER TABLE' don't support NOT NULL constraint
# without default value
return
fields = {
'desc': '',
'integer': 0,
}
for key, value in fields.iteritems():
with Transaction().start(DB_NAME, USER, context=CONTEXT):
try:
self.modelsql.create({key: value})
except UserError, err:
# message must not quote key
msg = "'%s' not missing but quoted in error: '%s'" % (key,
err.message)
self.assertTrue(key not in err.message, msg)
continue
self.fail('UserError should be caught')
def suite():
return unittest.TestLoader().loadTestsFromTestCase(ModelSQLTestCase)
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())
+2
View File
@@ -255,6 +255,8 @@ def all_suite():
suite_.addTests(test_wizard.suite())
import trytond.tests.test_model_inherits as test_inherits
suite_.addTests(test_inherits.suite())
import trytond.tests.test_modelsql as test_modelsql
suite_.addTests(test_modelsql.suite())
return suite_