This question has been flagged
2 Replies
11136 Views

I have added a compute field and I am calling API while rendering from Tree view to Form view and updating value in another fields as well. Currently want happening, form view get loading but compute function taking 2 seconds to fetch data, after fetching data I am able to update data of other fields (Visible in database table), but Form data is not getting updated. How can we :

1. Load form view after compute done and adding value in other fields

2. Auto-update the form view once my compute fields function executed.


Model :

class testCompute(models.Model):

    _name = 'test_compute'

    test_data= fields.Html('Recording', size=256)

    test_compute= fields.Char('Token', compute='getData', size=256)


    def getData(self, user_uuid=None):

         #API call to get data and getting HTML response - Taking almost 2 seconds to call API

        # Updating  test_data data field once get response from API call(HTML data in response)


Working Alternative Soln :

I have added a button on Form view and called this function using action="getData" . It is working fine and updating all fields, but when I am redirecting from Tree view to Form view it is not working

<button name="getData" string="Get Data" type="object"/>

Avatar
Discard
Best Answer

Hai Parag,
 In XML view please define the field "test_compute" in the form view too,  then the compute function work automatically.  No need of button action. if you not want to see it then hide it, but you must define it in form view. then its work perfectly.

Avatar
Discard
Author Best Answer

Hi Nikhil,

Thanks for response, I have added test_compute field in XML view as well.

When redirecting to form view, I can see compute function is also called, but before getting response from API call inside compute function, my form data is loaded, and not getting updated value once compute function API call finished.

XML View :

        <record model="ir.ui.view" id="test_view">

            <field name="name">Test</field>

            <field name="model">test_compute</field>

            <field name="arch" type="xml">

                <form >

                    <sheet>                     

 <button name="getData" string="Get Data" type="object"/>

<field name="test_data"/>

<field name="test_compute" invisible="1"/>

                      </sheet> 

                    </form>

                 </field>

          </record> 


Avatar
Discard