# -*- coding: utf-8 -*- # Copyright 2026 Nexa Systems Inc. # License OPL-1 (Odoo Proprietary License v1.0) # # Assigns existing fp.coating.config rows (with recipes) to parts that # don't have one yet. Round-robin distribution. Idempotent. # # Field name on fp.part.catalog is x_fc_default_coating_config_id. COATING_FIELD = 'x_fc_default_coating_config_id' def run(env): print('=== Assigning coatings to bare parts ===') Part = env['fp.part.catalog'] Coating = env['fp.coating.config'] coatings_with_recipe = Coating.search([('recipe_id', '!=', False)]) if not coatings_with_recipe: print(' No coatings with recipes available — abort') return print(f' Coatings with recipes: {len(coatings_with_recipe)}') bare_parts = Part.search([(COATING_FIELD, '=', False)]) print(f' Parts without coating: {len(bare_parts)}') # Assign first 20 bare parts (or all if fewer) to_assign = bare_parts[:20] n = 0 for i, part in enumerate(to_assign): coating = coatings_with_recipe[i % len(coatings_with_recipe)] part[COATING_FIELD] = coating.id n += 1 print(f' {part.name!r} -> {coating.name!r}') env.cr.commit() print() print(f'=== Done. Assigned coatings to {n} parts ===') final_count = Part.search_count([(COATING_FIELD, '!=', False)]) print(f' Parts with coating now: {final_count}') try: run(env) except NameError: print('Run inside `odoo shell`.')