Automated Action to prevent duplicates

If you are not familiar with Automated Actions, start here

Enable Developer Mode and navigate to Settings / Technical / (Automation) / Automated Actions:

Click on CREATE and enter the following:

Model:  Product Template
Action To Do:    Execute Python Code
Trigger Condition:   On Creation & Update
Before Update Domain: Internal Reference is set
Apply on:  Match all records 

Python Code

if record.default_code:
   existing_product = env['product.template'].search([('id','!=',record.id),('default_code','=',record.default_code)])
   if existing_product:
     raise Warning("You can't have the same Internal Reference Number in Odoo twice!")