Commit Graph
256 Commits
Author SHA1 Message Date
Toufik Ben Jaa 22a71d694f [FIX] odoo: do not try to set source term on new records
closes odoo/odoo#36026

Signed-off-by: Denis Ledoux <beledouxdenis@users.noreply.github.com>
2019-08-23 13:16:40 +00:00
Raphael Collet e388efd059 [FIX] api: share protected among environments
If a field is protected against recomputation, it must be protected in
*all* environments.
2019-08-23 10:00:12 +00:00
Raphael Collet fcb77f0f53 [FIX] fields: use column format in towrite 2019-08-22 13:40:40 +00:00
Raphael Collet 8918bbbb5e [IMP] fields: do not trigger recomputations on transient models from regular models
This is a performance optimization: modifying a regular record will not
trigger some recomputation on a transient record.  Most transient
records are simply waiting to be garbage-collected, so there is no need
to keep their fields up-to-date.

closes odoo/odoo#35909

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-08-22 10:05:52 +00:00
Raphael Collet 1d2bccd0db [IMP] fields: stricter rules on selection fields overridings
One cannot override the attribute `selection`, and list selections can only be
extended with `selection_add`.

Adapt the bad extensions to be consistent with the new warnings

closes odoo/odoo#35663

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2019-08-21 14:36:19 +00:00
Raphael Collet 4cd093a001 [IMP] fields: extend selection with a given order
When extended with the selection_add parameter, a singleton (value,)
where `value` appears in the overriden selection, can be used.
The new values are inserted in an order that is consistent with the
overridden selection and this list.

selection = [('a', 'A'), ('b', 'B')]
selection_add = [('c', 'C'), ('b',)]
> result = [('a', 'A'), ('c', 'C'), ('b', 'B')]
2019-08-21 13:47:17 +00:00
Sébastien Theys 064ebe3b1a [IMP] fields, test_new_api: add ondelete support for m2m
Each model of the relation can define `ondelete` for its `column2` foreign key.

This way the behavior is similar to m2o where the target of the `ondelete` is
the `comodel` foreign key.

Some models were already defining `ondelete` 'restrict' on m2m fields and after
review it appears the behavior introduced in this commit is the expected
behavior for them.

The 'restrict' from product.product has to be removed however because the rest
of the code needs adaptation now that it is properly restricted. These changes
will be done on a separate PR.

closes odoo/odoo#35654

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2019-08-20 14:09:01 +00:00
Raphael Collet 9920f20e4c [IMP] models: ORM speedup
This branch is the combination of several optimizations in the ORM:

* store field values once in the cache: the cache reflects more
faithfully the database, only fields that explicitly depend on the
context have an extra indirection in the cache;

* delay recomputations by default: use method `recompute` to explicitly
flush out pending recomputations;

* delay updates in method `write`: updates are stored in a data
structure that can be flushed efficiently to the database with method
`flush` (which also flush out recomputations);

* make method `modified` take advantage of inverse fields to inverse
dependencies;

* filter records by evaluating a domain on records in Python;

* a computed field with `readonly=False` behaves like a normal field
with an onchange method;

* computed fields are computed in superuser mode by default.

Work done by Toufik Ben Jaa, Raphael Collet, Denis Ledoux and Fabien
Pinckaers.

closes odoo/odoo#35659

Signed-off-by: Denis Ledoux <beledouxdenis@users.noreply.github.com>
2019-08-20 12:43:59 +00:00
Martin TrigauxandRaphaël Collet 7593b887df [REF] fields: use ir.model.fields.selection
The selection values of a selection field are now stored in database in the
model ir.model.fields.selection

This will allow to have a modular approche on selections and each selection
is now linked to the module that declared it.
Previously to this change, the selections were linked to the field, meaning
uninstalling a module had no impact on the selections stored on database.

With this change, the selections will now be translated in the correct module
(having an external id) and the records having a used selection will now be
reset to null.

closes odoo/odoo#30228

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>


