https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44087 --- Comment #1 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Created attachment 211533 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211533&action=edit Bug 44087: Only use valid EAN-13 barcodes as the base for the next EAN-13 barcode With autoBarcode set to EAN13, the next barcode is computed from the highest numeric barcode in items, without checking that it is a valid EAN-13: - C4::Barcodes::ValueBuilder::EAN13 (cataloguing barcode plugin and REST API) takes the highest 13-digit barcode. Bug 42221 filtered on length, but a 13-digit barcode with a wrong check digit can still be the highest one. It is then incremented without a valid check digit, and the plugin's incrementEAN13 recomputes the check digit from its first 12 digits, which can suggest a barcode that is already in use. - C4::Barcodes::EAN13 (used when creating items while ordering) inherits db_max from C4::Barcodes, which takes the highest numeric barcode of any length, so it can even generate barcodes longer than 13 digits. This is common after a migration or a change of autoBarcode, when barcodes from other formats are kept. This patch adds C4::Barcodes::ValueBuilder::EAN13::max_valid_barcode, which returns the highest barcode that is a valid EAN-13, walking the 13-digit numeric barcodes downwards in batches. Both get_barcode and a new C4::Barcodes::EAN13::db_max use it, so all paths agree. When there is no valid EAN-13 barcode, the behaviour is unchanged. Steps to follow: 1. Set autoBarcode to "generated in the form <EAN13>". 2. Create items with these barcodes: 2000000000008 and 2000000000015 (valid EAN-13) and 2000000000016 (13 digits, not a valid EAN-13, e.g. a barcode migrated from another system). 3. Add a new item to any record and click in the barcode field. 4. The suggested barcode is 2000000000015, which is already in use. 5. Apply this patch and restart services. 6. Reload the add item page and click in the barcode field. 7. The suggested barcode is now 2000000000022, the valid EAN-13 that follows 2000000000015. 8. prove t/db_dependent/Barcodes_ValueBuilder.t t/db_dependent/Barcodes.t -- You are receiving this mail because: You are watching all bug changes.