Commit Graph
380 Commits
Author SHA1 Message Date
Raphael Collet 22b0142d4e [IMP] core: delegate fields should be auto_join=True
The field that supports inheritance should be auto_join=True.  This
guarantees that searching on an inherited field (X) or its explicit
related expression (foo_id.X) gives the same query.

Note that adding auto_join=True on that field does not weakens the
model's security, since searching on the model automatically injects the
parent model's security rules into the query (see _apply_ir_rules).

closes odoo/odoo#66925

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-03-01 08:28:48 +00:00
Raphael Collet b652d84cd1 [FIX] core: convert_to_write() of x2many field with new records
When comparing the values of a new record with its origin, x2many fields
are always different because we compare new records with real records.
For instance, converting the value of a one2many field where lines have
a many2many field always returns update commands for the many2many
field.

closes odoo/odoo#66950

X-original-commit: 03a4137cc3fa398dbd0cb214dc5472a083ae33b8
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-02-26 16:32:16 +00:00
Raphael Collet e6369c2535 [IMP] core: write x2many fields last
Writing on x2many field should be done last, because deleting x2many
lines causes pending computations and updates to be flushed.  Writing on
column fields after that inevitably adds extra update queries.

We introduce an attribute `write_sequence` on fields to order fields for
write.  The prescribed order is: all fields except monetary and x2many,
monetary fields, x2many fields.

closes odoo/odoo#65959

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-02-22 16:20:55 +00:00
luz paz c9e29e5917 [FIX] *: correct typos
Various user facing an non-user-facing typos
Found via `codespell`

Closes odoo/odoo#65648

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2021-02-19 13:20:48 +00:00
Raphael Collet be100b8b6c [FIX] core: flush domain before searching for records in many2many field
This guarantees the cache consistency of the many2many field values.

closes odoo/odoo#66299

X-original-commit: 421631d7f222f1fcc3381c79320e109562533f22
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-02-16 17:38:11 +00:00
Raphael Collet 2f93046cf7 [FIX] core: writing on one2many field on new record
When using command "6" (SET), the one2many field's inverse was not
assigned on the lines.

closes odoo/odoo#65675

X-original-commit: ba733a9ac73dcf978ed7eaab7681781b2d5a9bfc
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-02-07 14:32:19 +00:00
Ivan Yelizariev ed02c1a2db [FIX] core: fix adding a field related to Binary or x2many
such fields have store=True, but they don't exist in table.

---

https://github.com/odoo/odoo/pull/65232#issuecomment-773298323
https://github.com/odoo/odoo/commit/02417290191c22c9c99e6dc96a572c21f38e64f1

closes odoo/odoo#65669

X-original-commit: 2eee717ded0fc702b431f7fe784dc62438aa5603
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Signed-off-by: Ivan Yelizariev // IEL <yelizariev@users.noreply.github.com>
2021-02-06 12:41:03 +00:00
Martin Trigaux 76f305a556 [FIX] base: query company dependant as superuser
When retrieving company dependant values, the computed domain called
search_multi method of ir.property as normal user.
Since odoo/odoo@8f57863707 ir.property records are no longer
readable by a normal classical user.

To reproduce:
Add a domain using a company_dependant field
e.g. on res.partner, with purchase installed, modify the parent_id
field in form view to

  <field name="parent_id" ... domain="[('property_purchase_currency_id','=',property_purchase_currency_id)]" />

When clicking on the parent_id with a low priviledge user, an
access-right error is raised, as the user doesn't have access to
ir.property records

Fixes odoo/odoo#65450

closes odoo/odoo#65643

X-original-commit: 33868b4e14124800035ea99df111b35b4199ae60
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2021-02-05 16:20:49 +00:00
Ivan Yelizariev 1e9a5081b8 [FIX] core: initialize new stored related field via SQL
Filling the new column in SQL is dramatically faster than doing it via
the ORM, which iterates over all the records in the table.

The test case is creating a related field for 100+ records with distinct
values.  Setting the field's value was taking more than 100 queries.  It
now takes 3 queries.

task-2449313
opw-2380445
opw-2389376
https://github.com/odoo/enterprise/pull/15910

closes odoo/odoo#65432

X-original-commit: d66652b4aa514546356306e3eb48eaecaba07c33
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-02-02 18:52:13 +00:00
Ivan Yelizariev 3513b059e1 [FIX] odoo/fields.py: fix removing translations on writing ''
cache_value could be empty string rather than None. I'm not sure why it was
different before.