Co-authored-by: Raphaël Collet <rco@odoo.com>
2019-08-19 11:44:34 +00:00
Christophe Simonis e8a3f1a04e [IMP] core: remove support of oldname attribute
This attribute is misleading as it is insufficient to correctly upgrade
the database. It only renames the column in the database, but other
operations are needed, like updating the corresponding `ir.model.fields`
record (and its xmlid). The default values and the translations are also
lost during the upgrade.

Moreover, this feature was misused. It was:
- left on fields during multiple versions.
- used on reports (SQL views). This would be ok if the feature was
complete, but, as is, it was useless.
- kept unchanged after a second renaming of the field (which can happen
versions later the first rename).
- used, even when the meaning of the field changed. i.e. the field
`archived` has been renamed to the classic `active`, but the value
in the database should be switched.

closes odoo/odoo#35439

Signed-off-by: Christophe Simonis <chs@odoo.com>
2019-08-05 11:49:07 +00:00
Florent de LabarreandOlivier Dony c8fca2d052 [IMP] base: add more information for incorrect dependencies
If a dependency was wrong in the triggers, it was hard to debug

Co-Authored-By: Olivier Dony <odo@odoo.com>

closes odoo/odoo#31958

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2019-08-05 13:57:34 +00:00
Sébastien Theys 8206b5b4cc [IMP] fields: add image field
PR: #34925
2019-08-02 16:44:47 +00:00
Martin Trigaux 66dea8bb7b [REF] web: remove raw_mode flag on export
The export is now always in raw_mode
Adapt the tests

Fixes odoo/odoo#18798

closes odoo/odoo#26724

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2019-08-02 08:53:24 +00:00
Adrian Torres de91028e1d [REM] api: remove references to env.dirty
closes odoo/odoo#34556

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-07-09 07:36:15 +00:00
Raphael Collet 368e9530f4 [REF] *: record.env.user._is_XXX() -> record.env.is_XXX()
Superuser mode implies `record.env.is_XXX()`.
2019-07-04 11:32:22 +00:00
Raphael Collet 1e6c3bec2c [ADD] api: flag su on environments
The flag defines a "superuser mode" on environments, which allows to
bypass access rights without changing the current user id.
2019-07-04 09:24:23 +00:00
Martin Trigaux 573ccf098f [FIX] fields: implement _description_digits
Otherwise, fields_get returns the string, not the digits
Add test
2019-07-03 11:16:24 +00:00
Martin Trigaux e2bd3e328a [IMP] odoo: remove LazyCursor
Was specifically created for decimal.precision at f0646cb51b
Should no longer be needed
2019-07-03 11:16:24 +00:00
Mitali Patel 0c5121a979 [IMP] decimal_precision: integrate into base
The decimal precision feature makes sense to be an ORM feature, no need to be
in a specific module

Previous syntax was
    from odoo.addons import decimal_precision as dp
    fields.Float(digits=dp.get_precision('Foo'))

and now is:
    fields.Float(digits='Foo')

Remove the possibility to have a callable method on the digits attribute (it
was only used for precision anyway) and directly retrieve the digits on the
decimal.precision model

Rename the method digits to get_digits to avoid confusion between the field
attribute when declaring a field and the method to retrieve the precision

