Commit Graph

193 Commits

Author SHA1 Message Date
Denis Ledoux 03ec39d36b [FIX] models: custom models must add the table/column in database
This revision is related to 1b8c9aed9f

As `manual` is now the default value of the `state`,
if `state` is not given in the values when passed to
`create` or `write` of `ir.model` and `ir.model.fields`,
we must assume the value is `manual`, so the columns and tables
are instanciated in database

opw-657750
2015-11-27 13:58:28 +01:00
Denis Ledoux 1b8c9aed9f [FIX] models: custom fields seen as base fields
This was possible to create custom fields `x_*`
but seen as base fields.

For instance,
 - Go to Settings > Technical > Database Structure > Fields
 - Select a field (any)
 - Click on the model link, to be redirected to the model form
 - Edit & add a custom field from there.
 - Save
 - Notice that the field you just added is saved as a base field.

We solve this issue by assuming that all created fields and models
are customs, except the ones created by the ORM, by the database
initialization, the fields coming from the modules in python.

We therefore remove the mechanism on which a field was set
as custom according to the fact `manual` was set to True within
the context: This is now the case by default.

No change was required for the base fields: The `state` `base`
was already forced for those fields, that are created using
direct SQL requests `INSERT INTO`.

opw-657312
2015-11-26 15:44:29 +01:00
Raphael Collet cca7a7a051 [FIX] ir_model_fields: fix and simplify update on custom fields
Avoid "patching" the registry, as this introduces inconsistencies (some field
attributes are lost).  Instead, proceed as follows:
 - update the definition of custom fields in database;
 - clear the corresponding cache on the registry (this was missing);
 - setup the models in registry (this reloads the custom models and fields);
 - update the database schema of the models based on the registry.

This makes the update of custom fields simpler and more robust.
2015-10-01 15:26:07 +02:00
Christophe Simonis 94aae97c04 [MERGE] forward port of branch saas-3 up to e2bfb96 2015-05-08 18:52:57 +02:00
Christophe Simonis e2bfb969ed [MERGE] forward port of branch 7.0 up to 6e23b2a 2015-05-08 18:10:30 +02:00
Olivier Dony 6e23b2a807 [FIX] ir.model.data._update: create/modify XML IDs as super-user
When importing a CSV file with an "id" column containing
external IDs (XML IDs), the system automatically creates
or updates the corresponding ir.model.data entries.
This would fail for regular users who do not have
create/write access on this internal model.
2015-05-08 10:25:44 +02:00
Raphael Collet c58121e8f1 [FIX] method `ir_model.check` now decorated with `ormcache_context`
The method needs the `context` parameter to translate the error message in case
the access is denied and an exception is raised.
2015-03-26 17:14:42 +01:00
Raphael Collet 0beb14f0d2 [FIX] ormcache: fix calls to `ormcache` with unexpected context parameter
The implementation of `ormcache` does not work on methods that take a `context`
parameter.  Because of the decorator `decorator`, the arguments of the call are
passed positionally to the method `ormcache.lookup`, and positional arguments
are used in the cache key.

The fix consists in removing the `context` parameter from the faulty methods,
either directly, or by caching a private method called by the public method.
2015-03-26 16:42:10 +01:00
Olivier Dony d93148240b [FIX] ir.model.data: update_dummy should mark `inherits` parents too
When a `noupdate` record is processed during an update,
the update_dummy method marks the record as "seen" so
it won't be deleted at the garbage collection step,
and seen as an obsolete external ID.

This needs to be done also for the parent records via
_inherits, because they have also received an implicit
external ID at creation, and must not be garbage
collected, even if their `noupdate` flag (db side)
is not set because the flag was added later.

