This question has been flagged
1 Reply
3600 Views

Hello,

I want to add a filter to the field invoice_lines on the invoice -view. Because the invoices are way to long so I only want to show the sections.

I tried to add a domain directly to the field in the view xml. This doesn't work, the field still shows all the lines. 

I tried to add an extra field: filtered_invoice_lines using the same ID as the invoice lines. I added a domain to this field. 

This works perfect, the field only shows the records I want to. But now there is a problem when I try to create a new invoice. Odoo gives an error, because for some reason this new-field makes it so the bookings are not valid anymore...

Therefor my question: What is the correct way to add a domain filter to a one2many field, so only the wanted records are shown in a view. 

Thank you for your help!

Avatar
Discard
Best Answer

Hello Dries Cox
You need to add a domain in .py file

for example=> move_line_nosuggest_ids = fields.One2many('stock.move.line', 'move_id', domain=['|', ('product_qty', '=', 0.0), ('qty_done', '!=', 0.0)])

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard
Author

Hello Jainesh Shah, Like I explained in my question, I already tried this. This works perfect, but when you do this, it generates a problem when you try to make a new invoice. for some reason odoo adds the lines twice to the booking resulting in an error booking.
If you know a way to make this work without the errors in when making the invoice this would be great. But like this, it doesn't work.