Files
odoo_source/odoo/addons/test_convert/models.py
T
6367a89332 [FIX] core: import of o2m with recursive xml declaration
Let's imagine this data

```xml
<record model="my.model" id="1">
    <field name="name">parent</field>
    <field name="children_ids">
	<record model="my.model" id="1.1">
	    <field name="name">child</field>
	</record>
    </field>
</record>
```

Loading this data the first time, everything works fine.
But if we update it, this is what happens:
* load `my.model,1`: write on `name=parent` and `children_ids=None`
* load `my.model,1.1`: write on `name=child` and `parent_id=my.model,1`

The write on `children_ids=None` can unlink all the children if the
field is declared as `ondelete=cascade`
That will leade in all the records to be deleted and recreated, but
without keeping links with other documents.

For instance, when upgrading the `account` module, all the
`account.account.tag` are removed from `account.move.line` because when
the `account.tax.report.line` are updated, all the tags are deleted and
recreated.

closes odoo/odoo#82793

X-original-commit: de00316fa42173f3a5c394458bb4418e59e298cd
Signed-off-by: Raphael Collet <rco@odoo.com>
Signed-off-by: William André (wan) <wan@odoo.com>
Co-authored-by: rco-odoo <rco@odoo.com>
Co-authored-by: jva-odoo <jva@odoo.com>
Co-authored-by: william-andre <wan@odoo.com>
2022-01-14 16:37:50 +00:00

39 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class TestModel(models.Model):
_name = 'test_convert.test_model'
_description = "Test Convert Model"
usered_ids = fields.One2many('test_convert.usered', 'test_id')
@api.model
def action_test_date(self, today_date):
return True
@api.model
def action_test_time(self, cur_time):
return True
@api.model
def action_test_timezone(self, timezone):
return True
class Usered(models.Model):
_name = 'test_convert.usered'
_description = "z test model ignore"
name = fields.Char()
user_id = fields.Many2one('res.users', default=lambda self: self.env.user)
test_id = fields.Many2one('test_convert.test_model')
tz = fields.Char(default=lambda self: self.env.context.get('tz') or self.env.user.tz)
@api.model
def model_method(self, *args, **kwargs):
return self, args, kwargs
def method(self, *args, **kwargs):
return self, args, kwargs