This rare problem could be reproduced by creating a product
in a module, then referencing it in e.g. a sales order,
then updating the module after changing the product
record to be in a `noupdate` block.
At the end of the update the implicit product.template
record would be garbage collected, and trigger a cascade
deletion of its children - blocked by the SO reference
to the product.
2015-03-18 14:10:18 +01:00
Raphael Collet e182da22f4 [FIX] base/ir_model: upon custom field creation, always clear manual fields in registry
The invalidation in registry was done only if the field's model was already in
registry.  This situation is not the case when you create a custom model with a
custom field.
2015-03-17 11:51:22 +01:00
Christophe Simonis bfb877a671 [FIX] ir.model.data: cleanup _process_end()
Allow deletion of ir.model and ir.model.fields when updating modules
Log xml id of deleted records
Remove xml id of non-existing records
2015-02-19 14:01:49 +01:00
Olivier Dony 740bf28907 [FIX] ir.model.data: verify record exists in _update_dummy
When a stale XML ID exists in the database, `_update_dummy()`
must consider it as missing entirely, and the next call
to `_update()` will take care of cleaning up the old XML ID.

Failing to do so for `noupdate` records means the `_update`
will never happen, and as soon as another record is created
or updated with a relationship to that stale XML ID, it will
plainly crash the installation/update.
2015-01-24 00:15:26 +01:00
Raphael Collet cf26f7ed80 [IMP] models, registry: let the registry retrieve manual fields from database 2015-01-21 11:26:23 +01:00
Raphael Collet 8f38a7806a [IMP] enable loading custom models/fields and views from module data files
Loading views for custom models from module data files was not possible because
custom models and fields were introduced into the registry after all modules
were loaded.  As a consequence, the view architecture did not pass the checks.

This patch takes a different approach: custom models and fields are loaded
early on in the registry, so that views can be validated.  The trick is to take
special care of relational custom fields: we skip them if their comodel does
not appear in the registry.  This allows to install and upgrade modules that
create/modify custom models, fields and views for them.
2014-12-19 13:57:08 +01:00
Samus CTO 55fa50891d [FIX] Use _unknown model for missing models in relation fields
During a migration of database, it is possible that some custom field
("x_", state is 'manual') are relational to model from a module that is
not provided.

Note: this used to work in Odoo 7.0 but crashed in 8.0.

Closes #3877
2014-12-04 20:58:46 +01:00
Raphael Collet 2052c16d21 [FIX] ir_model: on a custom model, _rec_name should be 'x_name' if it exists 2014-11-17 12:05:37 +01:00
Raphael Collet 3c203703db [FIX] ir_model: always setup models before calling _auto_init() 2014-11-13 14:54:04 +01:00
Raphael Collet 3adbb49ec0 [FIX] ir_model: fix create/update/delete custom fields
Creating custom fields would crash on a model that has a related field without
string.  The crash was caused by the field not being set up, and method
BaseModel._field_create() violating a non-null constraint on the field string.
This has been fixed by setting up fields before updating ir_model_fields.

Deleting a custom field could also cause trouble when that field is inherited
in a child model.  In that case, the registry was simply no longer consistent.
The fix is to reload completely the registry.

