Odoo Help


This community 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.


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 1,916 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

--Ray Carnes--
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0 and Odoo 8.0, 9.0 (Since 2012)

Completed Functional and Technical Training.

Major Skills:

  • Needs Discovery and Requirements Analysis;

  • Function and Technical Specifications;

  • Project Planning;

  • Prototyping and Proof of concepts;

  • Data migration;

  • Configuration & Customization (UI and modules);

  • Integration - data, business logic and service levels;

  • Training and Knowledge transfer;

  • Go Live support;

  • Help desk;

  • Version Migration.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

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

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)


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