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


I'm trying to port following action from odoo v11 to odoo v13. but in v13 I can not use the function context.get() there any more.

Does anyone know how to check/bypass the previous context in an action window?

res_model="helpdesk.solution.wizard"
binding_model="helpdesk.solution"
...
context="{'default_solution_ids': active_ids, 'remove_solution': True, 'default_ticket_id': context.get('default_ticket_id')}"
id="action_remove_solution_act"/>

If I try to install it, I will get a NameError.

Traceback (most recent call last):
File "/opt/odoo/lib/odoo/odoo/tools/safe_eval.py", line 352, in safe_eval
return unsafe_eval(c, globals_dict, locals_dict)
File "", line 1, in
NameError: name 'context' is not defined

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Yu,

In Odoo 13+, the context variable is no longer available directly in XML expressions like it was in older versions (e.g., Odoo 11). That’s why you're getting the NameError: name 'context' is not defined.

How to Fix It

Instead of using context.get(...), you should use the new format, where previous context values can be accessed using ctx.get(...) inside the context attribute of an action. Here's how you can rewrite your XML:

<record id="action_remove_solution_act" model="ir.actions.act_window"> <field name="name">Remove Solution</field> <field name="res_model">helpdesk.solution.wizard</field> <field name="view_mode">form</field> <field name="target">new</field> <field name="binding_model_id" ref="helpdesk.model_helpdesk_solution"/> <field name="context"> { 'default_solution_ids': active_ids, 'remove_solution': True, 'default_ticket_id': ctx.get('default_ticket_id') } </field> </record>

Explanation

  • Odoo 13+ replaced context.get(...) in XML with ctx.get(...).
  • ctx refers to the evaluated context passed from the action or environment.
  • active_id, active_ids, and ctx are all accessible in that scope.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 10 15
9602
1
thg 8 25
299
1
thg 8 25
364
1
thg 8 25
708
0
thg 8 25
452