import re # Migration: isi code kategori & item_code produk untuk data existing env.cr.execute( "CREATE UNIQUE INDEX IF NOT EXISTS product_template_item_code_uniq " "ON product_template (item_code) WHERE item_code IS NOT NULL" ) env.cr.commit() cats = env['product.category'].search([]) for c in cats: if not c.code: c.code = f'{c.id:02d}' env.cr.commit() print(f'Kategori di-update: {len(cats)}') prods = env['product.template'].search([]) for p in prods: p._generate_item_code() env.cr.commit() print(f'Produk di-update: {len(prods)}') # Verifikasi contoh for p in prods[:5]: print(f' {p.name!r} -> {p.item_code!r}')