ODOO8:如何将上下文发送到python方法?
ODOO8:如何将上下文发送到python方法?,python,xml,odoo,Python,Xml,Odoo,我想将上下文发送到python方法。 在xml中,我有以下代码: <?xml version="1.0" encoding="utf-8"?> <openerp> <data> <record id="view_mim_wizardfor" model="ir.ui.view"> <field name="name">mim.wizard.inherit</field> <field n
我想将上下文发送到python方法。
在xml中,我有以下代码:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_mim_wizardfor" model="ir.ui.view">
<field name="name">mim.wizard.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<notebook position="before">
<field name="entete"/>
<field name="purchase_order_id" context="{'show_state': True}"/>
</notebook>
<group name="sale_total" position="after">
<button name="action_mim_wizard"
attrs="{'invisible': [('state','not in',('draft','sent'))]}"
type="object" string="Ajout avancé"
class="oe_link oe_edit_only"/>
</group>
</field>
</record>
</data>
我不了解上下文中的“show_state”,我不知道为什么。您能帮我吗?我希望您在采购订单上访问此上下文(根据字段采购订单id)
尝试检查此项,self.\u context.get('show\u state')我不知道在搜索记录时会传递
上下文,它只在尝试在fly中创建记录时传递(例如使用create and edit选项)
而是在打开sale.order
记录的菜单操作中传递上下文。例如,Sales Orders
的菜单,您应该像这样更改其操作的上下文,对于您希望在其中包含此行为的任何菜单,也是这样:
<record id="sale.action_orders" model="ir.actions.act_window">
<field name="context">{'show_state': True}</field>
</record>
{'show_state':True}
在这种情况下,当您在任意多个字段中搜索任何记录时,该键将在上下文中传递,您应该在方法中找到。我尝试了self,然后用record对其进行了更改。_context.get('show_state')但不起作用。您是否可以检查具有更新上下文的“purchase_order_id”字段?您的上下文似乎没有正确更新。当我通过调试模式>编辑表单视图检查它时,上下文在视图中。我将尝试在act_Window中添加它。例如,在以前版本的Odoo中,可以将上下文传递到XML中的字段,并通过此字段的onchange
等方法接收它。现在这个选项消失了,我们必须在动作中写入上下文。但更糟糕的是,刷新浏览器时会删除操作上下文。您知道是否有其他方法可以将标志变量从XML视图传递到Python方法吗?我刚刚检查了将上下文传递到XML字段并在例如onchange
methods中接收它实际上在Odoo 13中起作用,我的视图刷新得不好。在onchange方法中是,但它是否在m2o字段中的搜索调用中也通过了?
<record id="sale.action_orders" model="ir.actions.act_window">
<field name="context">{'show_state': True}</field>
</record>