Odoo Help


Best way to warn user a supplier invoice is already entered (match on supplier invoice number)

Ray Carnes
on 6/4/13, 6:54 PM 2,435 views

What would be the best way to implement a "duplicate check" when users are recording a supplier invoice?

The aim would be to avoid accountants entering the same invoice twice, based on the supplier invoice number.

It shouldn't prevent them from entering the invoice - just warn them that an existing invoice is already in the system with the same number.

constraints prevent duplicate entry, the objective here is just to detect a potential duplicate and warn the user - letting them enter it again if they need to.

Ray Carnes
On 10/18/13, 8:39 PM

I ended up writing a function:

    def onchange_supplier_invoice(self, cr, uid, ids, reference, context=None):

        msg = reference + 'has already been used!' 
        res = {'reference': reference, }

        if not reference:
            return res

        # Get all Supplier Invoices
        invoice_ids = self.search(cr, uid, [('type','=','in_invoice')], context)

        # Get all the references for all Supplier Invoices
        invoices = self.read(cr, uid, invoice_ids, fields=['reference'],context=context)

        # Check for duplicates
        for inv in invoices:
            if inv['reference'] == reference:
                raise osv.except_osv('Possible duplicate Invoice!',msg)

        return res

And triggering the function via on_change in the relevant field (in this case reference).

<field name="reference" string="Invoice Number" 

Depending on the use case, searching for Supplier Invoices matching the current supplier (if populated) may be better.

Bista Solutions US, Ray Carnes
on 10/21/13, 3:18 AM

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

0 follower(s)


Asked: 6/4/13, 6:54 PM
Seen: 2435 times
Last updated: 3/16/15, 8:10 AM