Task id: 48198
2019-07-03 11:15:48 +00:00
Raphael Collet be560c2828 [FIX] models: new() cannot not trigger any recomputation
Set the flag `validate=False` to prevent `convert_to_cache` on x2many
fields from triggering recomputations with command 1 (update).
2019-06-13 15:01:29 +00:00
Raphael Collet 26bf8ca880 [FIX] fields: x2many value overrides default value on new records
When instantiating a new record, the commands of an x2many field apply
on an empty recordset instead of the field's default value.  This is
less bug-prone, and avoids an infinite recursion in `convert_to_cache`.
2019-06-13 15:01:29 +00:00
Raphael Collet c22912ec42 [FIX] models: convert values to cache in the right order
When updating the cache of a record, convert currency fields before
monetary fields in order to enable proper rouding.
2019-06-13 14:46:21 +00:00
Raphael Collet fb04afb15d [FIX] fields: avoid infinite recursion in convert_to_write 2019-06-13 14:39:13 +00:00
Christophe Simonis 71a50a2214 [MERGE] forward port branch saas-12.3 up to 409679866b 2019-06-06 11:54:35 +02:00
Christophe Simonis cfe0523714 [MERGE] forward port branch 12.0 up to 8f21148e1a 2019-05-31 14:37:38 +02:00
Robot Odoo bae24d7bdd [MERGE] web, web_editor, *: allow image optimize from media dialog
Merge commit for PR #31208

Before this task, many websites were slow due to big images.

Most users upload images without understanding the impact on SEO and speed.

Each upload of an image is important and require some configuration to find the
best solution between speed and quality according to the situation.

After this task, users will have more control on the upload of images,
especially they are given the possibility to reduce their size, quality, and
change the filename.

task-1930726

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-06-05 02:03:30 +02:00
Sébastien Theys 76cf2ae82a [IMP] web_editor, *: improve media dialog attachment upload
* = web_unsplash, website

Remove iframe upload and replace it with a proper RPC. The route is now only
accepting one file at a time, which makes it easier to maintain, and allows to
process the first file as soon as it is ready, instead of having to wait on
everything.

Also fix a bug where a document could not be uploaded because it would try to
parse it as an image.

Remove filter after search result from the JS and add the corresponding
conditions in the domain to avoid processing and returning unnecessary records.

If multiple attachments exist with the same URL, now display them all to avoid
confusion.

Compute all the necessary values in the python model instead of in the JS.

Allow SVG in the widget (the server already accepted them before).

Disable multiple image upload when not in multiImages mode.

task-1930726
PR: #31208
2019-06-04 22:14:13 +02:00
Raphael Collet b415da5daa [IMP] fields: add method to get a usable domain from a field
closes odoo/odoo#33816

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-06-03 12:37:39 +00:00
Yannick Tivisse f5dfe4727c [IMP] api.py: Rename company_id/company_ids into company/companies
The goal is to be coherent with the user property.

Actually, company_id and company_ids on the environment are no fields.

Calling env.company_id returns a browse record, not an id.
2019-05-29 08:09:15 +00:00
Florent de Labarre 897feb553e [IMP] doc: add information about index attribute
closes odoo/odoo#32606

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2019-05-27 16:29:50 +00:00
Christophe Simonis 8d7ee39213 [MERGE] forward port branch saas-11.3 up to 8a0e819d0b 2019-05-29 14:06:12 +02:00
Martin Trigaux 44d11fe777 [FIX] fields: inherit context_dependent from parent fields
If a field is inherited from another model, the attribute context_dependent
was not propagated correctly.

Example of bug:
>>> product = self.env['product.product'].search([], limit=1)
>>> product.name
'Whiteboard Pen'
>>> product.with_context(lang='fr_FR').name
'Whiteboard Pen'  # cache used
>>> template = product.product_tmpl_id
>>> template.name
'Whiteboard Pen'
>>> template.with_context(lang='fr_FR').name
'Marqueur pour Tableau Blanc'
>>> product._fields['name'].context_dependent
False
>>> template._fields['name'].context_dependent
True

Fixes odoo/odoo#33641
Closes odoo/odoo#33722

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-05-28 14:26:29 +00:00
Christophe Simonis cffd147cfd [MERGE] forward port branch 11.0 up to a20a31486c 2019-05-28 15:52:00 +02:00
Christophe Simonis a20a31486c [MERGE] forward port branch saas-15 up to cad0be27e7 2019-05-28 15:04:40 +02:00
Christophe Simonis cad0be27e7 [MERGE] forward port branch saas-14 up to 6b6d2c8455 2019-05-28 14:36:59 +02:00
Christophe Simonis 6b6d2c8455 [MERGE] forward port branch 10.0 up to 01020e18e9 2019-05-28 14:07:09 +02:00
Raphael Collet 0c912354a9 [FIX] fields: recursive stored fields
The compute method of a recursive field must be invoked on single
records even when several records are marked to recompute.

