|
7 | 7 | from operator import itemgetter |
8 | 8 | from textwrap import dedent |
9 | 9 |
|
| 10 | +from psycopg2.extras import execute_values |
| 11 | + |
10 | 12 | try: |
11 | 13 | from unittest.mock import patch |
12 | 14 | except ImportError: |
@@ -424,6 +426,37 @@ def custom_module_field_as_manual(env, rollback=True, do_flush=False): |
424 | 426 | ) |
425 | 427 | mock_x_email_fields = [r[0] for r in env.cr.fetchall()] |
426 | 428 |
|
| 429 | + temp_ir_model_access_ids = [] |
| 430 | + if version_gte("14.0") and custom_models: |
| 431 | + # 1.2 Version 14.0 and above requires new access rights for transient models, |
| 432 | + # and the rights are yet to be added post standard upgrade for custom modules. |
| 433 | + # To avoid access errors, create some temporary access rights for these models. |
| 434 | + env.cr.execute( |
| 435 | + """ |
| 436 | + SELECT id |
| 437 | + FROM ir_model |
| 438 | + WHERE model IN %s |
| 439 | + AND transient |
| 440 | + AND id NOT IN ( |
| 441 | + SELECT DISTINCT model_id |
| 442 | + FROM ir_model_access |
| 443 | + WHERE active |
| 444 | + ) |
| 445 | + """, |
| 446 | + [custom_models], |
| 447 | + ) |
| 448 | + |
| 449 | + no_access_custom_transient_ids = env.cr.fetchall() |
| 450 | + |
| 451 | + if no_access_custom_transient_ids: |
| 452 | + insert_query = """ |
| 453 | + INSERT INTO ir_model_access (name, active, model_id, perm_read, perm_write, perm_create, perm_unlink) |
| 454 | + VALUES ('tmp_access', true, %s, true, true, true, true) |
| 455 | + RETURNING id |
| 456 | + """ |
| 457 | + execute_values(env.cr._obj, insert_query, no_access_custom_transient_ids) |
| 458 | + temp_ir_model_access_ids = [r[0] for r in env.cr.fetchall()] |
| 459 | + |
427 | 460 | # 2. Convert fields which are not in the registry to `manual` fields |
428 | 461 | # and list the fields that were converted, to restore them back afterwards. |
429 | 462 | # Also temporarily disable rules (ir.rule) that come from custom modules. |
@@ -596,6 +629,8 @@ def patch_display_name(): |
596 | 629 | ) |
597 | 630 | if disabled_ir_rule_ids: |
598 | 631 | env.cr.execute("UPDATE ir_rule SET active = 't' WHERE id IN %s", (tuple(disabled_ir_rule_ids),)) |
| 632 | + if temp_ir_model_access_ids: |
| 633 | + env.cr.execute("DELETE FROM ir_model_access WHERE id IN %s", [tuple(temp_ir_model_access_ids)]) |
599 | 634 | for field_id, selection in updated_selection_fields: |
600 | 635 | env.cr.execute("UPDATE ir_model_fields SET selection = %s WHERE id = %s", (selection, field_id)) |
601 | 636 | for field_id, on_delete in updated_many2one_fields: |
|
0 commit comments