odoo 16 ir.actions.server AttributeError NoneType

43 views Asked by At

I want to create an ir.actions.server action to open a form with a new record after login. For testing purposes I coded a function in my class

    class kskassenbuch(models.Model): 
_name = 'ks_sale.kskassenbuch'


@api.model    
def serveraction(self):        
    ​raise Warning(_('Test action!'))

and in xml:

<record id="action_new_kassenbuch" model="ir.actions.server">
        <field name="name">Kassenbuch_Action</field>
        <field name="type">ir.actions.server</field>
        <field name="model_id" ref="model_ks_sale_kskassenbuch"/>
        <field name="binding_model_id" ref="model_ks_sale_kskassenbuch"/>
        <!-- <field name="binding_view_types">form</field> -->
        <field name="state">code</field>
        <field name="code">records.serveraction()</field>
    </record>

After running this code I always get the error:

 ValueError: : "'NoneType' object has no attribute 'serveraction'" while evaluating 'records.serveraction()'

To me, it looks that the class is not connected to the action.

How can I write this action correctly?

1

There are 1 answers

0
klausjulius On

i solved it by adding from odoo import _ in the .py file