我想将上下文发送到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>




和我蟒蛇我有这个:

def name_get(self, cr, uid, ids, context=None):
    if context is None:
        context = {}
    res = []
    for record in self.browse(cr, uid, ids, context=context):
        _logger.info('==============context============================%s', context)
        name = record.name
        if context.get('show_state', False):
            name = '%s %s' % (name, record.state)
        res.append((record.id, name))
        _logger.info('==============name_get============================name_get==============')
    return res


我没有上下文中的“ show_state”,也不知道为什么。
你能帮助我吗?

最佳答案

我并不是说在搜索记录时会通过context,只有当您尝试动态创建记录时(例如,使用创建和编辑选项),才会传递sale.order

而是在打开Sales Orders记录的菜单操作中传递上下文。例如的菜单,您应该像这样更改其操作的上下文,对于要在其中具有此行为的任何菜单,该操作都是相同的:



   <record id="sale.action_orders" model="ir.actions.act_window">
        <field name="context">{'show_state': True}</field>
   </record>


在这种情况下,当您搜索任何many2one中的任何记录时,该键将在上下文中传递,并且应该在您的方法中找到它。

关于python - Odoo 8:如何将上下文发送到python方法?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60316664/

10-11 22:38
查看更多