Topic: Prevent Duplicate Suppliers Short Name

Currently Customer Short Name does not allow duplicates, this is good when we use short names as codes
But Suppliers Short Name is allowing duplicate, it is confusing to choose duplicated values from Suppliers List.

Should we add unique key for field supp_ref in table suppliers ?

Phuong

Re: Prevent Duplicate Suppliers Short Name

Is there any other js / ajax / php check for such duplicates in the Customer Short Name scripts that needs to be put in for the Supplier scripts as well apart from the unique key?

Re: Prevent Duplicate Suppliers Short Name

Yes:

add this function to supplier_db.inc

function duplicated_supplier_short_name($name, $id) {
    return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."suppliers WHERE supp_ref = ".db_escape($name)." AND supplier_id != ".db_escape($id));
}

add this check to submit handle (line 210) of suppliers.php

if (duplicated_supplier_short_name($_POST['supp_ref'], $supplier_id))  {
        $input_error = 1;
        display_error(_('Duplicate supplier short name found.'));
        set_focus('supp_ref');
    }

and change KEY `supp_ref` (`supp_ref`) to UNIQUE KEY `supp_ref` (`supp_ref`)  in the suppliers table in the two sql scripts

Phuong

Re: Prevent Duplicate Suppliers Short Name

@joe: nice fix?

Re: Prevent Duplicate Suppliers Short Name

Yes, but we can't fix the db change during 2.4.X.

Can it be used without the db change?

Joe

Re: Prevent Duplicate Suppliers Short Name

This can be implemented in FA 2.4 itself as it only affects one small index. FA 2.5 is certainly years away and such important db changes should not be delayed. Remember how long FA 2.4 was in the making.....

The code changes however, are independent of the index.