Commit Graph
245 Commits
Author SHA1 Message Date
Raphael Collet ab33c7714c [REF] fields: reimplement field.setup_triggers
The purpose of this reimplementation is to separate the resolution of
dependencies from the creation of the invalidation/recomputation triggers.
2016-08-01 16:39:49 +02:00
Raphael Collet 629e175501 [FIX] fields: enable setting attribute group_operator to None 2016-07-06 16:18:04 +02:00
Raphael Collet 5560ac4a04 [FIX] models: generalize the protection mechanism to not recompute some fields
The protection prevents fields to be invalidated/recomputed on some records.
This mechanism is useful against accidental cache invalidation when computing
or inversing fields.  It also prevents to trigger the recomputation of fields
before and/or after their inversion.

Add a test on stored field with compute and inverse methods: the test checks
how many times the compute and inverse methods are invoked in several cases.
Essentially, the field should not be recomputed when it is written.
2016-07-01 10:49:27 +02:00
Olivier Dony 2fb0784d64 [IMP] base: simplify code from b3feb2358c 2016-06-30 20:08:35 +02:00
xmo-odoo b3feb2358c [IMP] allow group_operator on any field
There's really no reason to limit group_operator to numeric fields and Postgres's flexible aggregate make the ability to aggregate on non-numeric fields (and/or non-numerically)

