forked from alaguraj/odoo-testing-addons
add script to synchronize POS categories to public categories for products lacking them.
This commit is contained in:
parent
8ea9a66022
commit
26c9e252cc
25
sync_cats.py
Normal file
25
sync_cats.py
Normal file
@ -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.")
|
||||
Loading…
x
Reference in New Issue
Block a user