Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
936 Lượt xem

anyone help please!

Hello community, i need to execute some python codes in the server side before the window action below is calling, and after the python code executed the winodow action should be call.

menu:

          name='Inbox'
parent="main_menu_letter_management"
sequence="20" action="action_egp_letter_inbox_tree_view"/>

window action:

"
Letters
egp.letter.inbox
tree,form
{"default_desired_value": ""}
[('recipients', '=', context.get('default_desired_value'))]

[(False, 'tree'), (ref('egp_letter_inbox_form_view'), 'form')]
"


python function:

def open_custom_window(self):
employee = self.env['hr.employee'].search([('user_id', '=', self.env.user.id)], limit=1)
print('the employee gotted id', employee.id)

departments = self.env['hr.department'].search([('manager_id', '=', employee.id)], limit=1)
print('department gotted id ', departments.id)

action = self.env.ref('egp_letter.action_egp_letter_inbox_tree_view')
computed_value = departments.id
action.write({'context': {'default_desired_value': computed_value}})

return self.env.ref('egp_letter.action_egp_letter_inbox_tree_view')



Ảnh đại diện
Huỷ bỏ

Hmm I look into your code and i see your problem is the context 'default_desired_value' didn't have as you want right ?

Câu trả lời hay nhất

Hi,
Following video explains how to call a python function from the menu item and from the function return the action. see if it helps in your case,

See:  How To Call Python Function From Menu Item in Odoo



Thanks

Ảnh đại diện
Huỷ bỏ