Commit Graph
191 Commits
Author SHA1 Message Date
Romain Derie 90a9dce222 [FIX] base, (test_)website: remove the copy_ids orphan leftover
Before this commit, if a theme record (eg `theme.ir.ui.view`) was deleted,
its copy_ids would not be.
While this is perfectly normal and wanted behavior when this is done in a
website context (to not alter other websites), it shouldn't be the case when
performing a theme update through CLI/Migration (or if the user find a way to
update the module through the UI).

Fixes https://github.com/odoo/upgrade/pull/3048
task-2593407
opw-2680866
opw-2685951
opw-2685124
opw-2679040

closes odoo/odoo#81953

X-original-commit: 3146dd72e6cb07d6e78ca763325f13dd54de0086
Related: odoo/design-themes#548
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2021-12-28 11:47:05 +00:00
Xavier-Do 74ff542278 [IMP] base: avoid setup_models() when creating custom selection
There exists an optimization when creating fields to avoid calling
`setup_models()` for fields when creating a custom model, since the
latter already calls `setup_models()`.

We add the same optimization for field selections, so that creating a
custom field with selections only calls `setup_models()` once.  Note
that both optimizations are combined when creating custom models with
selection fields: `setup_models()` will be called once for all.

closes odoo/odoo#78514

Related: odoo/enterprise#21746
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2021-10-22 17:34:19 +00:00
Xavier-Do a6c40de0f9 [IMP] base: batch creation of custom models
Part-of: odoo/odoo#78514
2021-10-22 17:34:19 +00:00
Raphael Collet 76f699ca0b [IMP] base: batch creation of custom related fields
Before this commit, trying to create a field related to another field in
the same batch raises an error, because the computation of the field
'related_field_id' cannot find the target field in the registry.

The new approach consists in getting the target field from the database
instead.  It works when creating fields in batch, because all records
are inserted into the database before the field is computated.

