I want to send context to python method.
In xml, I have this code :
<?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>
and I python I have this :
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
I don't get the 'show_state' in context, I don't know why.
Can you help me?
I don't that context
is going to be passed when you search for record, it's only passed when you try to create a record in fly (using create and edit option for example).
Instead pass the context in the action of the menu that opens sale.order
records. for example the menu of Sales Orders
you should change the context of its action like this, same thing for any menu you want to have this behavior in it:
<record id="sale.action_orders" model="ir.actions.act_window">
<field name="context">{'show_state': True}</field>
</record>
In this case when you search for any record in any many2one this key will be passed in the context and you should found in your method.