0
1 答案
0
最佳答案
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)"/>