This costs extra queries, but it allows to batch field creation and
avoids multiple calls to setup_models() when creating a model with
partner field in Studio. (see odoo/enterprise#21746)

The creation of a simple custom related field (related="x.y") costs 3
additional queries to determine the target field:
 - 2 queries to get a given field on a given model
 - 1 query to get the first field's comodel

Part-of: odoo/odoo#78514
2021-10-22 17:34:18 +00:00
Xavier Morel b4b260b916 [IMP] base: batch creation of custom fields
Registry updates can be quite expensive (on the order of a second).
When creating new fields, this update is performed *for each field*,
leading to sub-par performances when bulk-creating fields.

Also remove `_existing_field_data` which has been unused since
9afce4805f, and the `clear_caches`
set up for that purpose.

Part-of: odoo/odoo#78514
2021-10-22 17:34:17 +00:00
william-andre d3f4ce1152 [IMP] core: allow set [value] in selection ondelete
In some cases we migh want to change to a value that isn't the default
one when uninstalling.
For instance: when we uninstall the module `event_sale`, a product has
the field `detailed_type` set to `event`, which is a subtype of `service`.
So we want to update the value to `service` when uninstalling instead of
the default value, which would be `consu` and wouldn't make any sense.

Part-of: odoo/odoo#77876
2021-10-11 10:15:48 +00:00
Adrian Torres bbee0b3081 [FIX] base: allow setting group_expand for ir.model.fields
PR #75856 introduced a default implementation of group_expand for
Selection fields that set the value of group_expand to True.

However the PR lacked the necessary bits that allow the same behavior
for fields created on the fly instead of through code.

This commit allows the propagation of the group_expand attribute for
fields of type Selection, this commit also exposes the checkbox in the
UI to enable/disable the setting.

closes odoo/odoo#76775

X-original-commit: 1cacc3e53cf722a31bedff7a76f8e5cc6ed45ce0
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-09-18 17:00:52 +00:00
Raphael Collet 765ec7837c [REF] core: add methods flush() and clear() on cursor
This deprecates the ugly and inconvenient functions flush_env(),
clear_env(), and avoids explicit calls to precommit.run().

Part-of: odoo/odoo#75598
2021-09-03 15:45:46 +00:00
Adrian TorresandRaphael Collet d543f53c33 [FIX] base: avoid recursion depth errors during uninstall
For some reason _logger.info with exc_info=True inside a recursive
function generates RecursionErrors, presumably because the logger uses
recursion itself to generate the stack trace that is logged.

A simple solution would be to remove exc_info=True, but I've decided to
move the log out of the delete function and simply call it once per
uninstall process with all undeletable IDs, so it's kind of a fix +
optimization.

closes odoo/odoo#75445

X-original-commit: 3a04de569bca10a1d1a01f719635de6842e747b2
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
2021-08-23 10:51:57 +00:00
Martin Trigaux 9aedb999f5 [IMP] *: remove xmlid_to_object helper
Use env.ref instead of the xmlid_to_object
To make it more readable and be able to clean old helpers
2021-08-10 14:24:11 +02:00
Martin Trigaux fd67339a3e [IMP] base: remove get_object helper
Not used anywhere, similar to env.ref
2021-08-10 13:49:05 +02:00
Martin Trigaux 15692f3948 [IMP] *: merge ir.model.data helpers
remove _get_id and _get_object_reference that were one liner to
_xmlid_lookup
2021-08-10 13:49:05 +02:00
Martin Trigaux c7bac3dee0 [IMP] *: make ir.model.data helper private
No reason to interfact with them directly in RPC
2021-08-10 13:49:04 +02:00
Adrian TorresandRaphael Collet 4f5b2dc550 [FIX] base: perform sanity check on undeletable ir.model.data
This commit adds a sanity check to the part of the ORM that uninstalls
module data, as a recap, here's how module uninstallation works:

- We fetch all data (ir.model.data) that corresponds to the module being
uninstalled (`WHERE module='my_module'`)
- We divide this data according to its type (ir.model, ir.model.field,
constraints, etc.)
- We fetch the corresponding records to each type, we delete them in a
certain order (e.g. ir.model.field before ir.model) and then finally we
delete the ir.model.data as a last step

The data is deleted in batch for maximum performance, if one of the data
cannot be deleted however, we perform a binary search until we find the
culprit(s) and we store these culprits in a list of undeletable_ids.

At the end of the process, we delete all ir.model.data **except** for
the ones that are undeletable, however, it is possible that because of
the multiple-step procedure, an undeletable ir.model.data could have
become deletable.

Imagine that an ir.model.field cannot be deleted, its module data id is
added to the list of undeletable_ids, however if later on its ir.model
is deleted successfully, the ir.model.field is dropped because its table
is dropped, in this case the ir.model.data becomes deletable, but since
we simply ignore it at the end of the process, we potentially end up
with orphaned xmlids.

This can be problematic when we reinstall the module and uninstall it
again, as the system does not expect an orphaned xmlid, will completely
crash and prevent the 2nd uninstallation of the module.

This is the case with CRM and its
crm.lead.scoring.frequency.field.field_id field, its ir.model.field
cannot be deleted because the name field (and display_name) of the same
model depend on it, so it is left as is, then further down the process
the entire model is deleted and as a result so is all of its remaining
fields, however the ir.module.data for the field that could not be
deleted remains.

opw-2575592

closes odoo/odoo#73668

X-original-commit: 75697934b34df882ec03595b876a8a6dadcef4c5
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
2021-07-14 07:47:32 +00:00
Adrian Torres 5a04043546 [FIX] base: log Selection.ondelete ORM bypass at runbot level
This commit changes the warning log for Selection fields that states
that the hook could not go through the ORM for the deletion at uninstall
(because of some business error) and that it had to bypass the ORM (aka
pure sql delete) and turns it into a runbot-level log, meaning that it's
technically a warning but the runbot won't fail because of it.

This is done because for the install/uninstall tests it shows up as an
actual failure but it is not as it is non-blocking, and 99.9% of devs
won't ever see this warning on runbot since it triggers on module
uninstall anyway.

closes odoo/odoo#73332

X-original-commit: c140f545d150da05bd47f2c2dabc28c53cefe912
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
2021-07-06 16:17:23 +00:00
Alvaro Fuentes 23afd3642e [FIX] base/ir_model: fix materialized views columns listing
When there is a materialized view that has not been populated any select
on it will fail.

Example of traceback:
```
Traceback (most recent call last):
  File "/home/odoo/src/odoo/12.0/odoo/service/server.py", line 1162, in preload_registries
    registry = Registry.new(dbname, update_module=update_module)
  File "/home/odoo/src/odoo/12.0/odoo/modules/registry.py", line 86, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/home/odoo/src/odoo/12.0/odoo/modules/loading.py", line 367, in load_modules
    registry.setup_models(cr)
  File "/home/odoo/src/odoo/12.0/odoo/modules/registry.py", line 262, in setup_models
    env['ir.model']._add_manual_models()
  File "/home/odoo/src/odoo/12.0/odoo/addons/base/models/ir_model.py", line 321, in _add_manual_models
    cr.execute('SELECT * FROM %s LIMIT 0' % Model._table)
  File "/home/odoo/src/odoo/12.0/odoo/sql_db.py", line 148, in wrapper
    return f(self, *args, **kwargs)
  File "/home/odoo/src/odoo/12.0/odoo/sql_db.py", line 225, in execute
    res = self._obj.execute(query, params)
psycopg2.errors.ObjectNotInPrerequisiteState: materialized view "x_bi_sql_view_report_copy" has not been populated
HINT:  Use the REFRESH MATERIALIZED VIEW command.
```

Several upgrade requests have or had had this error which has been
solved with specific scripts.

Related to #40930

closes odoo/odoo#71008

X-original-commit: b208570ce8399bc6d3e4a8ba02eef6558e0a6ccc
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-05-18 18:51:19 +00:00
Raphael Collet 4fb958d086 [IMP] core: group all field_inverses dicts on registry
This makes the union of many dicts into a single dict.

On a registry with 296 modules, this saves 300 kilobytes of memory,
which is about 3% of the registry's memory footprint.
2021-05-10 14:29:43 +00:00
Raphael Collet 1abe965b59 [IMP] core: keep field.related as a string
This mainly keeps field.related's type consistent.

On a registry with 296 modules, this saves 325 kilobytes of memory,
which is about 3% of the registry's memory footprint.
2021-05-10 14:29:42 +00:00
Raphael Collet 386dfe81ca [FIX] core: removal of fields from triggers 2021-05-10 14:29:07 +00:00
Raphael Collet e5ded717f4 [IMP] core: clarify model definition and registry classes 2021-05-03 12:33:29 +00:00
Raphael Collet f7d5d11238 [IMP] core: do not add magic and inherited fields on abstract models
Magic and inherited fields are not really useful on abstract models.
The _inherits specification is used anyway by models that inherit from
those abstract models.

The main goal of this change is to prepare a refactoring of models where
fields are no longer duplicated on the registry classes, but fields
defined on classes are used directly.  But this new design cannot be
applied to all fields: a field being overridden simply cannot be used
directly.  This branch improves the situation by avoiding unnecessary
field overridings.

closes odoo/odoo#69372

Related: odoo/upgrade#2409
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-04-22 08:59:36 +00:00
Adrian Torres ab7b5af3e8 [FIX] base: properly execute Selection field ondelete actions
With this commit, 2 changes are made to the way that the
fields.Selection.ondelete cleanup action works:

1) We manually delete ir.model.fields.selection **before** the deletion
of ir.model.fields purposefully to **avoid** SQL CASCADE deletes, as we
do not know which selections are deleted in cascade and thus we cannot
perform the corresponding ondelete cleanup action (which is implemented
within the ORM).

