From 26c9e252cc46add67b0a08e15c84cee302ba3978 Mon Sep 17 00:00:00 2001 From: Alaguraj0361 Date: Fri, 6 Mar 2026 22:07:58 +0530 Subject: [PATCH] add script to synchronize POS categories to public categories for products lacking them. --- sync_cats.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 sync_cats.py diff --git a/sync_cats.py b/sync_cats.py new file mode 100644 index 0000000..66515c2 --- /dev/null +++ b/sync_cats.py @@ -0,0 +1,25 @@ + +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.")