The modification of custom fields was not reflected on field objects.  The fix
applies changes on fields before updating columns accordingly.
2014-11-04 14:52:13 +01:00
Xavier Morel 4d2b24adcb [ADD] Stripe-style APIDoc: content 2014-10-27 17:23:16 +01:00
Denis Ledoux 1c6c289f7b [FIX] api: clear environments on module installation 2014-10-02 17:46:25 +02:00
Raphael Collet 24f26c0eeb [FIX] ir_models: fix registry when we add/remove/modify a custom model/field 2014-09-24 15:30:37 +02:00
Martin Trigaux f0c3856be2 [IMP] gamification: allow to select fields of inherited models 2014-09-18 11:12:15 +02:00
Martin Trigaux 423a9f3011 [ADD] base: list of inherited models on a ir.model
This field is needed to retrieve the list of inherited fields (instead of only the fields of a current model) of a model using domain such as ('model_id', 'in', model.inherited_model_ids) on ir.model.fields
2014-09-18 11:12:15 +02:00
Denis Ledoux 51e7e03502 [MERGE] forward port of branch saas-5 up to 163d7f5 2014-09-15 14:25:02 +02:00
Olivier Dony ddc78626e1 [IMP] ir.model:.fields allow setting ondelete=restrict foncustom fields 2014-09-12 17:51:56 +02:00
Christophe Simonis ab6318e538 [FIX] base: ir.model.data.name_get() respect expected behavior.
name_get() must return a value for each ids and keep order of ids.
2014-09-09 13:28:47 +02:00
Yannick Vaucher bdfa970d3d fix typo on undeclared variable xml_id 2014-09-01 16:26:55 +02:00
Martin Trigaux 80d8532370 Forward port of branch saas-5 up to rev 4895281e 2014-08-22 09:12:14 +02:00
Martin Trigaux 7bcefaf232 Forward port of branch 7.0 up to 0ab88f5 2014-08-21 17:57:57 +02:00
Martin Trigaux 0ab88f54f9 [FIX] ir_model: invalidate cache when adding new fields
When a new ir.model.field is created, add the new field in the fields_by_model (cache of custom fields). This is required as the __init__ method would not retrieve the new field if fields_by_model is already set.
Otherwise, the _columns would not contain the new fields and we could not access it without restarting the server (e.g. the installation of a module adds ir.model.fields and use it in the a view.
2014-08-21 17:24:45 +02:00
Martin Trigaux 768b3592c2 [FIX] base: wrong model change check
Comparing an id and a browse record will always fail so the exception would have always been raised when changing a model (e.g. updating a module with custom fields).
2014-08-21 14:30:10 +02:00
Martin Trigaux f138aa2608 [FIX] models: display_name and name_get mismatch
- display_name uses name_get and not the other way around:
name_get should not call _compute_display_name, _compute_display_name should call name_get.
The previous behaviour was not backward-compatible with the old api.
All the models redefining name_get would have 2 different behaviors between name_get and display_name.

- Do not set an inverse function to display_name:
In most cases, writing on display_name writes on _rec_name (if any, not mandatory).
If the display_name computation is redefined, we need to redefine as well the inverse method to avoid unexpected behaviour
This required to also modify tests in base_import as readonly fields are avoided.

- Remove search method on display_name:
For the same reason as for the first point, it could be good that searching on display_name use name_search (and not the other way around).
However doing this would be very inefficiant (need to do the search, without limit, extract the ids of the name_get result just to generate
a subdomain ('id', 'in', [...]). As in most cases it would anyway mean to search on the _rec_name it's better to directly do so.

- Changing label to avoid mismatch:
In view displaying the list of fields or when a match is made on the label of a field (e.g. when importing csv file,
matching is made on both label and technical name), the fact that display_name field has '
Calling it 'Display Name' will avoid most errors.

- remove display_name definition from website_forum_doc,ir_model:
These fields are doing the same thing as the display_name of the new api, we can remove them.
We need to keep the one for res.partner as it's a stored field.
2014-07-25 13:58:59 +02:00
Xavier Morel b2ddda47e5 [FIX] missing part of initialization in ir.model and ir.model.fields 2014-07-15 08:56:58 +02:00
Christophe Simonis f654a7719b [MERGE] forward port of branch saas-5 up to 73d39a0 2014-07-10 22:49:53 +02:00
Christophe Simonis a35aec2a0b [MERGE] forward port of branch 7.0 up to 6e96ffd 2014-07-10 22:02:01 +02:00
Xavier Morel 19c7380951 [FIX] small potential encoding issue in custom models 2014-07-10 17:34:48 +02:00
Martin Trigaux 84e9a67cdf [FIX] orm: better removal of custom m2m fields
orm: do not try to create ir.model.relation for custom m2m as self._module is either empty (for custom models), either the one of the last inheriting module (which is wrong). The field should be removed manually and should not be impacted by the uninstallation of modules. The removal of the relation table can be done when removing manually the custom field (see rev 6af3193).

ir.model: when removing a model, drop the table with the CASCADE instruction. This will remove left constraints from remaining m2m tables.
This means that dropping a table (either manually removing a custom model or uninstalling a module) will not drop the relation table for a custom m2m field. This is not ideal but better than the previous behaviour (which was to fail the DROP TABLE instruction and keep the table with a few columns and unconsistent data).
2014-07-08 15:56:24 +02:00
Martin Trigaux 6af3193d17 [FIX] ir.model.fields: better unlink
When droping a column, remove also the relation table in case of custom m2m field.
The relation table needs to be dropped otherwise an unremovable constraint to the targetted table is kept (and anyway is not needed anymore).
2014-07-08 13:55:48 +02:00
Raphael Collet cbe2dbb672 [MERGE] new v8 api by rco
A squashed merge is required as the conversion of the apiculture branch from
bzr to git was not correctly done. The git history contains irrelevant blobs
and commits. This branch brings a lot of changes and fixes, too many to list
exhaustively.

- New orm api, objects are now used instead of ids
- Environements to encapsulates cr uid context while maintaining backward compatibility
- Field compute attribute is a new object oriented way to define function fields
- Shared browse record cache
- New onchange protocol
- Optional copy flag on fields
- Documentation update
- Dead code cleanup
- Lots of fixes
2014-07-06 17:05:41 +02:00
Jaydeep Barot 026e38b48f [REM] Unnecessary `size` parameters on char fields 2014-06-25 17:13:43 +02:00
Christophe Simonis 4601d85944 [MERGE] forward port of branch 7.0 up to 6fdb783 2014-06-10 11:49:14 +02:00
Martin Trigaux 426993e06d uninstall: avoid errors during uninstall
When uninstalling a module, remove the ir.model.constraint after removing the non-model records and before fields and model definition.
Without this fix, some constraint would be removed too early allowing to have broken relations and data left from removed module.
2014-06-05 12:52:11 +02:00
Christophe Simonis 38abc8a006 [MERGE] forward port of branch 7.0 up to revid b09b6a0 2014-05-20 18:57:04 +02:00
Martin Trigaux 07e4e15f4d [FIX] ir_model_fields: when adding a new custom column to a custom model, set a valid _rec_name to this model (otherwise would require a server restart to reinstanciate the model) 2014-05-15 16:25:51 +02:00
Denis Ledoux b882dd7109 [MERGE] Forward-port of latest 7.0 bugfixes, up to rev. 5294 revid:odo@openerp.com-20140505074636-bl2y5pst4pfmpz3u
bzr revid: dle@openerp.com-20140506121627-4oyw4zl4o6azy73w
2014-05-06 14:16:27 +02:00
Denis Ledoux 93ba7cc575 [FIX] base: ir.model.fields, write, use tools.ustr instead of str so it handle if the string is already unicode
Writing special chars in the field label resulted in a traceback (write only, no problem with creation)

bzr revid: dle@openerp.com-20140428110042-qeaswuwsquy1612h
2014-04-28 13:00:42 +02:00
Christophe Simonis c7d114d9a9 [MERGE] forward port of branch saas-2 up to revid 5020 chs@openerp.com-20140312174526-a5rhh83g0fw8djuc
bzr revid: chs@openerp.com-20140312180614-8yb454s3mkjwnk2q
2014-03-12 19:06:14 +01:00
Olivier Dony 07fbbe288c [MERGE] Forward-port of 7.0 bugfixes, up to rev. 5251 revision-id: odo@openerp.com-20140304152927-havybom9x1jgdzae
bzr revid: odo@openerp.com-20140305213115-w55dqs3xra6ejmni
2014-03-05 22:31:15 +01:00
Martin Trigaux b9f72dae74 [FIX] orm: do not drop low level columns (aka 'magic columns') when deleting ir.model.fields
lp bug: https://launchpad.net/bugs/1262150 fixed

bzr revid: mat@openerp.com-20140224161918-9pe1x3jeno8t82p1
2014-02-24 17:19:18 +01:00
Denis Ledoux 5fd307b921 [FIX] ir_model: Uninstall with orphan external ids of ir.model.fields
On uninstalling, if external ids are associated to an unexisting field, we do not try to delete the field (as it doesnt exist) and we remove the orphan external ids

bzr revid: dle@openerp.com-20140221104908-7ytdg6xkxaza05o4
2014-02-21 11:49:08 +01:00