'Odoo Filter Domain Many2one Field using Parent Id
I have a Many2one field, where the comodel_name is the same with parent model.
This is the parent model
class SaleOrder(models.Model):
_inherit = 'sale.order'
...
account_receivable_line = fields.One2many(...)
...
And this is the child model
class AccountReceivableLine(models.Model):
_name = '...'
...
from_order_id = fields.Many2one('sale.order', string='Sale Order')
...
As you can see, the comodel_name for from_order_id field is sale.order itself, where the sale.order is the parent model. I don't want the parent record show in from_order_id
I'm able to achive this feature using the domain filter in XML
<field name="from_order_id" domain="[('id', '!=', parent.id)]"/>
But I can't use XML domain filter, for some reason I need to use the python domain filter
return {'domain': {'from_order_id': [
('id', '!=', rec.parent.id), # This is not working
('partner_id', '=', rec.partner_id.id),
... # Another complex filter
]}}
The ('id', '!=', rec.parent.id) filter is not working in python code. How can I achieve that feature?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
