[FIX] core: check rules before flush() in unlink()
Just before deleting records, we mark fields on dependent records as "to compute", and their actual computation should happen after the records have been deleted. The problem is that checking security rules may trigger the computations that have been prepared. So we should check security rules before marking dependent records. closes odoo/odoo#85574 X-original-commit: 79908bc757a239c97bd2b4cda505b7b8df769325 Signed-off-by: Raphael Collet <rco@odoo.com>
This commit is contained in:
@@ -2536,6 +2536,24 @@ class TestFields(TransactionCaseWithUserDemo):
|
||||
self.assertFalse(Model.rare_description.prefetch)
|
||||
self.assertFalse(Model.rare_html_description.prefetch)
|
||||
|
||||
def test_98_unlink_recompute(self):
|
||||
move = self.env['test_new_api.move'].create({
|
||||
'line_ids': [(0, 0, {'quantity': 42})],
|
||||
})
|
||||
line = move.line_ids
|
||||
self.assertEqual(move.quantity, 42)
|
||||
|
||||
# create an ir.rule for lines that uses move.quantity
|
||||
self.env['ir.rule'].create({
|
||||
'model_id': self.env['ir.model']._get(line._name).id,
|
||||
'domain_force': "[('move_id.quantity', '>=', 0)]",
|
||||
})
|
||||
|
||||
# unlink the line, and check the recomputation of move.quantity
|
||||
user = self.env.ref('base.user_demo')
|
||||
line.with_user(user).unlink()
|
||||
self.assertEqual(move.quantity, 0)
|
||||
|
||||
|
||||
class TestX2many(common.TransactionCase):
|
||||
def test_definition_many2many(self):
|
||||
|
||||
+1
-2
@@ -3635,6 +3635,7 @@ Fields:
|
||||
return True
|
||||
|
||||
self.check_access_rights('unlink')
|
||||
self.check_access_rule('unlink')
|
||||
self._check_concurrency()
|
||||
|
||||
from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG
|
||||
@@ -3649,8 +3650,6 @@ Fields:
|
||||
self.modified(self._fields, before=True)
|
||||
|
||||
with self.env.norecompute():
|
||||
self.check_access_rule('unlink')
|
||||
|
||||
cr = self._cr
|
||||
Data = self.env['ir.model.data'].sudo().with_context({})
|
||||
Defaults = self.env['ir.default'].sudo()
|
||||
|
||||
Reference in New Issue
Block a user