STEPS:
* install an app that adds menu Products (e.g. Sales)
* activate second language and switch to it
* create new product, set some value to field description ("Internal Notes"),
save
* click edit, remove description, save

closes odoo/odoo#64752

Before: the value is not removed
After: value is empty, translations are removed
X-original-commit: 3ef5e63f62f0f84d6e92cb55eb112ab2f2924faa
Signed-off-by: Ivan Yelizariev // IEL <yelizariev@users.noreply.github.com>
2021-01-19 15:02:08 +00:00
Raphael Collet 1e7659ad48 [FIX] core: avoid access error when flushing
This takes a former patch one step further.

Assume you recompute a field on two records, and the computation assigns
the first record but not the second one.  Before this patch, the
recomputation process was accessing the field on both records.  When
accessing the first record, both records are recomputed, and the value
of the first one is found in cache.  When accessing the second record,
no recomputation is made (it has been done already), and the cache is
empty. The field is thus fetched from database, and this crashes because
of insufficient access rights.

This scenario was causing some obscure nondeterministic crashes in
tests. The nondeterminism comes from the choice of the environment for
flushing (it should not be in superuser mode); the order of records in
the set to compute; the order in which records are assigned in the
compute method; the fact that the compute method should assign some
records and some not.

The fix consists in adding a method that processes pending computations,
without doing anything special for unassigned records.  The method is
used in field accessors (__get__ and mapped) and in method recompute().
The access error is gone because the recomputation no longer tries to
get the value of a field to compute.

closes odoo/odoo#64264

X-original-commit: b7676ec33172e6196b5fd1eda4df730ebf90eb6b
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-01-08 13:06:25 +00:00
Raphael Collet 0a098aceaf [FIX] core: marking and traversing computed fields before modification
This fixes an issue that occurs when marking fields to compute in the
following situation:
 - it occurs before the actual modification,
 - a relational field is marked to compute,
 - the same field is traversed to inverse some dependency.

When the marking occurs after the modification, the traversal of the
field should actually recompute the field.  However, if the marking
occurs before the modification, the inversion of dependencies must be
based on the current value of the field.  This is the case with method
unlink(): we call method modified() to mark the fields that currently
depend on the records to be deleted, and the fields must be computed
only after the deletion!

X-original-commit: cd19c2d93db8911fe42802640ea32e5d87aadeec
2021-01-04 09:16:20 +00:00
Julien Castiaux a152c536b7 [FIX] fields: Better error for invalid @depends
Create a model as follow:

    class FooModel(models.Model):
        _name = 'foo'
        bar = fields.Char(compute="compute_bar")

        @depends('bazz')  # wrong dependency, bazz does not exist
        def compute_bar(self):
            for rec in self:
                rec.bar = "Babar raconte des beaux bobards."

Uppon -u foo_module, a ValueError is rose for the invalid dependency
with the following message:

> Field foo.bar cannot find dependency bazz on model foo.

We had feedback the error message was not very clear to some users,
the new error message is:

> Wrong @depends on 'compute_bar' (compute method of field foo.bar).
> Dependency field 'bazz' not found in model foo.

closes odoo/odoo#62328

Task: 2366612
Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
2020-11-26 09:17:30 +00:00
Laurent Smet 6f2a6f7f2e [FIX] core: invalidation of computed editable field in one2many
This fixes the issue introduced by revision fd50ba9fb8

The way computed fields are invalidated depends on the order of the dict
passed as a parameter to method onchange().  This causes some unexpected
behavior when dealing with computed editable fields: the user loses the
value in that field because of the onchange.

Explanation: during the onchange, the modified field is cached by

    record._update_cache(changed_values, validate=True)

If the field is a one2many, 'value' contains an update command for each
modified line.  Because of 'validate=True', the assignment triggers
field computations on the lines, which are already handled by another
call to onchange().  In case anything on the parent model modifies some
line, the whole one2many values are returned to the user, and
accidentally recomputed fields show up in the interface.

