@@ -1,3 +1,4 @@
|
||||
* Remove support for ``:id`` suffix in import data
|
||||
* Add export translations option to trytond-admin
|
||||
* Update TinyMCE to version 7
|
||||
* Add python-format flag to PO files
|
||||
|
||||
@@ -169,9 +169,6 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<record model="ir.message" id="msg_reference_syntax_error">
|
||||
<field name="text">Syntax error for reference: %(value)r in "%(field)s" of "%(model)s" (%(column)s).</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_xml_id_syntax_error">
|
||||
<field name="text">Syntax error for XML id: %(value)r in "%(field)s" of "%(model)s" (%(column)s).</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_domain_validation_record">
|
||||
<field name="text">The value "%(value)s" for field "%(field)s" in record "%(record)s" of "%(model)s" is not valid according to its domain.</field>
|
||||
</record>
|
||||
|
||||
@@ -924,44 +924,6 @@ class ModelStorage(Model):
|
||||
res = '%s,%s' % (relation, res[0].id)
|
||||
return res
|
||||
|
||||
@lru_cache(maxsize=1000)
|
||||
def get_by_id(value, ftype, field, klass, column):
|
||||
if not value:
|
||||
return None
|
||||
relation = None
|
||||
if ftype == 'many2many':
|
||||
value = next(csv.reader(value.splitlines(), delimiter=',',
|
||||
quoting=csv.QUOTE_NONE, escapechar='\\'))
|
||||
elif ftype == 'reference':
|
||||
try:
|
||||
relation, value = value.split(',', 1)
|
||||
except ValueError as e:
|
||||
raise ImportDataError(
|
||||
gettext('ir.msg_reference_syntax_error',
|
||||
value=value,
|
||||
column=column,
|
||||
**klass.__names__(field))) from e
|
||||
value = [value]
|
||||
else:
|
||||
value = [value]
|
||||
res_ids = []
|
||||
for word in value:
|
||||
try:
|
||||
module, xml_id = word.rsplit('.', 1)
|
||||
db_id = ModelData.get_id(module, xml_id)
|
||||
except (ValueError, KeyError) as e:
|
||||
raise ImportDataError(
|
||||
gettext('ir.msg_xml_id_syntax_error',
|
||||
value=word,
|
||||
column=column,
|
||||
**klass.__names__(field))) from e
|
||||
res_ids.append(db_id)
|
||||
if ftype == 'many2many' and res_ids:
|
||||
return res_ids
|
||||
elif ftype == 'reference' and res_ids:
|
||||
return '%s,%s' % (relation, str(res_ids[0]))
|
||||
return res_ids[0]
|
||||
|
||||
def dispatch(create, write, row, Relation=cls):
|
||||
id_ = row.pop('id', None)
|
||||
if id_:
|
||||
@@ -1063,15 +1025,7 @@ class ModelStorage(Model):
|
||||
is_prefix_len = (len(field) == (prefix_len + 1))
|
||||
value = line[i]
|
||||
column = '/'.join(field)
|
||||
if is_prefix_len and field[-1].endswith(':id'):
|
||||
field_name = field[-1][:-3]
|
||||
ftype = fields_def[field_name]['type']
|
||||
res = get_by_id(value, ftype, field_name, klass, column)
|
||||
if ftype == 'many2many':
|
||||
res = [('add', res)] if res else []
|
||||
many2many.add(field_name)
|
||||
row[field[0][:-3]] = res
|
||||
elif is_prefix_len and ':lang=' in field[-1]:
|
||||
if is_prefix_len and ':lang=' in field[-1]:
|
||||
field_name, lang = field[-1].split(':lang=')
|
||||
translate.setdefault(lang, {})[field_name] = value
|
||||
elif is_prefix_len and prefix == field[:-1]:
|
||||
@@ -1157,8 +1111,6 @@ class ModelStorage(Model):
|
||||
data.pop(0)
|
||||
return (row, nbrmax, translate)
|
||||
|
||||
ModelData = pool.get('ir.model.data')
|
||||
|
||||
fields_names = [x.split('/') for x in fields_names]
|
||||
fields_def = cls.fields_get()
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
|
||||
<record model="test.import_data.many2one.target"
|
||||
id="import_data_many2one_target_test">
|
||||
<field name="name">Test</field>
|
||||
</record>
|
||||
|
||||
<record model="test.import_data.many2one.target"
|
||||
id="import_data_many2one_target_duplicate1">
|
||||
<field name="name">Duplicate</field>
|
||||
</record>
|
||||
|
||||
<record model="test.import_data.many2one.target"
|
||||
id="import_data_many2one_target_duplicate2">
|
||||
<field name="name">Duplicate</field>
|
||||
</record>
|
||||
|
||||
<record model="test.import_data.many2many.target"
|
||||
id="import_data_many2many_target_test1">
|
||||
<field name="name">Test 1</field>
|
||||
</record>
|
||||
|
||||
<record model="test.import_data.many2many.target"
|
||||
id="import_data_many2many_target_test2">
|
||||
<field name="name">Test 2</field>
|
||||
</record>
|
||||
|
||||
<record model="test.import_data.many2many.target"
|
||||
id="import_data_many2many_target_test_comma">
|
||||
<field name="name">Test, comma</field>
|
||||
</record>
|
||||
|
||||
<record model="test.import_data.many2many.target"
|
||||
id="import_data_many2many_target_duplicate1">
|
||||
<field name="name">Duplicate</field>
|
||||
</record>
|
||||
|
||||
<record model="test.import_data.many2many.target"
|
||||
id="import_data_many2many_target_duplicate2">
|
||||
<field name="name">Duplicate</field>
|
||||
</record>
|
||||
|
||||
<record model="test.import_data.reference.selection"
|
||||
id="import_data_reference_selection_test">
|
||||
<field name="name">Test</field>
|
||||
</record>
|
||||
|
||||
<record model="test.import_data.reference.selection"
|
||||
id="import_data_reference_selection_duplicate1">
|
||||
<field name="name">Duplicate</field>
|
||||
</record>
|
||||
|
||||
<record model="test.import_data.reference.selection"
|
||||
id="import_data_reference_selection_duplicate2">
|
||||
<field name="name">Duplicate</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -305,28 +305,23 @@ class ImportDataTestCase(unittest.TestCase):
|
||||
'Test many2one'
|
||||
pool = Pool()
|
||||
Many2one = pool.get('test.import_data.many2one')
|
||||
Target = pool.get('test.import_data.many2one.target')
|
||||
|
||||
Target.create([{'name': "Test"}])
|
||||
|
||||
for value in ['Test', '']:
|
||||
with self.subTest(value=value):
|
||||
self.assertEqual(
|
||||
Many2one.import_data(['many2one'], [[value]]), 1)
|
||||
|
||||
@with_transaction()
|
||||
def test_many2one_id(self):
|
||||
"Test many2one with id"
|
||||
pool = Pool()
|
||||
Many2one = pool.get('test.import_data.many2one')
|
||||
|
||||
self.assertEqual(
|
||||
Many2one.import_data(
|
||||
['many2one:id'], [['tests.import_data_many2one_target_test']]),
|
||||
1)
|
||||
|
||||
@with_transaction()
|
||||
def test_many2one_many_rows(self):
|
||||
"Test many2one many rows"
|
||||
pool = Pool()
|
||||
Many2one = pool.get('test.import_data.many2one')
|
||||
Target = pool.get('test.import_data.many2one.target')
|
||||
|
||||
Target.create([{'name': "Test"}])
|
||||
|
||||
self.assertEqual(
|
||||
Many2one.import_data(['many2one'], [['Test'], ['Test']]), 2)
|
||||
@@ -342,22 +337,18 @@ class ImportDataTestCase(unittest.TestCase):
|
||||
with self.assertRaises(ImportDataError):
|
||||
Many2one.import_data(['many2one'], [[value]])
|
||||
|
||||
@with_transaction()
|
||||
def test_many2one_id_invalid(self):
|
||||
"Test many2one invalid id"
|
||||
pool = Pool()
|
||||
Many2one = pool.get('test.import_data.many2one')
|
||||
|
||||
for value in ['foo', 'tests.foo']:
|
||||
with self.subTest(value=value):
|
||||
with self.assertRaises(ImportDataError):
|
||||
Many2one.import_data(['many2one:id'], [[value]])
|
||||
|
||||
@with_transaction()
|
||||
def test_many2many(self):
|
||||
'Test many2many'
|
||||
pool = Pool()
|
||||
Many2many = pool.get('test.import_data.many2many')
|
||||
Target = pool.get('test.import_data.many2many.target')
|
||||
|
||||
Target.create([
|
||||
{'name': "Test 1"},
|
||||
{'name': "Test 2"},
|
||||
{'name': "Test, comma"},
|
||||
])
|
||||
|
||||
for value in [
|
||||
'Test 1', 'Test\\, comma', 'Test\\, comma,Test 1',
|
||||
@@ -366,25 +357,18 @@ class ImportDataTestCase(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
Many2many.import_data(['many2many'], [[value]]), 1)
|
||||
|
||||
@with_transaction()
|
||||
def test_many2many_id(self):
|
||||
"Test many2many with id"
|
||||
pool = Pool()
|
||||
Many2many = pool.get('test.import_data.many2many')
|
||||
|
||||
for value in [
|
||||
'tests.import_data_many2many_target_test1',
|
||||
'tests.import_data_many2many_target_test1,'
|
||||
'tests.import_data_many2many_target_test2']:
|
||||
with self.subTest(value=value):
|
||||
self.assertEqual(
|
||||
Many2many.import_data(['many2many:id'], [[value]]), 1)
|
||||
|
||||
@with_transaction()
|
||||
def test_many2many_many_rows(self):
|
||||
"Test many2many many rows"
|
||||
pool = Pool()
|
||||
Many2many = pool.get('test.import_data.many2many')
|
||||
Target = pool.get('test.import_data.many2many.target')
|
||||
|
||||
Target.create([
|
||||
{'name': "Test 1"},
|
||||
{'name': "Test 2"},
|
||||
{'name': "Test, comma"},
|
||||
])
|
||||
|
||||
self.assertEqual(
|
||||
Many2many.import_data(['many2many'], [['Test 1'], ['Test 2']]), 2)
|
||||
@@ -486,6 +470,9 @@ class ImportDataTestCase(unittest.TestCase):
|
||||
'Test reference'
|
||||
pool = Pool()
|
||||
Reference = pool.get('test.import_data.reference')
|
||||
Selection = pool.get('test.import_data.reference.selection')
|
||||
|
||||
Selection.create([{'name': "Test"}])
|
||||
|
||||
self.assertEqual(Reference.import_data(['reference'],
|
||||
[['test.import_data.reference.selection,Test']]), 1)
|
||||
@@ -493,19 +480,6 @@ class ImportDataTestCase(unittest.TestCase):
|
||||
self.assertEqual(reference.reference.__name__,
|
||||
'test.import_data.reference.selection')
|
||||
|
||||
@with_transaction()
|
||||
def test_reference_id(self):
|
||||
"Test reference with id"
|
||||
pool = Pool()
|
||||
Reference = pool.get('test.import_data.reference')
|
||||
|
||||
self.assertEqual(Reference.import_data(['reference:id'],
|
||||
[['test.import_data.reference.selection,'
|
||||
'tests.import_data_reference_selection_test']]), 1)
|
||||
reference, = Reference.search([])
|
||||
self.assertEqual(reference.reference.__name__,
|
||||
'test.import_data.reference.selection')
|
||||
|
||||
@with_transaction()
|
||||
def test_reference_empty(self):
|
||||
"Test reference empty"
|
||||
@@ -522,6 +496,9 @@ class ImportDataTestCase(unittest.TestCase):
|
||||
"Test reference many rows"
|
||||
pool = Pool()
|
||||
Reference = pool.get('test.import_data.reference')
|
||||
Selection = pool.get('test.import_data.reference.selection')
|
||||
|
||||
Selection.create([{'name': "Test"}])
|
||||
|
||||
self.assertEqual(Reference.import_data(['reference'],
|
||||
[['test.import_data.reference.selection,Test'],
|
||||
@@ -544,17 +521,6 @@ class ImportDataTestCase(unittest.TestCase):
|
||||
with self.assertRaises(ImportDataError):
|
||||
Reference.import_data(['reference'], [[value]])
|
||||
|
||||
@with_transaction()
|
||||
def test_reference_id_invalid(self):
|
||||
"Test reference invalid id"
|
||||
pool = Pool()
|
||||
Reference = pool.get('test.import_data.reference')
|
||||
|
||||
with self.assertRaises(ImportDataError):
|
||||
Reference.import_data(
|
||||
['reference:id'],
|
||||
[['test.import_data.reference.selection,foo']])
|
||||
|
||||
@with_transaction()
|
||||
def test_binary_bytes(self):
|
||||
"Test binary bytes"
|
||||
@@ -622,22 +588,6 @@ class ImportDataTestCase(unittest.TestCase):
|
||||
self.assertEqual(count, 1)
|
||||
self.assertEqual([m.name for m in record.many2many], ["Bar"])
|
||||
|
||||
@with_transaction()
|
||||
def test_update_many2many_id(self):
|
||||
"Test update many2many with id"
|
||||
pool = Pool()
|
||||
Many2many = pool.get('test.import_data.many2many')
|
||||
|
||||
record = Many2many(many2many=[{'name': "Foo"}])
|
||||
record.save()
|
||||
|
||||
count = Many2many.import_data(
|
||||
['id', 'many2many:id'],
|
||||
[[record.id, 'tests.import_data_many2many_target_test1']])
|
||||
|
||||
self.assertEqual(count, 1)
|
||||
self.assertEqual([m.name for m in record.many2many], ["Test 1"])
|
||||
|
||||
@with_transaction()
|
||||
def test_update_one2many(self):
|
||||
"Test update one2many"
|
||||
|
||||
@@ -3,7 +3,6 @@ depends:
|
||||
ir
|
||||
res
|
||||
xml:
|
||||
import_data.xml
|
||||
sequence.xml
|
||||
workflow.xml
|
||||
wizard.xml
|
||||
|
||||
Reference in New Issue
Block a user