2) In some actions, namely 'set default' and 'set null', we write a
"safe" value to the records containing the Selection being deleted,
before this commit this would go through the ORM (records.write()) but
this is problematic if there's a write override for the record's model
that raises an error for the field being written to. With this commit,
we first try to go through the ORM but if there's a failure (because of
the raise in a write override) then we will bypass the ORM and set it
with SQL.

opw-2451126

closes odoo/odoo#67616

X-original-commit: f5c7e861ee3ca0cdeb6c2f06d227ada07f923ed0
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
2021-03-11 06:45:42 +00:00
Adrian Torres 75243d5a43 [FIX] base: do not assign default ondelete policy for base fields
Previously, an ondelete policy would be assigned to any required
Selection fields, the default policy being 'set null'.

Base fields do **not** require an ondelete value, since if they are
deleted there is no "data fix" to apply because the field's column is
dropped, and in fact it's error-prone to do so because during
`_process_ondelete`, the system would attempt to set to null fields that
were required (i.e. NOT NULL).

This issue is hidden by the fact that ir.model.fields are usually
deleted **before** ir.model.fields.selection and thus the ondelete
action won't be applied on the field with the original definition
(because it has probably been deleted by SQL CASCADE)

X-original-commit: 2e238f1e0202d65a98177939dac166dd659bb39c
2021-03-10 16:45:06 +00:00
Raphael Collet f2d4ba6890 [FIX] core: imports with one2many lines with dangling external ids
Consider a model M with a one2many field with comodel L, such that
deleting records in M cascade-deletes records in L.  Import a bunch of
records in M with one2many lines having specific external ids.  Delete
the imported records: the database cascade-deletes the corresponding
lines, but the lines' external ids are not deleted.  Now re-import the
same records: this crashes, because the import process finds the lines'
external ids and tries to update the deleted lines!

