Reputation: 11
I'm creating a custom model in ir_model "x_custom_model" with its own custom fields "x_field_name" in ir_model_fields. Meanwhile I'm also generating a view, which uses this model and those fields. In this view I'm generating a Button which when clicked, has to call a method "my_method" in an already existing model "my_model_name".
I'm trying to access this method while currently working in "x_custom_model". The problem exists in not getting the method called. Any help or tips would be appreciated
1) I've tried giving the method name as a value of the name attribute as:
#Button attributes
<button name="my_method" type="object"/>
Error: x_custom_model had no attribute called "my_method"
2) Via server actions (Call_My_Method): Settings -> Actions -> Server Actions.
Python code:
print "Am I getting here?"
action = {"my_model_name".my_method}
#Button attributes
<button name="Call_My_Method" type="action"/>
Nothing happens, not even the print.
I'm currently stuck on this issue and I don't seem to find much useful information about it so any help would be appreciated.
Upvotes: 1
Views: 5972
Reputation: 2290
By default,
<button name="my_method" type="object"/>
will call the my_method
in the current object of the form view. You defined your object for form view like
<field name="model">x.custom.model</field>
You cannot simply call the other object my_method
from the current button. You need to define a custom method in your current x_custom_model
object and let it call the other object method by creating instance to that object.
Eg:
self.pool.get('other.object').my_method(cr, uid, arg, context=context)
Upvotes: 2