diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 41c91bf2b27..63ee42fc9cf 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -116,6 +116,9 @@ class SaleOrder(models.Model): self.ensure_one() return 'form' + def _search_invoice_ids(self, operator, value): + return ['&', ('order_line.invoice_lines.move_id.type', 'in', ('out_invoice', 'out_refund')), ('order_line.invoice_lines.move_id', operator, value)] + name = fields.Char(string='Order Reference', required=True, copy=False, readonly=True, states={'draft': [('readonly', False)]}, index=True, default=lambda self: _('New')) origin = fields.Char(string='Source Document', help="Reference of the document that generated this sales order request.") client_order_ref = fields.Char(string='Customer Reference', copy=False) @@ -175,7 +178,7 @@ class SaleOrder(models.Model): order_line = fields.One2many('sale.order.line', 'order_id', string='Order Lines', states={'cancel': [('readonly', True)], 'done': [('readonly', True)]}, copy=True, auto_join=True) invoice_count = fields.Integer(string='Invoice Count', compute='_get_invoiced', readonly=True) - invoice_ids = fields.Many2many("account.move", string='Invoices', compute="_get_invoiced", readonly=True, copy=False) + invoice_ids = fields.Many2many("account.move", string='Invoices', compute="_get_invoiced", readonly=True, copy=False, search="_search_invoice_ids") invoice_status = fields.Selection([ ('upselling', 'Upselling Opportunity'), ('invoiced', 'Fully Invoiced'),