The fix consists in checking that an external id's record actually
exists.  The existence check was removed for performance reasons by
https://github.com/odoo/odoo/pull/26496.  We reintroduce it by resolving
the external id with a join on the model's name, which checks the
record's existence faster than an extra query.  This patch allows to
re-create the imported records' lines.

Another patch is necessary to actually update the external ids that
refer to deleted records, otherwise they remain dangling, and importing
the same records again duplicates the lines, because their external ids
do not match any existing record.

OPW 2409649

closes odoo/odoo#63318

X-original-commit: 0322febbea2cfd2d2fd7aedc42ef03632b17c967
Related: odoo/enterprise#15285
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-12-14 11:29:21 +00:00
Wolfgang Taferner 25a6f79e4a [FIX] base: key error during uninstall of unavailable module
In case a user has installed a module where the code becomes unavailable or during migration a module was removed and needs to be removed after migration it is impossible to uninstall the module from a database still holding the fields or the models.
In order to disable prefetch based on information from the database it is needed that the module and models of the unavailable module are initialized with related fields and models.

closes odoo/odoo#62895

X-original-commit: e4a1121e572d07cc720ede8c1b1116d4f1d7ae98
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-12-04 14:06:32 +00:00
Adrian Torres 679185f3e8 [IMP] *: replace all raises inside unlink by api.ondelete
With this commit, all instances of errors being raised inside
`BaseModel.unlink` overrides are moved into methods decorated with
`api.ondelete` which is safer.
2020-12-04 09:16:16 +00:00
Julien Castiaux 90b52d144a [REF] base: Use Command helper for x2many
Task: 2366606
2020-11-30 10:16:09 +00:00
Adrian TorresandRaphael Collet 64b95a01d0 [FIX] base: do not prefetch fields to be uninstalled
During the uninstall step of the registry, we perform a commit right
after the uninstallation of all module data, this commit is performed
right before the creation of a new registry, this means that said commit
will call `flush_env` and thus `recompute` on an environment that is
based on a stale Registry (memory and database are unsynchronized).

This means that during this specific moment, there's a chance that the
recompute function may have to fetch some fields it depends on to
perform its computations if said fields are not in cache, this in turn
means that it will try to prefetch fields that are potentially no longer
in the database, making the registry crash and preventing the uninstall.