closes odoo/odoo#62748

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-12-02 15:36:51 +00:00
Raphael Collet e3b27f2670 [FIX] core: document cache miss behavior in Field.__get__ 2020-12-02 14:42:33 +00:00
Julien Castiaux eded14b4c4 [ADD] fields.py: New x2many command helper
We provide a new helper class to help redact x2many commands for create
and write methods. To ensure best compatibility with the xmlrpc layer we
do not change the protocole, the commands are still 3-elements tuples
where the first element is still an integer in between 0 and 6. The
helper class provide the cannonical constants and static methods to ease
working with the commands. The new helper class is also available in QWeb.

Developers are encouraged to transition their code so it uses this new
helper class.

Task: 2366606
2020-11-30 10:16:09 +00:00
Julien Castiaux 762fce1d89 [FIX] fields.py: provide fields a default name
From python code, import a module class and print one of its field, it
shows garbage because the `model_name` and `name` fields are None. We
provide a default str/repr of the field.

closes odoo/odoo#46996

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-11-30 09:49:40 +00:00
Adrian Torres 49bd732de1 [FIX] core: allow writing to delegated m2o fields on records
Before this commit, it was impossible to write to a delegated m2o field
if the length of the recordset was greater than 1.

The reason was because the special case for delegated fields inside
fields.Many2one.convert_to_cache would check for `record.id` which is a
bit misleading, since record can be greater than one.

The solution is to check whether any of the records are real records
instead, as if all of the records are NewRecords, then the parent is a
NewRecord too.

Fixes #62069

closes odoo/odoo#62343

X-original-commit: 76bf9dc94165c79be873a8864bfdb50a0a636084
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-11-25 15:48:11 +00:00
Raphael Collet af6c56711f [FIX] core: avoid access error when flushing
This patch guarantees that computed fields with `compute_sudo=True` do
not cause access errors when fetched from database.

This fixes a non-deterministic access error upon `commit`, where fields
are recomputed and flushed with some random environment.  The method
`recompute` performs its duty by accessing the fields to recompute.  The
compute method of a field is called but does not assign it.  As the
field is not in cache, its value is read from database.  However, as the
latter is not done in superuser mode, it may cause some access error.

closes odoo/odoo#61842

X-original-commit: cfb942ab5902e0992434eb2c7db2940526df404e
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-11-17 11:32:42 +00:00
Raphael Collet c2150d9117 [FIX] core: use 'x_name' as _rec_name only on custom models
This fixes a very obscure bug that happens on workers serving multiple
databases.  Consider two databases A and B with the same model M, that
does not have a field 'name', but has a custom field 'x_name' only on
database A.  The bug can be reproduced with the module 'account' and its
model 'account.register.payments'.

Assume the server loads a registry for database A.  In that registry,
the model M uses 'x_name' as its _rec_name, and the field 'display_name'
on model M determines its dependencies to be the field 'x_name'.

Now assume the server load a registry for database B.  In that registry,
the model M has no _rec_name.  However, an optimization reuses the field
'display_name' for the model M on the registry of A.  The field's
attribute 'depends' is equal to the tuple ('x_name',).  When the ORM
tries to resolve the field's dependencies, it does not find the field
'x_name' on M and crashes.

In order to avoid this situation, we forbid the usage of 'x_name' as
_rec_name on non-custom models.

OPW 2349238

closes odoo/odoo#61534

X-original-commit: 731e676fa8a9f7bdc6a66056c124c3b39a0800ad
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-11-09 12:39:19 +00:00
Raphael Collet 8de95a3fb4 [FIX] core: validation of field parameters
The feature was actually not working as expected.  It has been fixed,
and a test now ensures it does work as expected.  This commit also fixes
some invalid parameters, hopefully nothing critical.

closes odoo/odoo#60429

X-original-commit: 231bdca3f26d96f578503694e5aec062de2317ed
Related: odoo/enterprise#14285
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-10-21 10:18:36 +00:00
Raphael Collet 7a1e0b2ada [FIX] core: assignment of binary field on new record with origin
The assignment of a binary field on a new record with origin did
actually modify the attachment storing the value of the field on the
origin record!  The fix is simply to avoid messing up with attachments
when updating new records.

closes odoo/odoo#59919

X-original-commit: 6778c4c10fa68c46bde6fae176f547f905e9c02f
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-10-13 17:28:48 +00:00
Raphael Collet 11d521d918 [FIX] core: assignment of size to new records
Upon onchange, the web client sends unchanged image fields on one2many
lines as "bin size" values, while changed image fields are sent as their
full value.  As the value is not base64-encoded, the assignment of that
value crashes.

