from odoo import api, SUPERUSER_ID import odoo registry = odoo.modules.registry.Registry('Chennora') with registry.cursor() as cr: env = api.Environment(cr, SUPERUSER_ID, {}) # 1. Get all products that have a POS category but NO public category products = env['product.template'].search([('pos_categ_ids', '!=', False), ('public_categ_ids', '=', False)]) print(f"Syncing categories for {len(products)} products...") for p in products: for pos_cat in p.pos_categ_ids: # Find or create matching public category pub_cat = env['product.public.category'].search([('name', '=', pos_cat.name)], limit=1) if not pub_cat: pub_cat = env['product.public.category'].create({'name': pos_cat.name}) print(f"Created Public Category: {pos_cat.name}") # Link to product p.write({'public_categ_ids': [(4, pub_cat.id)]}) cr.commit() print("Optimization Complete: Categories are now synced to the Website.")