Skip to Content
Menu
This question has been flagged
1 Reply
8166 Views

I have been trying for a while now to put a domain filter on the sale.order.line's tree view in the sale-order view. The list of sale orders should be dynamically filtered based on a record in the parent(order_line)

Can somebody acknowledge that it is possible in odoo to put a domain filter on a One2many field in child-parent relation.

Strategies I tried:

place direct domain filter on the view ->not working

return a domain filter from an onchange event, triggered by changing the parent-field that should filter the view. The print of the return domain is like:{'domain': {'order_line': [('id', '=', 69)]}} or I even tried to add a reload action: {'domain': {'order_line_filtered': [('id', 'in', [67])]}, 'type': 'ir.actions.client', 'tag': 'reload'} (don't know if that is even allowed) both give no result.

-> not working

I tried a quite extende way of adding a virtual m2m field and then filter the order_lines based on the filtered m2m. This works as far as that the m2m is filtered perfectly, It behaves exactly as I like, but the O2m that has a filter to only show the values present in the virtual m2m doesn't changes... so, not working...

for the extended explanation of this there is a great explanation on the forum:

https://www.odoo.com/id_ID/forum/help-1/odoo-10-how-to-compute-domain-dynamic-domain-set-a-domain-based-on-a-function-or-a-field-157682

The last thing I tried was adding a calculated boolean field on the sale.order.line that is true if the line should be visible and false if the line should be filtered. The value shows on the screen, the calculated field is working and showing True/False nicely when lines should be filtered. But when I add the domain [('to_filter', '=', True)] to the O2m to filter out the True. Nothing happens... 

Am I doing something wrong here? or is there a different way of doing this?

Thanks for helping my out. This is the last clue I need to finish a project. I never thought this would be a difficult thing... 

Thanks in advance        

Avatar
Discard
Best Answer

Hi,

Try using the Web Domain Field module from OCA and see: Web Domain Field

How to Use:

.. code-block:: xml

<field name="product_id_domain" invisible="1"/>
<field name="product_id" domain="product_id_domain"/>


.. code-block:: python

product_id_domain = fields.Char(
compute="_compute_product_id_domain",
readonly=True,
store=False,
)

@api.multi
@api.depends('name')
def _compute_product_id_domain(self):
for rec in self:
rec.product_id_domain = json.dumps(
[('type', '=', 'product'), ('name', 'like', rec.name)]
)

Thanks

Avatar
Discard
Related Posts Replies Views Activity
1
Jun 22
4877
1
Jun 21
1794
1
Jun 15
3141
2
Jun 15
2478
0
Sep 24
107