closes odoo/odoo#33529

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-05-21 12:39:02 +00:00
Christophe Simonis 2c68df0ab4 [MERGE] forward port branch 11.0 up to 82c901c937 2019-05-02 10:59:21 +02:00
mreficent c6d718f211 [FIX] In new records *2many, enable to handle multiple RPC inputs
closes odoo/odoo#24458

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-04-26 13:54:20 +00:00
Christophe Simonis 4c61621efb [MERGE] forward port branch 11.0 up to 9a7e3c8b49 2019-04-08 17:45:00 +02:00
Raphael Collet 76ee0afb29 [REF] api: remove deprecated env.in_onchange 2019-05-23 05:47:11 +00:00
Raphael Collet d0bb596f1d [IMP] fields: x2many fields of new records are new records
The value of an x2many field on a new record are new records, possibly
related to a real record, called its "origin".
2019-05-23 05:47:11 +00:00
Raphael Collet 3f555c9068 [FIX] fields: enforce compute_sudo on fields
closes odoo/odoo#33493

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-05-20 13:57:49 +00:00
Raphael Collet 6ad43a44a2 [IMP] models: new records return default values 2019-05-20 11:00:40 +00:00
Christophe Simonis 8dd5a85267 [MERGE] forward port branch saas-12.3 up to 60e71302a3 2019-05-13 15:26:12 +02:00
Yannick Tivisse a5b6f31cf2 [IMP] base: Contextualize the multi company
Purpose
=======

Allow the user to select the allowed companies for which he wants to see records
on top of selecting his current company.

It is confusing for users to see the records from the company he is connected to
and the records of the children companies.

Instead of using the hierarchy of companies to access records across companies,
the user can now select (from his set of allowed companies) the companies for
which he wants to access records.

/!\ This means that the user will interact with records from company A when in
company B.
Example: a SO has been created and confirmed in A. When in B, I create the
invoice from it.

Specifications
==============

1/ Deprecate the parent/children hierarchy on the res.company model. The fields are
kept on the res.company model to ensure the retro-compatibility, but won't be used
accross the standard code anymore. The only functional usage for this mechanism
was to allow to see records from several companies by creating a virtual parent
company, which will be possible with the new mechanism.

2/ By default, a user will only see the records of the company he is connected
to (or records without a company). (It is still editable by the user if needed).
For that, put this information in the user context, to allow having different
configurations on different browser tabs. Instead of having domains like
['|',
('company_id', '=', False),
('company_id', 'child_of', user.company_id.id)]
you'll have something like
['|',
('company_id', '=', False),
('company_id', 'in', company_ids)]
Note that the 'company_ids' is a value that is passed in the evaluation
context on the record rule, as we already have user, or time.
company_ids is a list of the ids of all the enabled companies in the
user's context.