This is what happened with multiple if not all `payment_*` modules, the
main module `payment` depends on a `ir.module.module` record, most
notably the `color` field of the `payment.acquirer` model which depends
on the `state` field which in turn depends on the
`ir.module.module.state` field.

This meant that uninstalling a module such as `payment_paypal` triggered
a recompute of `payment.acquirer.color` during uninstall, and to perform
that computation we need several `payment.acquirer` fields to be fetched
from cache or the database. If in cache, the uninstall would go through
without a hitch, if not in cache, we would fetch the required fields
from the database but we'd also attempt to prefetch the fields
introduced by `payment_paypal` that had just been deleted from the
database!

To avoid this, the `_module_uninstall_data` method of `ir.model.data`
will henceforth guarantee that `ir.model.fields` that are to-be-deleted
will have their prefetch set to False, meaning only existing fields will
be fetched from the database during the uninstall of extending modules.

Fixes #60424
opw-2372598

closes odoo/odoo#62247

X-original-commit: 7bffd2df0d5d7eff841cdf7ba7cb6ea84a5c5c49
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
2020-11-24 13:42:25 +00:00
Raphael Collet 747ce6adcc [FIX] core: update of custom models in registry
When removing custom models from the registry, one also has to remove
indirect references to those model.  One such reference is the name of
the custom model in its parent models' `_inherit_children`.

Not removing that reference causes a crash when one of the parent models
is extended: the parent model will make its children models recompute
some of their attributes (see method `_build_model_attributes`).

closes odoo/odoo#62008

X-original-commit: 07404bf5e93878b26468e2944c69885bbc688e57
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-11-19 11:39:38 +00:00
Adrian Torres f4bd4f7b60 [FIX] base: allow custom fields to use time module
After commit 06a8c5264eb6e87c29ad1d23a14e12dd45aa281c it is no longer
possible to pass bare modules to `safe_eval`'s context, however during
the aforementioned commit only the wrapped datetime and dateutil modules
were updated in ir_model's SAFE_EVAL_BASE context, thus the bare `time`
module was still being passed (and this triggered a traceback whenever a
custom computed field that used the time module was computed).

The fix is simple: pass the wrapped time module to the `safe_eval`
context instead of the bare one.

This commit also introduces a regression test to verify that the passed
modules actually work in custom fields.

opw-2347711

closes odoo/odoo#59560

X-original-commit: 02e816877ec12471a1446ba894b5cfca309979da
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
2020-10-08 18:41:08 +00:00
Debauche StéphaneandXavier Morel 7ecb903bea [REM] *: ability to put raw modules in evaluation contexts
Co-authored-by: Xavier Morel <xmo@odoo.com>
2020-09-28 10:33:52 +02:00
Raphael ColletandFlorent de Labarre c500bb0484 [IMP] core: prevent deletion of a group with ACLs or record rules
This simply makes it less easy to screw up a database by preventing all
users to do their daily tasks.

closes odoo/odoo#57776

X-original-commit: 665a795fc1b199f4f17cc9f1257d1b36b6276e6f
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Co-authored-by: Florent de Labarre <florent.mirieu@gmail.com>
2020-09-15 16:39:25 +00:00
Xavier-Do b7cd70efc8 [IMP] core: remove _drop_table model not exist warning
This warning is unlikely to be triggered during an install, and is problematic
during an upgrade since upgrade scripts will already do the same check but are
able to manage exceptions. The log is kept in log 25 for debuging/monitoring.

closes odoo/odoo#57667

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-09-14 14:30:43 +00:00
Xavier-Do 7a97bde596 [IMP] base: remove duplicate warning
Upgrade scripts are now doing custom check on view/field/model unlink. This check
can be removed from odoo.

closes odoo/odoo#56657

Related: odoo/upgrade#1711
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2020-08-27 14:35:30 +00:00
Adrian Torres b532e65206 [FIX] base: properly handle orphan xmlids
Before this commit:
    * Add a field with studio to any view of module A
    * Note that the model has to be unique to module A
    * Uninstall module A
    * Try to uninstall the `studio_customizations` module
    -> MissingError, impossible to uninstall `studio_customizations`