Fix it by making assignment on new records not crash when decoding the
image: the value is simply not assigned to the field.  In the situation
described above, the record being assigned is a new record with a real
record as origin.  Because the field is actually not assigned, its value
is implicitly the value of the field on the origin record, which is
consistent with the fact that the field was not modified in the form.

X-original-commit: 4442d6f0f29a2bf6e992515cd535c88215855a36
2020-10-13 17:28:48 +00:00
Xavier-Do 71549030c7 [FIX] core: cache consistency of one2many field with computed inverse
Consider a one2many field with a corresponding many2one field that is
computed.  After modifying the many2one field's dependencies, the cached
value of the one2many field is inconsistent until the many2one field has
been recomputed.  Therefore, one has to force the computation of the
many2one field before accessing the cached value of the one2many field.

closes odoo/odoo#59034

X-original-commit: b9201ebdd65eaabab9257cf97c58410681783fa6
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-10-02 17:20:10 +00:00
Raphael Collet bc0dd33e5b [FIX] core: compute on batches of maximum PREFETCH_MAX records
Calling a compute method on 1M records inevitably brings a worst case in
cache prefetching: the code that determines which records to fetch has
time complexity O(N²).  We avoid this situation by calling the compute
method on maximum 1K records.  Each computed batch has a "prefetch set"
of maximum 1K records too, which avoids the worst-case scenario above.

closes odoo/odoo#58664

X-original-commit: 0b1aa660b1d94fe46dea09670b875f2d81ca36a3
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-09-28 11:59:23 +00:00
Raphael Collet f55fcbe15f [FIX] core: always evaluate field.depends upon setup
This is necessary when a field's dependencies are given by a callable.
This functionality was broken with the support for an explicit parameter
`depends` in the fields' definition, because the implementation could
not distinguish between the field parameter `depends` and the `depends`
evaluated from compute functions.

The fix consists in storing the field parameter `depends` into
`field._depends`, and the result of the setup into `field.depends`.

closes odoo/odoo#58144

X-original-commit: aebe9a76c9b35e84eda1f46bec3ef6da152b1539
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-09-21 14:04:25 +00:00
Raphael Collet b951579d31 [FIX] core: non-stored binary fields should have attachment=False
This prevents some code (in controllers) to retrieve an attachment for a
field that is not stored, as the code only relies on `field.attachment`.
This also makes the field definition more consistent.

closes odoo/odoo#57980

X-original-commit: 7325c3f8c538a8b8c0435963cdda3ced6fe4b324
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-09-17 16:54:02 +00:00
Raphael Collet 126ebbc905 [IMP] core: error message for computed field left unassigned
Non-stored readonly computed fields must be assigned by compute method.
Make the error message more explicit.

closes odoo/odoo#56269

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-08-21 09:39:27 +00:00
Raphael Collet 3e91fa1dbf [FIX] core: first onchange on new one2many line
Consider models `M` and `L`, with a one2many field `M.l_ids` with
inverse `L.m_id`.  Consider also a computed field `L.foo` that depends
on `L.m_id`.

The field `L.foo` is not computed correctly by `onchange` on a new line
in the form view of `M`: its value is forced to `False` because it has
no default, and is not recomputed by `onchange` since the field `L.m_id`
is never triggered an `onchange`.

Modify the method `onchange` to not force fields without a default to
`False`, and return all fields.
2020-08-20 13:39:04 +00:00
Rémi Rahir ecb1d732c6 [FIX] base: docstring typo
closes odoo/odoo#55983

X-original-commit: edacc0fc920e27b9759408887762fcba284ee391
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2020-08-17 09:52:26 +00:00
Xavier Morel bfa00919cd [IMP] core: clarify making fields inaccessible
* add a constant to `fields` for that purpose
* add a test to ensure that it works as expected
* fix the formatter so it handles the pattern correctly
2020-08-17 09:30:53 +00:00
Raphael Collet ef01493678 [FIX] core: update of one2many field on new record with origin
When setting the inverse many2one field on a record, the record is not
removed from its inverse relation if the field's current value is not in
cache.  Fix this by setting the field's value in cache before updating.

closes odoo/odoo#54711

