Skip to Content
Menu
This question has been flagged
1 Reply
2003 Views

Hello, 

I need to run python code when opening a view 

example : when i open invoice form, i need that an account.move method to be run automatically

Is there a way for that? May be a specific decorator for the method ?

Avatar
Discard
Best Answer

Hi,

Try create a boolean field on the model and mention the compute function on that field
then write a compute function without the depends decorator and include the boolean field on form view

for eg:

is_check = fields.Boolean("Check", compute="compute_is_check")

then inherit form view of account.move add the field to view. you can also make that field invisible

define compute method

def compute_is_check(self):
for record in self:
record.is_check = True
record.action_post()

Then the action_post will work when open form view.

Regards

Avatar
Discard