This question has been flagged
2 Replies
2435 Views

I added 2 columns in the sales order entry form. The 1st calculates the 2nd which can be possibly modified. My problem is that my cursor is positioned right away on the 2nd column, but the result appears only 1 to 2 seconds after.

I use onchange method to compute the field, is this the best way do that ?

I see 2 manners to obtain what i want :

- find a speeder way to get my result

- pause user interface until calculation is done (hourglass/gray screen)

Thank you in advance for any help you may offer.

Avatar
Discard

Hello Morvan,

I have been looking further into this and I think I have found the solution!

Here is how you block the UI and I have tested a quick script with JQeury to run this with an Onchange event. Here is the code which was added to the back to make the event happen. This script was added to the Backend Assets.

<script type="text/javascript">

$(document).ready(function(){

$(document).on("change", "#o_field_input_27", function(){

$.blockUI();

setTimeout(function(){

$.unblockUI();

$("#o_field_input_28").focus();

}, 2000);

});

});

</script>

You need to find out the input id of the field and then call the blockUI funciton, set a delay of however long (2 seconds in this case) and then unblock the UI. You then find the next element, in your case the onchange field and set this as the new focus.

You can go further and only add this script depending on the model etc using t-if to not confuse with any other models.

Here is the documentation I have found relating to blocking the UI. http://malsup.com/jquery/block/#overview

Hope this solves the issue!

Thanks,

Best Answer

Hello Morvan,

It seems you are using an onchange, when really it should be a computed field. 

See the documentation here: https://www.odoo.com/documentation/14.0/reference/orm.html#module-odoo.api

You need to define the compute value as a field parameter then use @api.depends("field1"). This would make the field readonly by default, meaning the cursor will not appear on the field2. 

I believe this should fix your issue. 

EDIT:

I have been looking further into this and I think I have found the solution!

Here is how you block the UI and I have tested a quick script with JQeury to run this with an Onchange event. Here is the code which was added to the back to make the event happen. This script was added to the Backend Assets.

<script type="text/javascript">

$(document).ready(function(){

$(document).on("change", "#o_field_input_27", function(){

$.blockUI();

setTimeout(function(){

$.unblockUI();

$("#o_field_input_28").focus();

}, 2000);

});

});

</script>

You need to find out the input id of the field and then call the blockUI funciton, set a delay of however long (2 seconds in this case) and then unblock the UI. You then find the next element, in your case the onchange field and set this as the new focus.

You can go further and only add this script depending on the model etc using t-if to not confuse with any other models.

Here is the documentation I have found relating to blocking the UI. http://malsup.com/jquery/block/#overview

Hope this solves the issue!

Avatar
Discard
Author

Thank you for your answer but computed fields do not correspond to my request, in the perspective where the caculated value is the default value but can be modified by the user.

The first field is the number of packages, and the 2nd the numbers of unit, and because product are fruits and vegetables, this could be different.

Apologies, I did not read the question properly, how about adding a read-only on the view for field 2. When field 2 is empty it is read-only, so it only becomes editable when it has a value?

Author

If i do that, the cursor will go to the next field after this one, and this is not what we want. Furthermore we will facing to the same issue, when user have to modifiy the order lines.

It seems to me to have already seen in Odoo, waiting times with hourglass/gray screen when the application is processing.

time.sleep(x) will stop the current thread and will cause the loading screen, but there is about 2-second delay before the loading screen pops up, sorry I couldn't be much help

Author Best Answer

.

Avatar
Discard