This happens because when uninstalling module A, all `ir.model.fields`
for models of said module are deleted in cascade by PostgreSQL when
unlinking the module's `ir.model`, this means that the ORM has no way of
knowing exactly which `ir.model.fields` where deleted and which
corresponding `ir.model.data` should be deleted, so the `ir.model.data`
remain in the database as orphans (that can, and will be cleaned up
later).

However since #34435 the mechanic that avoids the removal of
LOG_ACCESS_COLUMNS performs field access on records that may not exist.

This commit solves this by simply making sure that all records exist
before performing any checks that may require field access (and thus can
trigger a MissingError if the record does not exist).

opw-2316973

closes odoo/odoo#56285

X-original-commit: 08e662823ccf7dbe4d497f3f487287cba285a852
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-08-21 11:10:50 +00:00
Raphael Collet 1f48130d2b [REF] core: _name_search() now returns a list of ids
This provides a better API to search for records by name without the
formatting part (`display_name`).

This also simplifies all the overridings of `_name_search` that no
longer need to call `name_get()`.  The call to `name_get()` is done in
method `name_search` in a generic way.
2020-08-18 13:02:41 +00:00
Xavier Morel ef709fd92b [IMP] core, base: avoid multiple xids when importing records w/ inherits
Before this change, we create an xid for every parent of a record
being imported, regardless of whether it already has an xid, or if
it's being created implicitly through the child.

This generates unnecessary extra xids on pre-existing objects
e.g. update 5 product variants -> the product gets 5 new xids despite
already having one.

We should *only* set a xid on parent records which are being
implicitly created by the creation of a child with a specified
xid. That is, we should never set a xid on the parent if it exists
before the child is created.

Update _process_end to try and see if "non-loaded" xids correspond to
an automatically generated "parent" xid: we're still setting a xid on
implicitly created records (if the child is created with a xid) so
they're properly removed if e.g. the module is uninstalled, but
because we're only doing so at creation these xids will not be visited
during update and _process_end will try to delete them.

A special case can be added to check that "unknown" parent xids don't
have children which _inherit them, in which case we want to protect them.

Task 2251039

closes odoo/odoo#53283

Related: odoo/enterprise#12023
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-07-27 06:32:59 +00:00
Xavier Morel 65b8751e32 [FIX] core: mis-updated SQL queries
odoo/odoo#53938 improved the SQL linter and used psycopg2.sql to
silence the linter where that still made sense. However I forgot to
mark table names (pretty much exclusively) as `sql.Identifier` in a
few somewhat rare callsites, which consequently break when invoked as
a simple string is not a Composable and psycopg2 therefore rejects it
when composing the query.

closes odoo/odoo#54556

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-07-16 09:10:03 +00:00
Jinal Patel 8d721f6728 [IMP] base: change unique model name sql constraint message
-Purpose of this task is to make the unique model name constraint
 clearer by specifing name of the model needs to be unique.

-In this commit, change the constraint message from
 'Each model must be unique!' to
 'Each model must have a unique name.' to let the user know name
 of the model causes the issue.

task-2254964
Closes-#51513

closes odoo/odoo#51513

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-05-19 09:08:36 +00:00
Xavier Morel e162e6f714 [FIX] test_lint, *: false negative in sql injection linter
The linter would miss / fail to warn on injection of *local variables*
in some cases.

Try to improve it to be stricter and more reliable, after discussion
with odo, sql which is "correctly" dynamic should use psycopg2's sql
package in order to bypass the linter (bonus: it should also properly
escape & quote identifiers).

closes odoo/odoo#53938

Related: odoo/enterprise#11718
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-07-10 07:12:35 +00:00
Christophe Simonis 85c3fd8b73 [FIX] core: do not mark ir.model* unique fields as modified
These field combinations [1] are actually secondary keys. They are
unique and represent the record identity.

