diff options
| author | Christophe Simonis <chs@odoo.com> | 2016-10-17 16:00:39 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2016-10-17 16:00:39 +0200 |
| commit | 53d8f76a401de522dca40471b161bf91b86a3a0e (patch) | |
| tree | 8294518369751f6707d6fd68421c066069b99c50 /odoo | |
| parent | a9abce09c066df2a04d1c49ae719b7881ac7e175 (diff) | |
| parent | e8e4145c998c335d00a48a0b2a7a9e961b3f3983 (diff) | |
[MERGE] forward port branch saas-12 up to e8e4145
Diffstat (limited to 'odoo')
| -rw-r--r-- | odoo/addons/test_new_api/tests/__init__.py | 1 | ||||
| -rw-r--r-- | odoo/addons/test_new_api/tests/test_onchange.py | 2 | ||||
| -rw-r--r-- | odoo/fields.py | 16 | ||||
| -rw-r--r-- | odoo/models.py | 3 |
4 files changed, 14 insertions, 8 deletions
diff --git a/odoo/addons/test_new_api/tests/__init__.py b/odoo/addons/test_new_api/tests/__init__.py index 2bbcfe40990..b90ccc96825 100644 --- a/odoo/addons/test_new_api/tests/__init__.py +++ b/odoo/addons/test_new_api/tests/__init__.py @@ -3,5 +3,6 @@ from . import test_new_fields from . import test_onchange from . import test_attributes +from . import test_one2many from . import test_ui from . import test_domain diff --git a/odoo/addons/test_new_api/tests/test_onchange.py b/odoo/addons/test_new_api/tests/test_onchange.py index 87fc8229b7c..a6e2bff1b35 100644 --- a/odoo/addons/test_new_api/tests/test_onchange.py +++ b/odoo/addons/test_new_api/tests/test_onchange.py @@ -176,7 +176,7 @@ class TestOnChange(common.TransactionCase): self.assertEqual(values, { 'name': partner.name, 'partner': partner.id, - 'lines': [(5,), (4, line.id)], + 'lines': [(6, 0, [line.id])], }) # modify 'partner' diff --git a/odoo/fields.py b/odoo/fields.py index ee732b5b62f..c542945a781 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -894,10 +894,12 @@ class Field(object): env.invalidate(spec) else: - # simply write to the database, and update cache + # Write to database write_value = self.convert_to_write(self.convert_to_record(value, record), record) record.write({self.name: write_value}) - record._cache[self] = value + # Update the cache unless value contains a new record + if not (self.relational and not all(value)): + record._cache[self] = value ############################################################################ # @@ -1987,7 +1989,7 @@ class _RelationalMulti(_Relational): def convert_to_write(self, value, record): # make result with new and existing records - result = [(5,)] + result = [(6, 0, [])] for record in value: if not record.id: values = {name: record[name] for name in record._cache} @@ -1998,7 +2000,7 @@ class _RelationalMulti(_Relational): values = record._convert_to_write(values) result.append((1, record.id, values)) else: - result.append((4, record.id)) + result[0][2].append(record.id) return result def convert_to_onchange(self, value, record, fnames=()): @@ -2171,7 +2173,11 @@ class One2many(_RelationalMulti): query = "SELECT id FROM %s WHERE %s=%%s AND id <> ALL(%%s)" % (comodel._table, inverse) comodel._cr.execute(query, (record.id, act[2] or [0])) lines = comodel.browse([row[0] for row in comodel._cr.fetchall()]) - lines.write({inverse: False}) + inverse_field = comodel._fields[inverse] + if inverse_field.ondelete == 'cascade': + lines.unlink() + else: + lines.write({inverse: False}) class Many2many(_RelationalMulti): diff --git a/odoo/models.py b/odoo/models.py index 714cde7ff0b..8f15a59d7cd 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -3508,8 +3508,7 @@ class BaseModel(object): ``(6, _, ids)`` replaces all existing records in the set by the ``ids`` list, equivalent to using the command ``5`` followed by a command - ``4`` for each ``id`` in ``ids``. Can not be used on - :class:`~odoo.fields.One2many`. + ``4`` for each ``id`` in ``ids``. .. note:: Values marked as ``_`` in the list above are ignored and can be anything, generally ``0`` or ``False``. |
