summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic
AgeCommit message (Collapse)Author
2018-01-24[FIX] web: handle nested x2m default valuesMartin Geubelle
A `default_get` for a x2many field can return a new list of commands for one of its x2many field, like [[0, 0, { 'groups_id': [[6, 0, [1, 2, 3]]], }]] where [1, 2, 3] is a list of existing ids. This use case was not correctly handled by the BasicModel because `_makeDefaultRecord` was not recursive. Closes #22401
2018-01-18[FIX] web: fix crash when creating record with too many default valuesGéry Debongnie
When creating a record with many default values, it could happen that the number of ids returned by the default get (or onchange) exceeds the limit for the form view. For example, we can see the issue in the expenses list view. We can increase the limit in the pager, to a value higher than 40. Then, clicking on select all, then on 'Submit to manager' in the action menu will result in a traceback. The Submit to manager action will trigger a new action with a context key 'active_ids' with a large number of ids. After that, the web client will execute the server actions, which will return a new action with a context key 'default_expense_line_ids' with a bunch of ids. Then, it will attempt to create a form view. This will call the makeDefaultRecord method in the basic model. This method will generate the commands for the one2many, for all ids, but will only load the 40 first sub records. After, it will attempt to apply the onchanges, with some code that assumes that all operations of type 'ADD' correspond to a local datapoint. In this commit, we fix the code to properly work with operations of type ADD with a res_id, but with no id. In that case, we simply generate a command 'LINK_TO', since the value has not been changed. opw 804370
2018-01-17[FIX] web: fix issue with multiple pages and relational fieldsGéry Debongnie
When fetching x2manys in a x2many, the basic model did not properly sort the internal data structure before fetching the data. This is usually not an issue, except when we have an order which is different from the order of the res_ids. In that case, it can cause crash in some conditions, because the results from the fetchx2manybatched were applied to the wrong datapoint. To reproduce this issue, some specific conditions needs to be met. I think that it is easier to refer to the test, instead of trying to explain that. In this commit, we properly sort the data at the correct place. Note that this probably solves a bunch of other related issues, caused by the fact that the internal structure was corrupted.
2018-01-17[FIX] web: remove dead codeAlexandre Kühn
Cleaning dead code from these commits that have been reverted: 41fe7f9d1113d026b226b136b4477aaaf9f1f638#diff-54fd886cc58f994ad518ee72df4d3edeR50 2a5488619da22cfd901963dd141e722b195e82ab#diff-f96b339a9374f74489f1f98755e9787bL9253 41fe7f9d1113d026b226b136b4477aaaf9f1f638#diff-86d6d41b5bb7499bf055258d05549d59R3111 With these final changes, we hope to stop the many issues that have occured with binary fields, from these commits: 255e8ca3d92e3a77d7c2a145677623518bc2f978 7813a8e714f268983b0be88827ae1c8ad887e6c7 41fe7f9d1113d026b226b136b4477aaaf9f1f638 2a5488619da22cfd901963dd141e722b195e82ab What remains is the format of binary fields in list views without widgets, which shows the bin_size instead of the base64 string representation... ... Rest assured, the computation is in JS, so there are no 'bin_size' shenaningans!
2018-01-15[FIX] web: disable {bin_size: true} on binary fieldsAlexandre Kühn
Revision on 41fe7f9d1113d026b226b136b4477aaaf9f1f638 This commit intended to reduce the network load when reading records with binary fields. This was made possible by enforcing the contextual key `bin_size` to be set for records with binary fields. However, it is causing some issues (see #22222, #22231) which are: - write with bin_size:true generates a traceback - read/search_read with bin_size:true breaks some images on some views (e.g. base.view_partner_form) Since the problems outweight the gain of these changes, we revert them.
2018-01-12[FIX] web: contexts on field widgets + enforce bin_size for binaryAlexandre Kühn
Field widgets now have a key 'context' that let them extend the context of the dataPoint (e.g. list). In particular, widgets on binary fields enforce the contextual item {bin_size: True}, so that the server gives the size of the binary field as its value, instead of its content. This change on binary fields reduces network load when accessing a view with binary fields.
2018-01-11[FIX] web: prevent crash in some rare casesGéry Debongnie
When we have a form view with a one2many with an onchange, and with lines which contains a x2many, and more lines that the limit (so more than one page), and the read is not in the same order as what is displayed because we have a widget=handle, then we might have a problem when we delete one of the lines, if the onchanges tries to change the x2many. This is due to the fact that the order of the basicmodel datapoint is not preserved by the various operations going around. I think that we may still have a few other issues of this type, but it is actually quite difficult to establish. In any case, this situation is now properly handled. opw 804530
2018-01-09[MERGE] forward port branch saas-16 up to 4c410ee6a17Christophe Simonis
2018-01-05[FIX] web: add a stableSort method for sorting x2mChristophe Matthieu
Issue: create 60 lines in ordered x2many with the same value (0) for the order field and make a change ; the displayed records will be switched. The problem appears because the sorting function is not stable and the records with the same values can change place (hence change page), which is quite disturbing for the user.
2018-01-05[FIX] web: sort and onchange in tabbed editable x2mChristophe Matthieu
Two attempts of dealing with sorting (and resequencing) in tabbed (multi-pages) x2many editable lists (see odoo/odoo@c2563db and odoo/odoo@983c7ae) have been previously done, using a static attribute (`keepChangesUnsorted`) on the datapoint. This solution sadly only covers both cases separately, not if they are combined. Morever, onchanges were not correctly managed in neither of these two cases. A new approach is used here, by "freezing" and "unfreezing" the datapoint when needed, which is more flexible. Some modifications have been introduced: - when ordering a x2many, all records are now considered (and not only the records on the current page) ; an additional read is thus done on the sorted field for all records in the x2many relation - `setSort` is now asynchronous as a `read` might be needed
2018-01-03[FIX] web: issue with id field in x2m formStéphane Bidoul (ACSONE)
When the 'id' field is present in a x2m form, the x2m actions generated on create of the parent object are incorrect.
2017-12-18[FIX] web: better mode handling, prevent useless work in some casesGéry Debongnie
Before this commit, the way mode was handled was not optimal. The end result was correct (the widget were properly created/displayed in edit/readonly as required), but useless work was done. In particular, if we have list/x2manys with widgets and modifiers, it could happen that widgets were created in edit mode, then destroyed and recreated in readonly mode. This could happen in some important views, for example, any view with a field many2many_tags with a readonly modifiers (pretty much all views handling taxes) In this commit, we add a 'editable' attribute to list renderer. This is necessary, because the list renderer is not actually editable when it is in a x2many in a form view which is in readonly mode. Also, we need to manage the distinction between the fact that a list view is editable, and the fact that some widgets are created in edit and other in readonly mode, depending on modifiers, and on which line is being edited. We also add a benchmark (courtesy of CHM) to be able to measure the performance impact of edit/readonly/onchange in a larger form view. Before this commit, running this form benchmark on my machine gave a number of 0.4 op/sec, and after, it increases to 1.26 op/sec, so a pretty large improvement.
2017-12-12[MERGE] forward port branch saas-16 up to a2ea4ba095cChristophe Simonis
2017-12-11[FIX] web: give context to fetch x2m batchedLucas Perais (lpe)
Before this commit M2Mtags widget did not translate. This was because no context was given to the rpc that fetched the fields Hence, the lang was not passed. After this commit, M2Mtags translate well OPW 784396
2017-12-07[FIX] web: send proper context when fetching m2o namegetsGéry Debongnie
When fetching batched namegets (typically after a default_get), we need to evaluate the context that we send to the server. This may be important for models with a custom name_get method. (note: overriding namegets should be avoided if possible) With the new views refactoring, this was not done properly and the 'view' context was sent instead. This is not really critical, the proof is that it took a few months before getting some complaints, but this is definitely a bug. To reproduce, simply add a context attribute to a m2o field in a form view, with a non empty value in a default get, and look at the context sent to the server.
2017-11-28[MERGE] forward port branch saas-16 up to 3f66814a0d0Christophe Simonis
2017-11-24[FIX] web: better support for async field widgetsGéry Debongnie
Most field widgets are synchronous, but some of them have to do extra work before being ready (for example, the pad widget, or widget which needs to lazy load JS/CSS files). Because of that, the new views have been well tested with synchronous widgets, but not completely with async widgets. Some code depended upon the fact that the widget was ready immediately after being created. This was incorrect, and is fixed in this commit, by adding a new hook that is called in (basic) views after a widget is ready (meaning, start and willstart are done)
2017-11-20[FIX] web: empty field char should be set to falseGéry Debongnie
With the new views, empty char fields were sent to the server as '' (empty string) instead of false. This is not the correct behaviour, and actually cause some problems. For example, if you have a char field with a unicity constraint, then you cannot set it to '', since there is only one record that can take that value.
2017-11-20[FIX] web: properly refetch x2manys in some casesGéry Debongnie
Consider the following situation: a form view with a one2many which contains sub x2many fields (for example a m2m_tags). Suppose that the one2many has more than 40 records. Before this commit, trying to delete one of these records caused a crash. The reason is that when we delete a record, we need to reload the missing records in the one2many field. We actually do that with a _readUngroupedList. However, the _readUngroupedList method did not process x2many fields, so the information stored in the datapoints was 'raw', and the rest of the web client expected it to be a datapoint. To reproduce the issue in the testing environment, i had to use onchanges and a readonly attrs, to reach a situation where a crash could occur. This shows that, while the issue is critical, it was not totally trivial to be impacted by it.
2017-11-16[MERGE] forward port branch saas-16 up to 745d00362abChristophe Simonis
2017-11-16[FIX] web: make sure modifiers works for async widgetsGéry Debongnie
Before this commit, asynchronous field widgets (with willStart async), with a non empty template had a problem: the invisible modifier was not applied properly. The reason is that the code that applied the modifiers was called directly after the widget was 'willStarted'. This means that if this is async, and if there is a template, the $el in willStart will be replaced by another $el after, which will remove the invisible modifier. This was an interesting problem with the pad widget (it is asynchronous the first time a pad widget is instantiated)
2017-11-16[FIX] web: make sure modifiers works for async widgetsGéry Debongnie
Before this commit, asynchronous field widgets (with willStart async), with a non empty template had a problem: the invisible modifier was not applied properly. The reason is that the code that applied the modifiers was called directly after the widget was 'willStarted'. This means that if this is async, and if there is a template, the $el in willStart will be replaced by another $el after, which will remove the invisible modifier. This was an interesting problem with the pad widget (it is asynchronous the first time a pad widget is instantiated)
2017-11-13[FIX] web: grouped list views: allow sorting groupsAaron Bohy
Before this rev., sorting groups in list views wasn't supported. It hadn't been implemented in the new views. This rev. activates the feature, so groups can now be sorted on their aggregates again. It also implements a basic (first level only) sorting in mockReadGroup, in the mock server. opw 781288
2017-11-09[MERGE] forward port branch saas-16 up to 82add438f21Christophe Simonis
2017-11-09[FIX] web: do not lose onchange info in some rare casesGéry Debongnie
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-08[FIX] web: reuse the same BasicModel instanceMartin Geubelle
Before this revision, only the FormView allowed to reuse the same datapoint. This was only used when opening a FormViewDialog when opening the form view of record in a one2many field. However, this could be useful in other places for other views. In Studio for example, we need to instantiate a x2m view without the parent view ; we thus need to be able to reuse the same model for all basic views.
2017-11-08[FIX] web: prevent useless discard dialog from showing upGéry Debongnie
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-10-27[MERGE] forward port branch saas-16 up to 8fdac4b6b2fChristophe Simonis
2017-10-27[FIX] web: revert to previous state when onchange failsGéry Debongnie
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-26[FIX] web: handle onchange on nested one2manysAaron Bohy
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[FIX] web: default value for o2m inside o2mAaron Bohy
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[FIX] hr_expense,web: explicit link_to command for o2mAaron Bohy
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-25[FIX] web: _applyChange() should return list of changed fields, even when no ↵Christophe Simonis
onchange are performed
2017-10-25[MERGE] forward port branch saas-16 up to 7bfde6e05d1Christophe Simonis
2017-10-24[FIX] web: propagate view context in all x2m operationsGéry Debongnie
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-23[FIX] web: restore scroll position when leaving form viewsAaron Bohy
For instance, open a list view with enough records so that there is a scrollbar, scroll, open a record of the bottom of the list and go back using the breadcrumbs: the scroll position should be restored. Before this rev., it wasn't the case: the scroll position was reset to the top of the list (i.e. to 0). This was due to the form renderer which manually triggered the event DOM_updated on the main bus to ensure that textareas were correctly autoresized. However, this wasn't done at the right place, and it impacted the way scroll positions of views were saved/restored. Indeed, this was only necessary when switching from readonly to edit mode, i.e. when the form view was actually already in the DOM, but not at each rendering as they may be performed outside the DOM (and in this case, the DOM_updated event is triggered by the view_manager when the view is really appended to the DOM). Note that this whole scroll mechanism relying on the DOM_updated event will probably change soon in master, with the refactoring of the upper part of the webclient.
2017-10-23[FIX] web: reordering lines using the handle widget triggers onchangeChristophe Matthieu
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-20[MERGE] forward port branch saas-16 up to dc2a6c6cd2aChristophe Simonis
2017-10-20[FIX] web: properly handle failures in onchangesGéry Debongnie
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[FIX] web: make sure m2m_checkbox works twice in a rowGéry Debongnie
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-19[FIX] web: do not send id in update commands for m2mGéry Debongnie
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-17[FIX] web: generate proper x2many commands in some casesGéry Debongnie
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-13[MERGE] forward port branch saas-16 up to 8ee9024a4c8Christophe Simonis
2017-10-12[FIX] web: fix issue with default_get/onchange and one2manyGéry Debongnie
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-09[FIX] unfuck JS docstringsXavier Morel
2017-10-04[FIX] web: Ordering of inline tree views (#19856)kujiu
Allow to order from several columns in inline tree views (x2many fields in form views).
2017-09-30[FIX] web: don't discard x2many rows coming from default_getAaron Bohy
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[FIX] web: fix one2many default getDavid Monjoie
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[FIX] web: correctly apply onchange on boolean fieldfwi-odoo
When an onchange sets a boolean field to 'true', if this boolean was set to 'false' previously, the old value was used instead of 'false'.
2017-09-30[FIX] web: don't discard x2many rows coming from default_getAaron Bohy
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.