Marking them as modified had a nasty side-effect: on some models, there
is a m2o to an ir.model and a stored related to ir.model/model that will
be recomputed at each model reflection. This can take some time on big
tables.
Moreover, some other stored fields may depend on those ir.model/model
related store, which adds useless time lost at recomputing unchanged
values.

[1] ir.model/model, ir.model.fields/{model,name} and
    ir.model.selection/{field_id,name}

closes odoo/odoo#54126

X-original-commit: db013a01ca4e10640ac33a59466c9cb5746e3698
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Signed-off-by: Christophe Simonis <chs@odoo.com>
2020-07-06 11:11:05 +00:00
Martin Trigaux 400cc4f14e [FIX] *: correct all or improve code translation lookup
This commit fixes all issues detected by the new pylint
gettext-variable test.
It converts some calls to the new syntax
  _("Foo %s", bar)

to progressively migrate the code to the new syntax.

A few calls were not technically incorrect but still detected by the
linter.

  _("Foo" +
    "Bar")

has been converted to

  _("Foo"
    "Bar")

as it has the same effect and make sure the argument is of type
asteroid.Const instead of BinOp).

closes odoo/odoo#53683

Related: odoo/enterprise#11467
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-06-30 10:19:59 +00:00
Sébastien Geelen (sge) 6d93c72564 [IMP] base : improve messages text in access_error pop-ups
* Improve layout of access error messages from group restriction
 * Improve layout of access error messages from security records rules
 * Use the error title in the js crash manager when possible
 * adapt unit tests

closes odoo/odoo#50369

Taskid: 2206787
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2020-06-30 13:59:23 +00:00
Julien Castiaux 5d5a3d7fa4 [FIX] base: missing xmlid for mixin fields
We want to create a XMLID for every first exhibition of a field in a
model. That is, we just want one XMLID by field by model and not one
XMLID by field by class. Previous implementation was determining the
"first field exhibition" by making sure the field was created and used
as part of the same module.

This assumption is invalid when we consider mixins. A mixin is an
abstract model that define fields and methods to be included in other
models. As it is abstract, it does not exhibits the field by itself. The
field will only be exhibited when included in a concrete model via
inheritance. When it is included in another module, the XMLID creation
is discarded.

Take a module M1 that defines a model A, take another module M2 that
defines a mixin X with a field X1. In a third module M3, extend A to
inherit from X. While M3.A is the first model module to exhibit the
field X1, the XMLID creation was discarded because `"M2" != "M3"`.

See https://github.com/odoo/odoo/issues/49354#issuecomment-614093767

Task: 2235368
Closes #49354