3/ Out of the generic improvements brought by this task, this will illustrate
issues that could exist since several versions. For example, it should not be
possible to create a scrap order for the company A with a package of the company
B, or it should not be possible to create an invoice on the company A with
payment terms from the company B. Before the version 12.0, it was easy to
encounter this kind of issues as the admin was the SUPERUSER_ID. A positive side
effect of the fact that the SUPERUSER_ID has become an inactive user was to
make it more difficult to introduce mismatch on the records, but haven't solved
the issue, as it was still possible to do it with parent companies
configuration. Some of these issues have been fixed in this commit, but all the
business flows should be re-tested to check if an ir.rule should be introduced
(eg: a multi company rule for stock.quand.package), if the company of a record
is correctly transfered to another record created from the first record (eg:
From a SO, create an invoice and a payment, the company of the sales order
should be transfered on the invoice and the payment, even if the company of the
sales order is A and I'm logged into the company B with the company A enabled.

4/ Currently, if I click on a button on a notification email (example 'View
Task'), I face a traceback if I'm not logged into the company of the record.
Now, if you click on a button and if you have access to the record, the correct
company will be automatically set.

5/ If I display a kanban view with several records from several companies (and
an image), all the images should be displayed.

6/ Currently if you copy paste an url, this will crash if you're not in the
correct company. This won't be fixed because it's quite impossible to do it in
a clean way. This task brings a workaround. Copy/Paste -> Traceback -> Log into
the correct company, re-copy/paste -> Ok.

7/ 2 property methods have been added on the environment to retrieve the company
on which the user is logged in and the companies the user enabled, on a specific
tab.
That way, when creating a record, instead of doing
default=lambda self: self.env.user.company_id
do
default=lambda self: self.env.company_id
On the other hand, to retrieve the enabled companies, do
companies = self.env.company_ids

8/ Modify the Company Switcher widget to allow to log into another company
WITHOUT writing on the res.users (and thus bringing cache invalidation issues
and so on). Also allow to enable several companies and see records from several
companies, and independantly of the other browser's tabs.

9/ When focusing on a tab, save the current company configuration on the local
storage. That way, when doing 'CTRL+T' or a middle click, the context is
propagated to the new tab.

10/ Improve the error message in case of multi company access errors. Now, when
the user is in debug mode, display the related names of the records and the name
of the user who brings the issue.

11/ Remove the context erasing when writing on a res.users
This is probably coming from the migration to new API of the base module.
The context was not propagated at this moment, which was a common mistake at
that time. When migrating the module, probably by using the 'black box' method,
as the context was not propagated, it was erased on the new version. This is
now an issue because the context (i.e. the enabled companies) was erased when
writing on a res.users, leading to tracebacks.
See: https://github.com/odoo/odoo/commit/7eab8e26d3d46c53f4be924d6a34e80a66e74960#diff-4c2e738ee8f64f11806c889ea097b5e7R624

12/ Fix the crash manager on redirect warnings. The issue is the following
- Create an invoice on a company without a configured CoA.
- Set a partner
- On the onchange_partner_id, a redirect warning is raised to propose you
to configure a CoA
- Click on 'Go to the configuration panel'
- A generic warning says something like 'Do you want to discard your changes?'
- Click on yes, the page refreshes, but not on the redirect action.
Now, set correctly the action on the hash, and reload instead. The breadcrumb is
lost for example, but you reach the correct action at least.

13/ Introduce a res.group to enable/disable the multi company per tab
feature.

14/ To help the users to know which tab is in which company, add the
possibility to have a favicon per company. When creating a company,
the classical 'O' icon is colored by default in a random color.

15/ Remove the company switcher on the frontend. This was mainly there
to allow a user to swicth to the company linked to the website.
This behavior is now transparent to the user. If the website A is
activated, then the company set on the context is the company of the
website.

16/ Deprecated the _company_default_get method on the res.company
model. Remove the method _get_company on the res.users model.

17/ Add 'allowed_company_ids' and 'current_company_id' on the pyeval
context. You can now use those variables on domains in the views to
access directly to the activated company.ies on the current tab.

TaskID: 1960971

closes odoo/odoo#32341

Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2019-05-13 08:57:49 +00:00
Christophe Simonis 04acf0cc7c [MERGE] forward port branch saas-12.1 up to 2420492c26 2019-05-03 18:47:49 +02:00
Christophe Simonis 62017de41e [MERGE] forward port branch 12.0 up to d7c0c5c127 2019-05-03 09:16:50 +02:00
Christophe Simonis 3ca58705c9 [MERGE] forward port branch saas-11.3 up to 2c68df0ab4 2019-05-02 13:16:27 +02:00
Christophe Simonis 6d4940675f [MERGE] forward port branch 12.0 up to ea1fc124ef 2019-04-09 11:11:48 +02:00