from odoo import api, SUPERUSER_ID def migrate(cr, version): env = api.Environment(cr, SUPERUSER_ID, {}) sf_shelf_model = env["sf.shelf"] sf_shelf_location_model = env["sf.shelf.location"] shelves = sf_shelf_model.search([]) for shelf in shelves: shelf_barcode = shelf.barcode or "" if not shelf_barcode: continue locations = sf_shelf_location_model.search([("shelf_id", "=", shelf.id)], order="id asc") for index, location in enumerate(locations, start=1): new_barcode = f"{shelf_barcode}-{index:03d}" location.barcode = new_barcode