* moves group_operator to Field
* adds a default value of `sum` on integer, float and monetary fields
* in read_group, filters on fields with a group operator rather than by
  type (also allow id fields, since Id doesn't have a group_operator by
  default it will be ignored anyway) (sequence is still specifically
  excluded for now because they're usually regular Integer fields)

Closes #12372
2016-06-29 17:52:30 +02:00
Raphael Collet 1ba91042d6 [FIX] fields: do not serialize more digits than necessary in monetary._symbol_set()
Add a class for float objects that carry their precision digits, use it for the
value of monetary fields in record cache, and serialize them as expected for
the database.
2016-06-23 10:08:57 +02:00
Christophe Simonis da53a27a5d [MERGE] forward port of branch saas-11 up to c88c70e 2016-06-21 16:24:38 +02:00
Christophe Simonis c88c70e900 [MERGE] forward port of branch saas-10 up to d73f0d8 2016-06-21 13:58:24 +02:00
Christophe Simonis d73f0d8063 [MERGE] forward port of branch saas-9 up to 68f5163 2016-06-21 12:42:34 +02:00
Christophe Simonis e37ba61832 [MERGE] forward port of branch saas-6 up to b87a93a 2016-06-20 14:20:03 +02:00
Christophe Simonis b87a93a091 [MERGE] forward port of branch 8.0 up to 5b1beec 2016-06-20 13:34:46 +02:00
Xavier ALT f02b23006b [FIX] fields: during an onchange(), do not invalidate *2many fields because of their domain
Our usage of domain on fields One2many seems to trigger an obscure behaviour on
onchange.

With the following (simplified) config:

    Message(models.Model):
        _name = 'test_new_api.message'
        important = fields.Boolean('Important')

    Discussion(models.Model):
        _name = 'test_new_api.discussion'
        name = fields.Char('Name')
        important_emails = fields.One2Many('test_new_api.emailmessage', 'discussion',
                                           domain=[('important', '=', True)])

    Email(models.Model):
        _name = 'test_new_api.emailmessage'
        _inherits = {'test_new_api.message': 'message'}

        discussion = fields.Many2one('test_new_api.discussion', 'Discussion')
        message = fields.Many2one('test_new_api.message', 'Message')

Steps:
- We change 'name' on discussion, triggers an `onchange()` call
- we ends up filling cache on virtual record (on secondary fields, we calling
  record.mapped('important_emails.important'))
- we get a cache miss ('important' field not provided, only 'important_emails' ids,
  i.e with no change on existing records)
- we fill the cache, this mark 'important' field as modified
- because of commit 5676d81 and because 'important' is that case is a related (i.e
  computed) field we triggers cache recomputation
- as there is no way to recompute 'important_emails' for virtual record (no real
  ID) we ends up with empty 'important_emails' generating removal of existing records.

=> Finally changing any value for 'test_new_api.discussion' that trigger an onchange
will always reset 'important_emails' to empty

Fixed by Raphael Collet <rco@odoo.com>, and test by Xavier Alt <xal@odoo.com>.
2016-06-17 17:50:25 +02:00
Christophe Simonis ca2dad4c44 [MERGE] forward port of branch 8.0 up to b9a006c 2016-06-06 15:41:50 +02:00
Denis Ledoux 950fd97d06 [FIX] fields: translations of the help of inherited fields
This is similar to revision 54140331f3

opw-673716
2016-06-06 11:44:34 +02:00
Christophe Simonis 2356c2015f [MERGE] forward port of branch saas-11 up to 3509217 2016-05-13 18:50:44 +02:00
Christophe Simonis 35092174c1 [MERGE] forward port of branch saas-10 up to bfb272c 2016-05-13 18:38:35 +02:00
Christophe Simonis bfb272c61e [MERGE] forward port of branch saas-9 up to da8a312 2016-05-13 17:42:34 +02:00
Christophe Simonis 820f7e11c1 [FIX] core: correct fields.modified_draft for triggers on other models 2016-05-13 17:32:00 +02:00
Christophe Simonis 1e26ef6579 [MERGE] forward port of branch saas-11 up to 91c9284 2016-05-13 16:36:04 +02:00
Christophe Simonis 91c9284951 [MERGE] forward port of branch saas-10 up to 5aa0bae 2016-05-13 16:33:51 +02:00
Christophe Simonis c4bba868f0 [MERGE] forward port of branch saas-9 up to 087729f 2016-05-13 15:58:06 +02:00
Christophe Simonis 7e999ece01 [MERGE] forward port of branch saas-6 up to 19a77d9 2016-05-12 18:20:08 +02:00
Christophe Simonis 2f374c4cba [MERGE] forward port of branch 8.0 up to 3a32021 2016-05-12 12:38:02 +02:00
Raphael Collet de54107fec [FIX] fields: add property auto_join on many2many fields
This makes this property available on all relational fields, although the
feature is currently not implemented on many2many fields.
2016-05-11 11:40:24 +02:00
Raphael Collet 5676d8121d [FIX] fields: invalidate x2many fields with a domain
Invalidate the cache of a x2many field when any of the fields appearing in its
domain is modified.  Use the invalidation triggers mechanism for that purpose.
2016-05-09 12:10:23 +02:00
Christophe Simonis 0fbc92e0c4 [MERGE] forward port of branch saas-10 up to 1e86774 2016-05-04 17:09:51 +02:00
Christophe Simonis 1e86774207 [MERGE] forward port of branch saas-9 up to 89873cb 2016-05-04 15:42:26 +02:00
Christophe Simonis db935df398 [MERGE] forward port of branch saas-6 up to e2faeab 2016-05-02 14:11:40 +02:00
Christophe Simonis 396facfaf0 [MERGE] forward port of branch 8.0 up to 8651d08 2016-05-02 11:04:21 +02:00
Raphael Collet 233c7780e6 [FIX] fields: filter result of 2many related fields with related_sudo
When traversing relational fields as superuser, you end up with a recordset for
which only a subset is accessible to the current user.  An earlier fix to this
issue completely dropped the `related_sudo` feature; change its implementation
to keep the feature.
2016-04-28 11:46:44 +02:00
Raphael Collet 7a8a8097f6 [IMP] fields: change the cache format of relational fields
Relational fields are now cached as tuples of ids instead of recordsets.
2016-04-25 13:37:12 +02:00
Raphael Collet 1ec7b28a09 [FIX] models, fields, api: do not mix the cache format with the record format 2016-04-25 13:37:11 +02:00
Raphael Collet d035828778 [FIX] models, fields: make read add secondary records for prefetching
Make the following statements add secondary records (values of relational fields)
in the prefetching object of ``self``:

    self.read(fields)
    self.partner_id             # implicitly invokes read()

This makes sure that traversing relational fields on records automatically
feeds the prefetching of secondary records.
2016-04-25 13:37:11 +02:00
Raphael Collet f9b08f09b2 [IMP] models: make with_env, sudo, with_context preserve the prefetch object 2016-04-25 13:37:11 +02:00
Raphael Collet 8bc7d8565c [IMP] models: attach prefetching data to recordsets instead of environments
The prefetching now has a more intuitive and controllable model: every
recordset is linked to a "prefetch object" that tells which record ids to
prefetch for any model.  The prefetch object of a given recordset is shared
with the records obtained by iteration and relational field access.  All other
operations instantiate recordsets with a fresh prefetch object.

    records = model.browse(ids)
    assert records._prefetch is not model._prefetch

    for record in records:
        assert record._prefetch is records._prefetch
        assert record.relation._prefetch is record._prefetch
2016-04-25 13:37:11 +02:00
Raphael Collet 6037f3a56d [REF] fields: change API and semantics of converter methods
The cache data format has been split between a cache format and a record format
(returned by accessing a field on a record).  We have the following converters:

                                   ANY FORMAT
                                       |
                                       | convert_to_cache
                                       v
                                  CACHE FORMAT
                                       |
                                       | convert_to_record
                                       v
                                 RECORD FORMAT
                                       |
                                       | convert_to_read
                                       | convert_to_write
                                       | convert_to_onchange
                                       | convert_to_export
                                       | convert_to_display_name
                                       v
                                 OTHER FORMATS

Modify the API of the converter methods to make them uniform (pass value and
record), and adapt their documentation.
2016-04-25 13:37:11 +02:00
Raphael Collet cb8d432bb2 [IMP] fields: do not validate values when not necessary 2016-04-25 13:37:10 +02:00
Raphael Collet d3cfb47285 [IMP] fields: simple code improvements (add blank lines, remove unused imports) 2016-04-25 13:37:10 +02:00
Christophe Simonis ddb0fb2739 [MERGE] forward port of branch saas-9 up to 59d3f63 2016-03-24 16:53:45 +01:00
Raphael Collet ce217acf18 [FIX] fields: *2many convert_to_cache for new records
When interpreting commands, the initial value for new records is an empty list.
This regression was introduced by 0939738479.

Fixes #11239.
2016-03-15 10:40:38 +01:00
Raphael Collet a4ea258176 [FIX] fields: company-dependent (property) fields should not be stored or copied 2016-03-03 16:47:05 +01:00
Thibault Delavallée fd25fd4d44 [FIX] fields: do not strip class by default
Do not strip class by default on html fields, this was an error. Currently
only mail_message body field should not contain classes. Indeed as external
content can be stored through the mail gateway we do not want to keep the
classes.
2016-03-02 16:43:04 +01:00
Thibault Delavallée c9e38cae9f [FIX] fields: html: strip_style / strip_classes
Added the support of strip_classes, like the already existing strip_style
parameter of html fields.. This parameter is missing but allow full
customization of html fields.

Also fixed the call to the sanitizer in fields. Indeed the strict mode is
set to False. When not in strict mode the classes are never stripped whatever
the value of strip_classes.

Sanitizer is now called always in strict mode to ensure the sanitize process
is correct and really take into account strip_style and strip_classes.

This fix is done in master due to possible side effects and possible behavior
changes that are not welcomed in stable versions.
2016-03-02 14:31:39 +01:00
Christophe Simonis 9a805c90ed [MERGE] forward port of branch saas-9 up to d70fde0 2016-02-10 18:40:56 +01:00
Denis Ledoux 04b2d910ac [MERGE] forward port of branch saas-6 up to fead627 2016-02-08 13:39:28 +01:00
Denis Ledoux fead627dd5 [MERGE] forward port of branch 8.0 up to 3ff4dae 2016-02-08 13:31:27 +01:00
Raphael Collet 408330a655 [FIX] fields: track correctly which module introduced a given field
If a module adds a field on a given model, deinstalling that module must remove
the field from all the models that inherited the given field.
2016-02-04 15:52:06 +01:00
Raphael Collet 58292bf311 [FIX] fields: in _setup_default, do not lookup _default in model classes 2016-02-04 15:52:06 +01:00
Raphael Collet 8a7552e5b7 [FIX] models: exclude magic, custom and inherited fields from a model's proper fields
Those cases can now appear, since a model inheriting (with `_inherit`) from
another model can observe those extra fields from its parent model's class.
2016-02-04 15:52:05 +01:00
Raphael Collet a3ec5a35a5 [FIX] fields: in copy_cache, add single records to set todo 2016-02-04 14:33:53 +01:00