Odoo Help


Filter in sale.order list

on 2/24/15, 4:59 AM 518 views

I need to list all the orders are paid, but not entirely (so all orders with a first facture). 
I extends sale_order class with this, but its not works (i have no error message)

class sale(osv.osv):
    def _invoiced_search(self, cursor, user, obj, name, args, context=None):
        if not len(args):
            return []
        clause = ''
        sale_clause = ''
        no_invoiced = False
        for arg in args:
            if (arg[1] == '=' and arg[2]) or (arg[1] == '!=' and not arg[2]):
                clause += 'AND inv.state = \'open\' AND inv.residual != \'0.0\' AND inv.residual != inv.amount_total '
                clause += 'AND inv.state != \'cancel\' AND sale.state != \'cancel\' AND inv.state = \'paid\' AND rel.order_id = sale.id '
                clause += 'AND inv.state = \'open\' AND inv.residual != \'0.0\' AND inv.residual != inv.amount_total '
                sale_clause = ',  sale_order AS sale '
                clause += 'AND inv.state = \'open\' AND inv.residual = inv.amount_total'
                no_invoiced = True

        cursor.execute('SELECT rel.order_id ' \
                'FROM sale_order_invoice_rel AS rel, account_invoice AS inv '+ sale_clause + \
                'WHERE rel.invoice_id = inv.id ' + clause)
        res = cursor.fetchall()
        if no_invoiced:
            cursor.execute('SELECT sale.id ' \
                    'FROM sale_order AS sale ' \
                    'WHERE sale.id NOT IN ' \
                        '(SELECT rel.order_id ' \
                        'FROM sale_order_invoice_rel AS rel) ' \
                    'AND sale.state != \'cancel\'')
        if not res:
            return [('id', '=', 0)]
        return [('id', 'in', [x[0] for x in res])]

    def _partial_invoiced(self, cursor, user, ids, name, arg, context=None):
        res = {}
        for sale in self.browse(cursor, user, ids, context=context):
            res[sale.id] = False
            invoice_existence = False
            for invoice in sale.invoice_ids:
                if invoice.state!='cancel':
                    invoice_existence = True
                    if invoice.state == 'open' and invoice.residual != '0.0':
                        res[sale.id] = True
            if not invoice_existence or sale.state == 'manual':
                res[sale.id] = False
            return res
    _inherit = 'sale.order'     
    _columns = {
            'partially_invoiced': fields.function(_partial_invoiced, string='Paid',
            fnct_search=_invoiced_search, type='boolean', help="It indicates that an invoice is partially paid."),

Help ;)

1) invoice.residual is numeric, you compare strings ... invoice.residual != '0.0' 2) you enable debug_sql and analyze the result

on 2/24/15, 6:57 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 2/24/15, 4:59 AM
Seen: 518 times
Last updated: 4/2/15, 8:27 PM