6af8b7f95e70e4f55cb72ec1f76c4c3752cda4c9
The problem is generally due to the use of `var`, this one https://github.com/odoo-dev/odoo/blob/58a046d2146e884d467cde827f89fa603ed98a3b/addons/web/static/src/js/views/basic/basic_model.js#L1780 followed by an asynchronous call to a function using it We can therefore summarize the part of the `_applyOnChange` function that interests us by ```js for () { if (field. type === 'one2many' || field. type === 'many2many') { var list; ... //using list ... promiseFunction(list).then(function(){ //using list }) } } ``` In the case where we have two one2many which follow each other, this scenario occurs: - `list` is initially the first o2m - the `promiseFunction` is called with `list` (first o2m) - before the promise is resolved the loop continues - `list` is `Promise.then()` the second o2m - the first call to `promiseFunction` with `list` (first o2m) is done - we enter in `Promise.then()` - `list` is currently worth the value of the second o2m because `list` is a `var` - the second call to `promiseFunction` with `list` is finished - we enter the `Promise.then()` - `list` is currently worth the value of the second o2m because `list` is a `var` Result: `Promise.then()` is called twice with the first o2m and never with the second We can see what happened with this code example: ```js const array = ["a", "b"]; const asyncRead = async(value) => { console.log("async function arg", value) setTimeout(()=>{ return Promise. resolve(value); }, 100) } const forFunction = () => { for (let i = 0; i < array.length; i++){ var list = array[i]; asyncRead(list).then(function (){ console.log("then async function arg", list) }) } } forFunction() /* async function arg a async function arg b then async function arg b then async function arg b */ ``` While if: We use `let` by replacing `var list = array[i];` with `let list = array[i];` OR We force the use of `Promise.resolve()` argument by replacing `.then(function (){}` with `.then(function (list){}` We will get: ```js /* async function arg a async function arg b then async function arg a then async function arg b */ ``` opw-2694855 closes odoo/odoo#89160 X-original-commit: 99cb2f52e109ccf94ac8bd735cd776e84ef04260 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
Odoo
Odoo is a suite of web based open source business apps.
The main Odoo Apps include an Open Source CRM, Website Builder, eCommerce, Warehouse Management, Project Management, Billing & Accounting, Point of Sale, Human Resources, Marketing, Manufacturing, ...
Odoo Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps.
Getting started with Odoo
For a standard installation please follow the Setup instructions from the documentation.
To learn the software, we recommend the Odoo eLearning, or Scale-up, the business game. Developers can start with the developer tutorials
Languages
Python
49.6%
JavaScript
47.8%
SCSS
2%
CSS
0.3%
HTML
0.2%