forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path__init__.py
More file actions
27 lines (21 loc) · 729 Bytes
/
__init__.py
File metadata and controls
27 lines (21 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from . import models
from odoo import api, SUPERUSER_ID
def pre_init_product_code(cr):
env = api.Environment(cr, SUPERUSER_ID, {})
cr.execute(
"""
SELECT product_tmpl_id from product_product
WHERE default_code is NULL
OR LENGTH(default_code) = 0
GROUP BY product_tmpl_id
HAVING COUNT(product_tmpl_id) = 1"""
)
product_template_ids = [x[0] for x in cr.fetchall()]
cr.execute(
"""UPDATE product_product
SET default_code = 'DEFAULT' || nextval('ir_default_id_seq')
WHERE default_code is NULL
OR LENGTH(default_code) = 0"""
)
env["product.template"].browse(product_template_ids)._compute_default_code()
return True