Odoo set specific domain on xml file

fueggit picture fueggit · Apr 21, 2017 · Viewed 7.5k times · Source

I made a custom button whick call a view:

@api.multi
def split_bot(self):
    view = self.env.ref('purchase_request.view_supply_conditions_tree')
    context = self.env.context
    return {
         'name':blabla',
         'type': 'ir.actions.act_window',
         'view_type': 'form',
         'view_mode': 'tree,form',
         'res_model': 'supply.conditions',
         'views': [(view.id, 'tree')],
         'view_id': view.id,
         'target': 'new',
         'domain': [('purchase_id', '=', self.id)],
         'context': context,
         'flags': {'form': {'action_buttons': True}}
    }

But now I don't need this button. I need to open tree view on default "Edit" button click with the same domain:'domain': [('purchase_id', '=', self.id)] How can I use the same domain in my xml form? I tried to put domain as:

Got an error:

name 'self' is not defined

For more information:

purchase_order_status = fields.One2many('purchase.order', 'request_id', string='Order',copy=True)

purchase_id = fields.Many2one('purchase.request', 'Purchase request')

How can I change self.id in my xml form to get the same domain as was on button click?

Answer

Charif DZ picture Charif DZ · Apr 21, 2017

in xml you cannot use self in web client but you can use the value of the fields in the same view so if you want to use the value of the id in many2one field:

<field name="id" invisible="1"/>
<field ... domain="[('field_name', '=', id)]" />

you cannot use field in attrs, domain or context that don't exists in the same view