1
votes

I have a onchange field on Odoo in which saves a float value, but then I need to use this field's value on a method that runs when a button is pressed, but when I try to get this value through self.field_name, the value comes equal to 0.

Anyone knows how can I get the field value?

4
What have you tried so far? Which Odoo version do you use?CZoellner
Well, I found the answer. What happens is that the field was a readonly field, and if the field is readonly, you can't save a value on it, I had to create a new invisible field that received the value and then I pass the value to the value to the readonly field.João Pedro Campos Silva
In Odoo, the frontend does not pass the value of a read-only field to the backend. So instead what you could do is to simply have a field which is invisible on XML and you can access values from there. Still, if you want to reflect the values for the read-only field, you could override the js module and can remove the condition which makes the value blank in case of a read-only field.Sudhanshu Gupta

4 Answers

3
votes

What was happening is that apparently on Odoo you can't write a value to a readonly field, so on my XML I doubled my field that was readonly, and the new one I made it just invisible, and now it works perfectly. This is something that I also discovered, you don't need to declare a new field on the .py file and create it on the XML, you can just copy and paste your field, remove the readonly attribute, and add an invisible attribute, works perfectly.

The field I'm talking about is the consolidated_balance, and my XML is like this:

<record id="projected_cash_flow_wizard" model="ir.ui.view">
    <field name="name">projected.cash.flow.wizard</field>
    <field name="model">projected.cash.flow</field>
    <field name="arch" type="xml">
        <form string="Projected Cash Flow">
            <group col="4" colspan="4">
                <field name="start_date" required="1"/>
                <field name="final_date" required="1"/>
            </group>

            <group col="4" colspan="4">
                <field name="journal_id" attrs="{'readonly': [('all_journals','=',True)], 'required': [('all_journals','=',False)]}" />
                <field name="all_journals" />
            </group>

            <group col="4" colspan="4">
                <field name="print_bool" />
                <field name="consolidated_balance" readonly="1" />
                <field name="consolidated_balance" invisible="1" />
            </group>

            <footer>
                <button name="process_projected_cash_flow" string="Confirm" type="object" class="btn-primary" />
                or
                <button string="Cancel" class="btn-default" special="cancel"/>
            </footer>
        </form>
    </field>
</record>
1
votes

Try to user force_save, bro.

<field name="emm" colspan="2" readonly="1" force_save="1"/>
0
votes

Known issue https://www.odoo.com/apps/modules/8.0/web_readonly_bypass/

(I have to type at least 30 characters)😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂 😂

0
votes

You can try add option: store = True