Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

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

Avatar
odoo
Avatar
Discard
1 Answer
0
Avatar
odoo
Best Answer

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)"/>
1 Comment
Avatar
Discard
Avatar
odoo
-

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