Commit Graph
580 Commits
Author SHA1 Message Date
Christophe Simonis a094f6318b [MERGE] forward port branch saas-16 up to 745d00362a 2017-11-16 12:40:36 +01:00
Géry Debongnie 6158c5ce04 [FIX] web: fix issue with combination of o2m, m2m, and m2o
Consider this: a form view with a one2many list view. In the one2many
list view, there is a many2one field.  When opening the manyone in a
modal form view, there is a many2many field.  In that situation,
clicking on 'Add a new record' on the many2many field had the
unfortunate effect of interfering with the one2many field in the main
form view, which caused a crash or the modal form view to close
unexpectedly.

The issue is that an event was simply not properly stopped at the proper
location.  This is usually not a big deal, but, as described above, it can be
a problem in some cases.
2017-11-15 13:48:49 +01:00
Aaron Bohy 995610c065 [FIX] web: JournalDashboardGraph widget crash
The JournalDashboardGraph requires nv, which is lazyloaded. Before
this rev., a crash occurred when this widget was instantiated and
destroyed before the loading of the lib was complete (because a
function of the lib was called in destroy()).

For instance, press F5 (to ensure that nv isn't already loaded),
activate some throttling in the network tab, go to Accounting and
as soon as the dashboard shows up, click on another menu.

opw 781628
2017-11-13 11:18:56 +01:00
Christophe Simonis de93645fe3 [MERGE] forward port branch saas-16 up to 82add438f2 2017-11-09 19:16:05 +01:00
Géry Debongnie ae4501da9c [FIX] web: do not lose onchange info in some rare cases
Here is a situation where we had a problem:
- a form view with a one2many field, which has no inline views
- the (non inline) list view has a field A, and is not editable
- the (non inline) sub form view has fields A and B, with an onchange on
  B which modifies A

In that case, the user could do this:
- go to edit mode
- click on 'add' a new one2many line
- change the value of B in the form view, this changes the value of A
- click on save to close the modal form view
- click on the new o2m record to reopen the modal form view
- rechange B
=> the onchange does not work

The explanation is that when we reopen the modal, we update the known fields
information, but we had to perform a fieldviewget to fetch the list
view, so we have a full knowledge of the fields.  However, the code did
not update the fields info (because it uses _.default), which means that
the onchange information contained in the form view is lost.

Note: the test system had to be adapted to more closely simulate what
actually happens.  In particular, the onchange flag is no longer added
by the mock server, since it should be done by the data manager, like
'real' code.  This change broke the basic model tests, which had to be
modified accordingly, by setting manually the onchange flag.
2017-11-09 14:03:35 +01:00
Géry Debongnie 9e97ad8dce [FIX] web: prevent useless discard dialog from showing up
Here is a scenario that could cause an issue:
- open a form view with a many2one
- click on edit button
- click on small external button for many2one. this opens a modal form
  view
- click on save in the modal (without changing anything)
- click on save in the main record
- exit form view. this opens a discard dialog

There were two issues here:
- saving the modal dialog automatically marks the many2one field as changed.
  This was necessary to force reloading the data, because editing a sub value
  in the modal form view could have changed the display_name of the manyone
  field.  However, this is not necessary when no change was done.
- when saving a record, the _isDirty flag was reset to false only if an
  actual rpc was done.  However, it may happen that the flag is set to
  dirty (for example, when modifying a value inside a many2one), but the
  main record has no changed fields.

In this commit, we also remove the on_save handler in the
formviewdialog.  This is a small refactoring in a stable version, but no code
currently use it, and I believe that it will make the code much easier
to maintain (the previous code was really awkward), so I think that the
tradeoff is acceptable.
2017-11-08 10:50:12 +01:00
Christophe Simonis 449ec5e29d [MERGE] forward port branch saas-16 up to 255478acbd 2017-11-07 15:28:28 +01:00
Martin Geubelle 255478acbd [FIX] web: clear m2o input at creation cancel
After entering a value in a many2one, if one clicks somewhere else, a popup
is opened to suggest the user to create (or not) a new record with the entered
value.

Before this rev, closing this popup resulted in an unclear situation where the
input was still set with the entered value but the new record hadn't been created.

This commit fixes this by clearing the input value if the record is not created.

See task#36055
2017-11-07 14:12:18 +01:00
Christophe Simonis 8f1e2044cd [MERGE] forward port branch saas-16 up to 810b6aa760 2017-10-31 16:29:07 +01:00
Géry Debongnie 3c55407f11 [FIX] web: allow dropdown selection in m2o
Before this commit, many2one fields were not (fully) usable in a list view: if
the user wrote some text, then when a dropdown with various choices
opened, pressed the 'down' key (to select a choice), the down keypress
caused a navigation move to the next line, which cancelled the
selection.

In this commit, we make the assumption that if the many2one dropdown is
opened, then navigation moves are not what the user wants.
2017-10-30 16:04:43 +01:00
Christophe Simonis e918271f76 [MERGE] forward port branch saas-16 up to 8fdac4b6b2 2017-10-27 14:09:20 +02:00
Géry Debongnie c163351e8a [FIX] web: revert to previous state when onchange fails
When an onchange fails (for example, because the onchange python code
raised a ValidationError, it is convenient to revert the form view to a
valid state, which is the previous state.

To do that, we keep in the _applyChange function the initial state, and
restore it in the case the onchange fails.
2017-10-27 11:49:19 +02:00
Géry Debongnie 416f8f6316 [FIX] web: mock server should add a __last_update field
A recent fix in web changed the field FieldImage to make sure it also
loads a __last_update field.  This is fine, except that a test in
enterprise (web_clearbit_tests) was using a field image, and failed
because it could not find the __last_update field in the demo data.

With this commit, we make sure that the mock server is always aware of
the __last_update field.
2017-10-27 11:04:40 +02:00
Aaron Bohy 16c90138bd [FIX] web: handle onchange on nested one2manys
Suppose that we have a form view with a one2many field o2m_1,
displayed as a list. The model of o2m_1 contains a one2many field
o2m_2 which isn't displayed in the list view, but which is in the
form view. If an onchange sets the value of o2m_1, e.g. with a
command 0 to create a new record, and that the value of o2m_2 for
this new record is set (e.g. with a command 0 as well), it crashed.
2017-10-26 08:22:00 +02:00
Aaron Bohy 6fa63eb15c [FIX] web: default value for o2m inside o2m
A traceback was raised when opening a new record for a model with a
one2many displayed inside a one2many (e.g. simply displaying the
number of records in the relation), and with an onchange setting a
default value to the inner one2many (for example, linking it to
existing records).

As the inner o2m has no subviews, it has no fieldsInfo, and the
code assumed that fieldsInfo was always set.

This was for example reproducible from v11 as follows:
  - create a product (with MTO/Buy and call for tender (need
    purchase agreement module))
  - create an SO with this product and confirm it
  - go to purchase order form view and add a move_dest_ids field in
    the tree definition of field order_line
  - go to menu purchase agreement and choose the PA generated by
    your SO
  - add a vendor, confirm the PA and click on 'New Quotation'.
2017-10-26 08:19:43 +02:00
Aaron Bohy 7b8001a847 [FIX] hr_expense,web: explicit link_to command for o2m
The ORM doesn't automatically link subrecords when it receives an
update command for a one2many. However, it may be necessary when
the default_get returns existing records for a one2many field. It
only worked before this rev. for the hr_expense model because of an
hack from 2016 (to reproduce: go to Expenses, check some expenses
from the list view, in Actions, click on 'Submit to Manager', the
new hr_expense_sheet contains the checked expenses (one2many), and
the webclient only sent an update command by linked subrecord).

This rev. fixes the problem properly: when the default_get returns
existing subrecords for a one2many field, a link_to command (4) is
generated alongside the update (1) command.
2017-10-26 08:19:43 +02:00
Lucas Perais (lpe) f45edfbe6d [FIX] web: image widget is dependent on its record's last_update
As a way to optimize loading, images are not necessarily fetched in db.
They have, in their url a "unique" parameter, which is the last_update date on **the record** and controls on the python-side whether it should get the image from a cache or from the db.

Before this commit, this __last_update field wasn't present in the view, so it wasn't fetched, and writes on a model's image worked but did not refresh.
The image displayed was the old one.

After this commit, when the image field widget is present, we force the loading of the __last_update field of the record.
Upon update, the image displayed is the new one.

OPW 777552

closes #20457
2017-10-25 16:39:52 +02:00
Christophe Simonis 693f8dc68a [MERGE] forward port branch saas-16 up to 7bfde6e05d 2017-10-25 14:57:24 +02:00
Géry Debongnie d58d6e270f [FIX] web: propagate view context in all x2m operations
It could happen in some cases that a rpc coming from a view was not made
with the context of the view (and from the action).  For example,

- enable "Lots & Serial Numbers" in the inventory settings
- create a stockable product tracked by lot
- go to the inventory dashboard, on the "receipts" card click on the
  three dots and then on "planned transfer"
this link forces the context key "planned_transfer" in the action
https://github.com/odoo/odoo/blob/11.0/addons/stock/views/stock_picking_views.xml#L725
- now add a stock move to move some quantity of the product you just
  created
- see that no button appears on the one2many list
- save
- see that a button appears on the one2many list

This is an issue because the read on the o2m at the end is made with the
wrong context.  The reason is that when we fetch x2m, we create a new
datapoint of type 'list' which did not reuse the context of its parent.
2017-10-24 15:38:55 +02:00
Christophe Matthieu b2327b8bf0 [FIX] web: reduce the number of changes when use handle widgets 2017-10-23 12:18:29 +02:00
Christophe Matthieu 512113b78a [FIX] web: reordering lines using the handle widget triggers onchange
issue: When reorder each line trigger an onchange on the line (if they are an
onchange linked to the field) and one onchange per line on the parent.

Adding an option doNotNotifyChange to avoid the trigger on the parent.
2017-10-23 12:18:28 +02:00
Christophe Simonis 10128fa7e8 [MERGE] forward port branch saas-16 up to dc2a6c6cd2 2017-10-20 19:27:04 +02:00
Géry Debongnie 635572b49d [FIX] web: properly handle failures in onchanges
With the new views, we mainly focused on making them work.  But we also
need to be able to handle unusual cases, such as some RPC failing.  An
example of such a problem was the following:

- a form view with a one2many with an onchange
- edit mode, change a field in the one2many, click elsewhere
- the onchange triggers, calls the server
- it may happen that the server fails with a ValidationError
- the onchange deferred fails, the line in the one2many is restored to
  the value known by the list renderer, which is the previous value (but
  the new value was applied to the model)
- we now have a 'corrupted' state: clicking on save will send the
  invalid value, even though the UI displays the previous one.

We solve this problem in this commit by making sure that the onchange
deferred returned by the _performOnchange always succeed (or stays
pending).  If the rpc fails, the deferred will succeed with an empty
dictionary.  This means that the list renderer will be updated with the
value from the model.

Note that it may not be intuitive that a failure in the onchange is not
seen as an error from the perspective of the _performOnChange, but I
think that it still makes sense:
- the validation/network errors are not really a concern of the UI. The
  UI just display the values entered by the user.
- if an onchange fails (for example, because of a coding error), we do
  not really want to prevent the user from working.

Also, when the onchange is performed, the initial change was already
applied to the local data.  Rollbacking them would be a more difficult
task.

Note that we also improve the mock server in this commit, to allow
mocking failures.
2017-10-20 17:14:10 +02:00
Géry Debongnie 823cfd6ab1 [FIX] web: make sure m2m_checkbox works twice in a row
We had an interesting bug with the field many2many_checkbox: in some
cases, it could cause a crash, because it could not find an element in the
localdata.

To reproduce this, start with a non empty field many2many checkbox, then
uncheck them twice.

The reason is that the datapoint of type 'list' that represents the
current value is actually modified, and the replace_with operation
assumed that it could find the localID by looking into its data.  I have
the feeling that a more complete fix is to make sure that the datapoint
is not modified (in its 'data' key), but is modified in its '_changes'
key.  However, this would probably be a bigger change.
2017-10-20 14:56:37 +02:00
Martin Geubelle 2455350c40 [FIX] web: deal with date widget on datetime
This use case was not correctly managed as the function evaluating if the
value has changed compares datetime and date.

This triggered an issue if the widget `date` was set on the field `date_order`
on a purchase order for example ; it was not possible to create a record as
the datapoint was set `dirty`.

This rev. ensures that a `field_changed` is not triggered if the day is the same
on a date widget.

This rev. also adds support of `datetime` fields on date widget, which appears
to be a valid use case.

Fixes https://github.com/odoo/odoo/issues/20311
2017-10-20 11:25:32 +02:00
Martin Geubelle 1312ee72cf [FIX] web: correctly render the field image
Before this commit, the image was directly built without using the corresponding
template, which set some properties on the image (class, width, etc.).
2017-10-20 11:04:08 +02:00
Géry Debongnie d8f03e64fd [FIX] web: do not send id in update commands for m2m
When we generate commands for many2many, it could happen that the id was
in the list of changed fields (when we are in a new records, with a non
empty initial onchange).  When this happens, the server is not happy.

To reproduce this, open the uninstall wizard of a module in the 'App'
application.  This creates a new record with a non-empty many2many
field. Then click on 'Show technical modules', this will trigger an
onchange which should not send the id field.
2017-10-19 10:56:49 +02:00
qsm-odoo 841f41f95b [FIX] web: domain field should never be considered unset
Indeed, false was already considered as "[]" in edit mode.
2017-10-18 18:14:33 +02:00
Géry Debongnie d365a289d4 [FIX] web: generate proper x2many commands in some cases
When creating a new record with a non empty default value for a one2many
field, we did send the command 0 (for each one2many line) instead of the
command 1 (update).  This was a pretty big problem, because then the
server would try to create a line with possibly incomplete data.

For example, it was not possible to create expense sheets: go to expense
menu, select one expense in the list view, click on the action menu
'submit to manager', this opens a form view with a one2many with the
selected expense, then save.  Before this commit, this would lead to a
server error.
2017-10-17 18:21:47 +02:00
Khoi Nguyen 8191d6d72e [FIX] web: tab navigation with phone widgets in form view
This commit ensures that tab navigation works properly when editing a
form view that contains input fields with phone widgets. Previously,
pressing TAB would skip those fields.
2017-10-16 13:05:19 +02:00
Khoi Nguyen 9f7af9f9b7 [FIX] web: ticking a checkbox in an x2many after onchange
This commits fixes a traceback that appears when ticking a checkbox in
an x2many which triggers an onchange. The root cause of the issue is
twofold:

- confirmUpdate requires currentFieldIndex to be defined, but might be
  needed when setting currentFieldIndex;
- confirmUpdate attempts to restore the selection range even if we are
  not dealing with a char field (e.g. checkbox).

We solve the issue by ensuring that _selectCell gives a temporary value
to currentFieldIndex. This value is chosen so that confirmUpdate calls
_selectCell with the right parameters. Moreover, we only restore the
selection range when the range is defined.
2017-10-16 11:34:39 +02:00
Khoi Nguyen bb692c76d4 [FIX] web: tab navigation with phone widgets in form view
This commit ensures that tab navigation works properly when editing a
form view that contains input fields with phone widgets. Previously,
pressing TAB would skip those fields.
2017-10-16 11:34:39 +02:00
Christophe Simonis 6df0bf2a67 [FIX] web: correct expectation in new test introduced by previous forward-port 2017-10-13 14:26:46 +02:00
Christophe Simonis 1da064a1d3 [MERGE] forward port branch saas-16 up to 8ee9024a4c 2017-10-13 13:13:11 +02:00
Géry Debongnie d4cf4374d1 [FIX] web: allow widget many2many_tags to display more than 40 records
Before this commit, the widget many2many_tags only loaded the first 40
records. This was difficult to see, because there were not so many views
with a lot of tags.
2017-10-12 16:15:06 +02:00
Géry Debongnie 66b692a5eb [FIX] web: fix display issue with fieldSelection
When displaying a many2one values, in edit mode, the option did not
properly display some characters.
2017-10-12 16:14:49 +02:00
Géry Debongnie 7d448d57e3 [FIX] web: fix issue with default_get/onchange and one2many
Before this commit, there was a bug when creating a new record which
contains a one2many with an onchange.  The commands sent to the onchange
did not contain the full information.

Here is how you could reproduce the issue: install expense, go to the
expense list view, select the 2 lines, then, in the 'action' menu in the
control panel, choose 'Expense: submit to manager'.  In the new expense
sheet, you could see that there were two lines in the one2many
expense_line_ids.  However, these lines are empty.  The reason is that
the commands sent in the onchange were 2 commands 0, with {} as data.

So, in short, the BasicModel did generate the proper commands, but with
empty data, in the specific case when we have a non empty one2many in a
default_get, then an onchange.

To solve this issue, I had to fix 2 things: the internal data struture
was wrongly updated, and the commands should be generated with all the
data, and not only the changes.
2017-10-12 16:14:47 +02:00
rgarnau b8dac2ff32 [FIX] web: integer not properly parsed
The parsing of the integers does not escape the thousands separator.

issue: Integers are currently not properly parsed. For example, create
a database in Spanish language, install product_expiry and in settings
activate Lots & Serial Numbers. Go to Products and create a new product.
Choose to track by lots and specify the use_time, life_time, etc.
When saving, all integers are set to 0
2017-10-12 10:34:40 +02:00
Christophe Simonis 6c2ab192ea [MERGE] forward port branch saas-16 up to 88a9980b0c 2017-10-10 16:49:59 +02:00
Khoi Nguyen 1bbb7d6241 [FIX] web: clear input on clicking 'Create and Edit' from many2one fields
We clear the input field when clicking 'Create and Edit' to ensure that
the field is empty if the user chooses to cancel the record creation. If
a record is indeed created, then the field value will still be updated.
2017-10-09 09:00:19 +02:00
Christophe Simonis 5ce21c7355 [MERGE] forward port branch saas-16 up to b3d0897f2d 2017-10-02 13:05:17 +02:00
Aaron Bohy 5164d30c92 [FIX] web: correctly redraw x2m list after onchange
When an onchange is set on an x2many field displayed as an editable
list in a form view, and the user updates one of the subrecords,
the updated subrecord is kept in the DOM and updated, and all other
subrecords in the relation are re-rendered and re-inserted at their
correct place in the list (because the onchange might have changed
them).

Before this rev., the order of the subrecords after the edited one
was reversed.
2017-09-30 17:33:20 +02:00
Aaron Bohy 776bac6a06 [FIX] web: don't discard x2many rows coming from default_get
Problem occured in the MRP Production wizard (with a consumed
product tracked by serial number). The opened record is a new
record, and its one2many has 2 default rows that are prefilled.
If the user edited one of the quantities in those rows, and set
an invalid value instead (e.g. a letter), the row was removed
without notice when it was focused out. This was because the
model wasn't aware that a change has been done on the record,
and as the record was flagged as new, it was simply abandonned.
2017-09-30 15:59:24 +02:00
David Monjoie 16eb262c60 [FIX] web: fix one2many default get
The one2many default get code used to meddle with basic_model's res_ids
manually, which ended up desynchronizing the data and res_ids fields
of the list representation of the one2many values.

This commit solves the issue by using the proper mechanisms of the
basic_model, that is creating a proper datapoint for those ids.

Steps to reproduce the original issue:
- Install sale_mamangement, mrp and purchase
- Create a product
- In the Inventory tab, in Routes, uncheck Buy
- Check and then uncheck back any other route than Buy
- Get a traceback because we are looking for a record with a given
  res_id in the list data but since they are desynchronized, data
  is empty at that point even though res_ids is not.
2017-09-30 15:59:24 +02:00
Khoi Nguyen bdeb775219 [FIX] web: focus issues after onchange in x2many with buttons
https://github.com/odoo/odoo/commit/36b4d78a2678806b25aaa5650b64496f9da9d205
fixes most post-onchange focus issues for x2many fields, but does not
account for "button columns" properly. More precisely, the current
widget is computed via a position index taking buttons into account in
an array that ignores them. This caused the index to be out of bounds,
resulting in a traceback. This commit fixes this issue.
2017-09-30 14:25:43 +02:00
Aaron Bohy 511fd5995c [FIX] web: don't discard x2many rows coming from default_get
Problem occured in the MRP Production wizard (with a consumed
product tracked by serial number). The opened record is a new
record, and its one2many has 2 default rows that are prefilled.
If the user edited one of the quantities in those rows, and set
an invalid value instead (e.g. a letter), the row was removed
without notice when it was focused out. This was because the
model wasn't aware that a change has been done on the record,
and as the record was flagged as new, it was simply abandonned.
2017-09-30 13:23:53 +02:00
David Monjoie 8d1630a40a [FIX] web: fix one2many default get
The one2many default get code used to meddle with basic_model's res_ids
manually, which ended up desynchronizing the data and res_ids fields
of the list representation of the one2many values.

This commit solves the issue by using the proper mechanisms of the
basic_model, that is creating a proper datapoint for those ids.

Steps to reproduce the original issue:
- Install sale_mamangement, mrp and purchase
- Create a product
- In the Inventory tab, in Routes, uncheck Buy
- Check and then uncheck back any other route than Buy
- Get a traceback because we are looking for a record with a given
  res_id in the list data but since they are desynchronized, data
  is empty at that point even though res_ids is not.
2017-09-30 09:04:29 +02:00
fwi-odoo da136d83bb [IMP] web: x2m list: conditionnaly hide a column
This commit introduces a new way to hide a column in a x2m list view.
The attribute 'tree_invisible' can be add in the field attrs in the x2m
view definition. This attribute can use the 'parent' key to make a reference
to the parent record (e.g. 'parent.id').
2017-09-29 16:49:20 +02:00
qsm-odoo da11387587 [FIX] web, mail: complete commit https://github.com/odoo/odoo/commit/87f1e360a89eb7617d5fd60cad58a143bea441df
Tests are overridding the `config` object directly but this was wrongly
done. Also, tests had to be adapted to set the `isMobile` value
correctly.
2017-09-29 16:39:06 +02:00
Aaron Bohy 36b4d78a26 [FIX] web,mail: reset focus after onchange on x2many
Rev. 2728fe1 introduced an attempt of restoring the focus on the
currently focused field in an x2many list after an onchange
returned, and the list has been updated. However, it was often
wrong (e.g. leaving a field by pressing tab/shift+tab, clicking on
another field...) and reset the focus on an unexpected field.

In addition to fixing this issue, this rev. also unifies the helper
functions to get and set the cursor positions in an input or
textarea, as they were duplicated between mail and web.
2017-09-29 16:02:36 +02:00