closes odoo/odoo#53435

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-06-22 16:05:56 +00:00
Martin Trigaux ba244cef01 [IMP] *: replace to new _() syntax
Using a few regex like
\((_\(.*%s.*)(\) % )([\w\[\]][\w .\[\]\(\)'"]*)\)
($1, $3))

Old syntax is still compatible but starts the migration to the new
syntax that catches error.
2020-06-18 13:03:34 +02:00
fja-odoo 061ff011df [IMP] base, website: fix prewebsite specific views
Things to know about specific views:

Since the introduction of website specific views, we can have multiple
views that are related to a website (specific views). These views have
no xml_id as it is only set on the original view (generic view).
We rely on the view's key to identify related views as it is the same
for all specific views of a generic view. Also the key is equals to the
xml_id.

When a generic view is updated, we will check if the specific views have
the same values as the generic view. If it is the case, the value that
are the same are considered updatable and are updated on both the
generic and specific view. Else these are considered as noupdate.

When a generic view is created we will check if the potential parent
generic view has specific views. If it is the case we will create a copy
of the created view for each specific view.

The issue:

The method that checks if a created/updated view has specific views is
located in website. When we update a module, each modules are
initialized and updated in a specific order. If a generic view that has
specific views located in a module loaded before website this view's
specific views will not be updated/created as the method does not exist.
This issue is mainly affecting portal views at the moment.

The solution:

For write:
We now COW(copy on write) the views in base module, meaning this will
apply to all qweb views that are duplicated and not only the website
specific ones.

For create:
We  will create the generic view as before but wait until we have
updated all the modules to gather all generic views that are supposed
to have a specific view but don't and create the specific views.
This will result in a change of behavior being that if a specific view
that have a parent is deleted it will be recreated on update
(same behavior as a generic view).

closes odoo/odoo#52629

X-original-commit: b1a90ee2bb441aa52e3cf4607c43fb464b55b1d7
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Signed-off-by: fja-odoo <fja-odoo@users.noreply.github.com>
2020-06-08 17:23:59 +00:00
Xavier Morel 148f3dabc9 [IMP] base: make ir.model.data use access fields
Apparently some "core objects" used to have a pair of
fields (date_init, date_update) which predate the current access
fields (hopefully anyway, the genesis of both is lost to time so we
can only speculate).

odoo/odoo#34988 removed them on constrains & relations and left them
on ir.model.data, but they do seem redundant with the regular access
fields which *are* enabled on ir.model.data.

* removes the date_init/date_update fields
* converts the one bit of code which did set those to set
  create_date/write_date
* add a default value on the columns, to ensure create_date is
  properly set even from SQL queries
* use create_date/write_date in the view
* adds setting those columns to a bunch of raw SQL queries which were
  missing them (also updates the queries some to merge the literal
  values into the queries as it seems unnecessary to interpolate
  e.g. a boolean literal)

Builds on and closes odoo/odoo#50516 as that's why I started looking
into it, and that fix is in this branch as well.

closes odoo/odoo#50661

Related: odoo/upgrade#1213
Related: odoo/enterprise#10772
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-05-27 06:16:01 +00:00
Anh Thao Pham (pta) dbd87ec464 [FIX] base: fix import of studio customizations
- Activate Studio from dashboard of database A
- Export studio customizations
- Activate Studio from dashboard of database B
- Import studio customizations previously exported
The imported data don't have the boolean studio field set to True.

Since v12, when loading a module, a query is executed to create or update XML ids.
The create and write methods are not called anymore.
Therefore the overridden create and write methods of "ir.model.data" defined in Studio module
are not called and thus cannot set the studio field to True.

The generation of the query creating XML ids has been moved to a private method
allowing another module like Studio to override it.

opw-2245578

closes odoo/odoo#51203

X-original-commit: 198ab837e466f3155ea1c3b35811b981b1c1e537
Related: odoo/enterprise#10586
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
2020-05-13 16:36:59 +00:00
Adrian Torres bdd87051f6 [FIX] base: allow removal of selection fields during dev
Let field F of model M be a Selection field.

Before this commit, creating a database with field F, removing/renaming
field F by changing its definition within the code then upgrading the
database to reflect the changes would result in a registry crash because
the field would still exist in the database but not in the ORM (memory),
thus trying to fetch the field in DB from the memory would result in a
KeyError.

This is due to the fact that field renames / removals are not stable
operations and should be handled with a migration script when upgrading
an existing database, nevertheless this can be quite an annoying
behavior while developing which is why this commit simply skips the
processing of the field if it does not exist in memory.

The ORM already foresees these cases and logs a warning to the developer
saying that the field was deleted anyway but that it was only a
partial delete and that it should be handled in a migration script in
order for the change to be production ready.

closes odoo/odoo#51099

X-original-commit: a54fecc35386f8e00018ff3d858b383d43f1dded
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
2020-05-12 12:24:46 +00:00
Nasreddin (bon) 04ecbe08b9 [IMP] base: Warning on m2o required field with ondelete set to 'Set NULL'
Since a required field can not be empty: a warning message will
be thrown if a many2one required field has the "on_delete"
attribute set to "Set NULL".

Task ID 2250533

closes odoo/odoo#50751

X-original-commit: 084555c6395b484a85ec9d386fbc8afc8aec1f8c
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
2020-05-06 11:59:31 +00:00