Odoo Help

4

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

By
Ray Carnes
on 6/4/13, 6:54 PM 2,258 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.

1

Ray Carnes

--Ray Carnes--
17330
| 9 7 9
Atlanta, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0; Odoo 8.0, 9.0, 10.0.

Completed Odoo Functional and Technical Training.

Major Skills:

  • User Needs and GAP Analysis;

  • Functional and Technical Design;

  • Prototyping and Proof of Concepts;

  • Requirements Specifications;

  • Agile Implementation;

  • Data Migration;

  • Configuration & Customization (UI and code);

  • Integration - Odoo and non Odoo Applications and Services;

  • Training and Knowledge Transfer;

  • Go Live Support;

  • Helpdesk;

  • Version Upgrades and Migration.

  • Accounting Expert.

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. 

I am a skilled Communicator and I only take the serious things seriously!

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" 
       attrs="{'required':[('state','!=','draft')]}"  
       on_change="onchange_supplier_invoice(reference)"/>

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.

Register

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)

Stats

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