X-original-commit: df12c85816dfa59f298c3e6a077bd88e4b7aa6a6
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-07-20 11:42:59 +00:00
Adrian Torres 9fefa08745 [FIX] core: mapped() does not prefetch as expected
Before this commit, calling `mapped()` on a relational field of a single
record inside a for loop does not correctly propagate the prefetch ids
from the bigger recordset down to the record inside the loop:

    [rec.line_ids.mapped('name') for rec in recs]

To be more precise, `recs` correctly propagates prefetching information
down to `rec.line_ids`, but method `mapped()` does not pass it along to
the record that triggers the prefetching.

This resulted in one query per record in `recs`, so if `recs` were a
1000 records recordset, at least 1000 queries would be necessary.

With this commit, the `mapped()` function correctly propagates the
`_prefetch_ids` of the larger recordset (`rec.line_ids`) so that the
prefetching works properly and the 1000 queries are brought down to 1.

This commit is a followup on #42611.

closes odoo/odoo#54565

X-original-commit: 0e97053fee36c0c76b70cb94be5340c3144b178b
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
2020-07-16 11:09:05 +00:00
Raphael Collet a21e8afda4 [FIX] core: update of one2many field on new record with origin
An onchange method can remove an existing line from a one2many field of
a new record with command 2, such as:

    move.line_ids = [(2, <NewId origin=42>), ...]

The processing of the command 2 above incorrectly tries to remove the
new line from the origin record, instead of the new record.

closes odoo/odoo#54545

X-original-commit: 7d138a445acbd9f2e122d9c30ca81877bae6a245
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-07-16 08:16:16 +00:00
Adrian Torres ce4fcebbbb [FIX] orm: don't log errors on constraint failure unless necessary
Given an scenario in which a field F of model M is defined in module X
as `required=True` and is extended by another module Y as
`required=False` in a database with data not satisfying the original
constraint:

During an upgrade of base the original constraint will be re-applied
on the data (and fail) even though it is no longer necessary because
module Y relaxes the NOT NULL constraint.

This failure in and of itself is non-blocking, the upgrade will go
through but an error and a warning are logged anyway which are not
problematic either except in the case of automated testing
infrastructure (such as runbot), because of this it would be best if
these errors would not be logged at all unless we're 100% sure that the
constraint that was applied is not relaxed downstream.

With this commit, the `finalize_constraints` method will verify that the
constraint is applicable (field is required) before re-applying the NOT
NULL constraint.

opw-2269220

closes odoo/odoo#53529

X-original-commit: f09f4826fbdd1a547503c51a3cfad71285312c49
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-06-23 15:33:04 +00:00
Xavier Morel 1eadda159f [FIX] core: make state special case overridable
`state` was special cased in `copy_data` such that it would always be
reset to its default value if it had one.

While this special case can be useful (maybe) and is certainly
ingrained in odoo, having it not be overridable can be
problematic. Move the special case to the fields, so it's possible to
explicitly mark state fields as copy.

closes odoo/odoo#53113

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-06-17 07:23:28 +00:00
Raphael Collet 150f68108c [FIX] core: do not compute a field on a mix of new and real records
This fix looks like good practice to avoid confusing developers when
writing compute methods for fields, and should not be necessary.  But it
actually fixes an extremely obscure bug in the computation of the field
`sale.order.invoice_status` when dealing with timesheets (module
sale_timesheet_enterprise).  The bug seems triggered by the fact that
the field is computed on both a given sales order and a new record with
that sales order as origin.

X-original-commit: f9c128c6f567dfaab5cfb0080e4fdc847942911a
2020-06-11 14:40:33 +00:00
Martin Trigaux 4afa747fa1 [IMP] *: make ir.property methods private
Should only interact with them via python code in a controlled
environment, no direct call with RPC
2020-05-26 15:50:11 +02:00
Victor Feyens 51bc8ef124 [IMP] doc: Image field documentation
It was considered important to precise that image fields without 
limitations weren't checked
at all and could therefore contain non image content (and precise some 
other things on Image fields).

Forward-port of #51200

closes odoo/odoo#51259

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2020-05-14 13:19:58 +00:00
Raphael Collet 8d99fd9448 [FIX] core: selection override with str or callable
If the original field is defined with a selection list, overrides with
method or methods names fall back on the list.

closes odoo/odoo#51232

X-original-commit: 272ba8d2238d1d1b87f47b114b55e6eed25314a8
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-05-14 08:41:44 +00:00
Victor Feyens 0a4b989536 [FIX] base: default check_company domain.
The supported case of check_company on `res_company` model fields was
not considered when specifying a default domain on `check_company=True`
fields.

