During the update of a module, the existing foreign keys are dropped if they have a different ondelete_rule than the one specified on the field.
The foreign keys for many2one transiant -> non-transiant are created with cascade rule by default (see `m2o_add_foreign_key_checked` method) so the check needs to be realised in the same conditions.
When computing a field on a recordset, a subset of the records may be missing
or forbidden by access rules. In that case, evaluate the compute method record
by record, and mark failed records as such in cache.
The method onchange() executes onchange methods in cascade. Suppose onchange()
is called and a field F=1 in the form. If an onchange method set F=2, that
value is put in the result variable. If another onchange method set it back to
F=1, the binding F=2 must be removed from the result variable.
Fixes#2309
When sending an email, both formats 'Name <email>' or '"Name" <email>' can be used for fields 'From', 'To' and others. If the name contains unicode characters, a regex only matching '"Name" <email>' was used to encode the name with RFC2047. That meant that the name was not encoded and eventually dropped, using only the email part.
Instead of using a limited regex, use the parseaddr method from email library.
Fixes lp:1272610, opw 607683
Cascading onchanges can be caused by a related field computed in cache. This
causes a bug in sale order lines, were setting the uom field forces reading
product fields, which are inherited from product templates. The inherited
fields are computed as related fields, which marks the product record as dirty.
This subsequently triggers an onchange on the product field, which resets the
uom field!
This fixes issue #2146. The inverse of a one2many field can be an inherited
field (_inherits). In that case, we cannot read its value with a simple
database query. Instead, we let the related field read it, but for performance
considerations we disable the prefetching of other fields.
Sometimes a cached bundled could be missing in the
ir.attachment filestore (for example after copying
a database for test purposes without duplicating
the filestore as well).
When this happens ir.attachment will return an empty
file contents ; treat this as a cache miss.
This means empty bundles would not be cached, which
is not a big issue - there is little benefit in
caching them, and they should not be common nor
useful.
When deleting filesystem-backed attachements, the
deletion on the file-system is not transactional.
In the event of a transaction rollback, the file
deletion would not be rolled back, which is a
dangerous side-effect.
This can happen for example when several transactions
try to delete the same file(s) at the same time.
The duplicate deletions might be detected by the
database (being concurrent update errors), and rolled
back at the point of the DELETE query, to be retried.
If the files have already been deleted in the file
system it before the rollback, it leaves the system
in an inconsistent state, at least temporarily.
One case where we have seen it is when web bundles
are loaded by many web users at the same time, right
after being updated (and thus invalidated).
As they are currently cached as ir.attachment records,
this often causes a corruption of the cache.
Add an attribute 'related_sudo' (True by default) for related fields.
A related field is computed as superuser if related_sudo is True.
Add explicit related fields 'name' and 'email' on 'res.users', as these should
be readable by the public user with module website_forum.
The test in test_ir_model creates a custom model. This causes a full reload of
the registry, which recursively installs the required modules while 'base' is
being tested. As a side effect, it commits stuff from the database, so that
the effects of test_ir_model are actually not rolled back.
This fixes a bug which is usually triggered in module account_followup, but
does not occur deterministically. Some recomputations of computed fields are
apparently missing. Environment objects containing recomputations todos and
kept alive by a WeakSet, are removed by the Python garbage collector before
recomputation takes place. We fix the bug by moving the recomputation todos in
a non-weakref'ed object.
When a relational field is assigned in an onchange, its inverse field is
updated in cache. Reading the current value of the inverse field may be
costly, for instance in the case of a one2many field with thousands of records
as a value. Instead, put in cache a SpecialValue that reads and updates the
field; it will be triggered only when it is accessed.
When reading a one2many field, the inverse mapping of the lines (matching m2o -> lines of corresponding record) was instantiating each line and then triggering the prefect of fields.
To improve the performances, the inverse mapping is done in sql to avoid triggering the prefetching.
The selection of records in cache for prefetching was moved to method
_read_from_database() by xmo at rev 785018cc in order to fix an access right
bug. But this introduced an issue: to explicitly avoid prefetching, you should
use read() instead of browsing records. We revert the change by xmo, without
reintroducing the bug (which apparently was fixed by another way).
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.
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).
through a server action, try to correctly set the value to write on a given
fields according to its type. For example many2one fields should receive an
int, not a unique containing the id of the new value.
It turns out TTFontFile can throw not only TTFError (generic) and KeyError, but also ValueError (unknown cmap) and maybe others.
Just catch Exception, warn that the font couldn't be loaded and report why.
Sometimes a node can't be translated using the website Translate
mode. The translation is added to the Application term list but
the id of the view is not correct.
This happen when a translatable node is a children of a inherited
node whose branding could not be kept. data-oe-source-id was left
over because it was not registered in MOVABLE_BRANDING
one2many and many2many fields depends on the security rules.
For instance, on products, with the taxes_id many2many fields, you only see the taxes of your own company, thanks to the multi company security rule
With related *2many fields, if you browse it with superuser, you will have all records of the one2many fields, even those you are not allowed to see, as superuser ignores security rules.
For instance, taxes_id of product.product is a related of taxes_id of product_template (through the inherits on product.template), and you should see the same taxes on the product template and on the product product (variant). This is not the case if the fields is read using the superuser
When the context contains 'recompute': False, the recomputation was not even
prepared. Now both create() and write() prepare the recomputation by invoking
method modified(). The flag only controls whether method recompute() is invoked.
In addintion, the former flag 'no_store_function' was converted to the flag
'recompute', so that both create() and write() use the same flag.
Fixes#1456
At the end of _prefetch_field(), a check is made to ensure that the cache
contains something for the field to prefetch. The check was incorrect because
the cache was checked for a regular value only.
The result of _convert_to_write() is intended to be pass directly to
`write()` or returned to the client (`onchange()` and `default_get()`.
`NewId` is as special value that must not be stored into the database
or exposed to the client.
On one2many fields writing in an existing record (not when creating new record), the computed stored fields of the one2many were not re-computed correctly
Computed stored fields were marked as modified only if no_store_function was not set to True in the context. no_store_function is set when writing one2many records on an existing record.
Now, these computed stored fields are marked as to be recomputed, but are recomputed later, at the end of the existing record write
The title field should not have a domain by default.
When a new record is created or the 'is company' field is changed, the onchange_type is triggered to restrict the domain accordingly to is_company field.
When an existing record is modified, there will have no domain on title field. It's not ideal but at least companies will be able to change the title without the need to modify twice the field is_company.
Fixes#1713
When the addons_path config contained the
default path, the system was working with
an empty addons_path in the middle of the
other paths. This empty one matched for all
files, making all files appear to belong to
the root path component, e.g. `home` if the
root path is in /home.
Refactored a bit to avoid duplicates and
redundant path calculations.
On Launchpad, as commented on bug 933496, PO entries (and their comments) are
shared between series. This mean that e.g. the 7.0 series can have the wrong
`reference` comments (those beginning with #:) as they would be copied from say
the trunk series. Those `reference` comments are used to import translations
and look them up.
This patch adds a few lines of code to tools.translate so that targets
defined in the POT `reference` comments are used in addition to those from the
PO file.
Also adds a test module to validate the new behavior.
This patch stems from:
- the 6.1 branch by Vo Minh Thu:
https://code.launchpad.net/+branch/~openerp-dev/openobject-server/6.1-fix-po-targets-933496-vmt
- the 7.0 port by Numerigraphe:
https://code.launchpad.net/~numerigraphe-team/openobject-server/7.0-fix-po-targets-933496-vmt
The title of the partner is restricted with a context that will change in the onchange_type. Having twice the same field will not work well.
Remove the invisible attribute as the domain is handled by the domain.
Due to the multi-company record rule on gamification.goal,
each access to the Goals menu and each opening of the
Messaging menu (thus calling get_serialised_gamification_summary())
is extremely slow (with several thousands goals/users).
Adding auto_join to the user_id FK on goals makes it much
faster. However it causes crashes when reading the table
because the _order of gamification.goal uses `create_date`,
which becomes ambiguous after the auto_join with res_users.
Solving this can be done by re-implementing _read_flat()
in the ORM using the internal Query object, as in search(),
which takes care of fully-qualifying all column names.
Until this is fixed, a simple workaround is to use
start_date in the _order instead of collision-prone `create_date`.
Fixes the translation term import/export logic to
support terms inside QWeb templates.
Refactored a bit the export code so the babel-based
QWeb terms extractor for ./static/src/*.xml files
uses the same logic as the regular extractor for
ir.ui.views with type QWeb.
Server-side QWeb rendering uses a mix of the native
view inheritance mechanism and the template inclusion
(t-call) mechanism. During rendering the translations
are only applied at "template" level, *after* the
view inheritance has already been resolved.
As a result translations are local to a template,
not to the inherited view in which they are actually
written.
In terms of exporting PO[T] files, this is done by
resolving the "root" QWeb template a view belongs
to, and using it as the location of the translated term.
During import there is one extra quirk for QWeb
terms: they need to be linked to the `website` model
rather than the actual `ir.ui.view` model they
are really pointing to, so the rendering phase can
properly recognize them.
The new API introduced a small behavior change where empty
string values written or stored in a char/text field were
replaced by False (i.e. as if they were NULL).
This was done to mimic the web client behavior, but introduces
a very surprising effect: a.name = ""; assert a.name == "";
would fail. It would also require many more tests in the
code when reading existing required values from the database,
as they could still be False when an empty string value
had previously been stored, for some reason.
[FIX] Do not raise 500 error when an asset is missing
Note: those features are already present in master but could not be backported because the asset bundles are now completely different since the sass and less support where added.
If a forward porting occurs, you can drop this merge and keep master's version
After commit f28be81, boolean columns may have more
NULL entries than before. In the (rare) cases where
a boolean column was used for an ORDER clause
(e.g. in the /shop page of website_sale), this
causes a change of the resulting ordering.
By coalescing NULL values to false in SQL,
we make the ordering consistent with what the
framework does for domain expressions with booleans,
and when reading boolean values, that is, NULL is
the same as False.
- [FIX] bounce regex: too many emails were considered as bounce and therefore
not displayed in the chatter and lost for the communication history. The regex
was not correctly looking for the bounce alias in the email_to.
- [FIX] invite email: replying to the invitation email (invitation as new
follower) now replies to the user sending the invitation.
- [FIX] mass_mailing: added a column to store the id of the original email
in addition to the many2one column. The many2one is set to null when deleting
the original email. As the information is necessary, it is saved on another
field. The many2one is necessary for indexes purpose as the inverse of
a one2many.
In combination with f28be81, this should help speed up
initialization of new boolean columns. psycopg2 handles
bool parameters values just fine inside cr.mogrify()
Boolean fields always default to False in 8.0,
even when they do not have explicit default values.
This causes extra queries in the form:
UPDATE <table> SET <bool_field> = false
WHERE <bool_field> IS NULL;
Those are not necessary as the ORM automatically
folds NULL booleans to False, and can be very
expensive on tables with several million rows,
as the whole table may sometimes need to be
rewritten (can take dozens of minutes)
This is related to commit d31faceb67
(This is to avoid the runbot being yellow if on_change methods have extra keys in the returned value, this is not wrong, the web client will simply ignore them).
When you set the date of a cron the July 1st at midnight, if the user
time zone has a positive offset, then the converted UTC date is the
June 30th and adding 1 month will end up on July 30th translating to
July 31th instead of September 1st.
To solve this issue we use the super user time zone for the date
calculation.
Some many2one fields happen to have several corresponding one2many fields,
typically with different domains. It is also the case for the field 'res_id' of
mail.message, where each model inheriting from mail.thread defines a one2many
based on that field. The fix ensures that when a relational field is updated,
all its inverse fields are invalidated.
The default values are computed by evaluating fields on a new record. The fix
retrieves values from the cache earlier, because in some cases, the evaluation
of a field invalidates a formerly evaluated field.
In the return result of an on_change, having keys which are not ine the view is not that bad, it is not an actual problem.
Display warning instead of asserting all the keys are in the views.
The extra parsing check is not necessary when we're
not validating inputs, because in that case the
values come from the database and are valid.
The validation is quite expensive due to calls
to strptime() + strftime().
This can give a performance boost on large databases
and should not be a concern in terms of access control
as the inheritance already grants access to the parent
records.
management to access documents in notification emails, as well as for the
'view quotation' link in portal_sale module.
models: added a get_access_action method: basically, returns the action to
access a document. It uses the get_formview_action by default (form view
of the document). However for some documents we want to directly go to the
website, leading to an act_url action for some documents. This method allows
this behavior.
portal_sale: get_signup_url now uses the mail.action_mail_redirect method
instead of directly redirecting towards a portal menu. This allows to fall
back on a standard behavior.
portal_sale: get_formview_action updated, to match actions tailored for
portal users.
website_quote: get_access_action of sale order updated. If the sale order
has a template defined, the returned action is an act_url (website view
of the quotation), not the form action anymore.
mail: fixed signature + company signature in notification emails. Even without
user signature, the company signature + access link should be correct.
portal: signup url in notification emali was not using the mail redirection
as action. It is now the case.
Due to the use of a sudo env, the records
were being added to the sudo cache one by
one instead of all at once. This meant the
prefetching was not able to load all
records at once, leading to prohibitive
times when processing thousands of
records.
If a selection field is defined by a list as selection, such as:
state = fields.Selection([('a', 'A'), ('b', 'B')])
one can extend it by inheritance by redefining the field, as:
state = fields.Selection(selection_add=[('c', 'C')])
The result is that the selection field will have the list
[('a', 'A'), ('b', 'B'), ('c', 'C')] as selection.
As `_inherits` fields are now handled via `related`
fields (not stored, obviously), a new descriptor
`searchable` has been added to `fields_get()` result
to indicated if the field is searchable or not.
Singleton object was required while access model properties, but search returns multiple results and hence caused traceback while accessing record.property
The one2many field 'user_ids' was initialized with an incorrect value for the
inverse field 'wizard_id', using a res.users id. The latter was causing a
MissingError exception. The fix is simply to not define explicitly the inverse
field in the one2many.
Also did a small cleanup of the code of the wizard.
The existing code was buggy when writing on *2many fields with a list of
commands: the value was converted for the cache, but taking an empty recordset
as the current value of the field.
It is not useful to try to create foreign keys when the destination model is
a PostgreSQL view for example.
We already do this kind of verifications but ir.actions and transient models
but did not for _auto.
- simplify the code by removing unused cases
- do not modify input argument 'value' of create/write
- do not call BaseModel.read() with reified group fields (this causes warnings)
When a new record is returned as the value for a many2one on a new record, the
method Many2one.convert_to_write() now returns a NewID, and default_get() then
discards that value from its result. This makes it consistent with its former
behavior.
Manual rebase of #1547
On child partner creation of a parent partner, the commercial_partner_id is not computed (and stored) in the create method.
Therefore, we should compute the commercial_partner_id before trying to sync his data