closes odoo/odoo#48674

Nb: It is already correctly supported in the `_check_company()` method.
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-05-13 12:21:13 +00:00
Raphael Collet 5fc9b8c44a [FIX] core: partial unlink in recordset
The following loop crashes on the second iteration:

    for record in records:
	record.display_name     # access non-stored computed field
        record.unlink()         # delete record

The cache has been invalidated by `unlink` on the first iteration, so
the field is computed.  The computation is done on the whole recordset,
which fails with a `MissingError` because of the first record.  The fix
is to retry the recomputation on the single record in this case.

closes odoo/odoo#50910

X-original-commit: 7f33ebf528b1415452ce549e3329c3fe89be0ad8
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-05-08 11:33:38 +00:00
Raphael Collet eb08e2c228 [FIX] core: unexpected cache invalidation when updating one2many
When setting a many2one field, the corresponding one2many fields are
updated in cache.  When such a one2many field has a domain, the
evaluation of the domain may require to fetch some fields from the
database.  If the `towrite` cache has not been updated yet, the many2one
field is overridden by the database value.

Fix by setting the `towrite` cache before updating inverse fields.

closes odoo/odoo#50788

X-original-commit: c1ebfe05a66cfebc7ced36e25db5f6ff4bfb2d46
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-05-06 19:25:17 +00:00
Raphael ColletandChristophe Simonis c99873d149 [FIX] core: improve cache consistency of translated fields
X-original-commit: 7460d65387edd9d8578e048da6ee634ef6a2e71e
Co-authored-by: Christophe Simonis <chs@odoo.com>
2020-04-30 17:30:21 +00:00
Raphael Collet e7b98b811c [FIX] fields: screwing up cache when rounding monetary value
Consider a sales order with a single line.  Edit the sales order: remove
the line, and add another line with the same subtotal.  When saving, the
total of the sales order is 0.0.

Here is the explanation: the form view performs a `write` on the sales
order, and modifies the lines with a command `2` (remove line) and a
command `0` (create line).

After deleting the first order line, the cache is emptied, and a call to
`flush()` forces the recomputation of the total.  The value is computed
to be 0, and assigned to the field.  The assignment converts the value
for the cache, without prefetching the currency field (optimization),
and puts 0.0 in cache.  The assignment then converts the value for the
database, which prefetches most fields on the sales order: the cache is
now inconsistent and contains the old value V, while the database is
then updated with 0.0.

After creating the new order line, the total is once again recomputed.
Its value is V, and because the cache also contains that value, no
update is performed to the database, which remains at 0.0!

The fix consists in avoiding the prefetching of fields when accessing
the currency field to round a monetary value.

opw-2223134

closes odoo/odoo#49741

X-original-commit: 048ea2f20a0a2fa6d629cbe262cbbe765248d36f
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-04-18 09:46:33 +00:00
Xavier Morel 172722c4d2 [IMP] base: remove redundant base64 back and forth in attachments
* add a `raw` computed field, though only update some of base to use
  it (addons for which that makes sense can be migrated progressively)
* avoid working with base64 data when it's possible to work with the
  actual data
* improve datas (base64 encoded content): should depend on bin_size

closes odoo/odoo#47212

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-04-08 06:03:28 +00:00
Raphael Collet 7d34a334a6 [FIX] fields: add support for parameter invisible (actually used) 2020-04-07 09:25:08 +00:00
Raphael Collet 1b1b2142f1 [IMP] fields: add validation of parameter names 2020-04-07 09:25:08 +00:00
Victor Feyens 57eb964182 [IMP] base: document all field types.
closes odoo/odoo#49135

X-original-commit: cc653d3f1a49e2b7b2cc0ec833097bd7cf3528a1
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2020-04-07 12:11:57 +00:00
Raphael Collet a233d534c2 [FIX] core: add NOT NULL constraints in post-init
The method `_init_column` for the field `alias_id` of `mail.alias.mixin`
requires the reflection of models, because `mail.alias` records have a
many2one field to `ir.model`.  The actual initialization of the column
is thus performed in post-init phase (after reflection).  Therefore, the
NOT NULL constraint cannot be added right away.

X-original-commit: 2e3400f149ce4ed4c00bc49a519f58993b49bc51
2020-04-03 11:40:29 +00:00