-
-
Notifications
You must be signed in to change notification settings - Fork 811
Expand file tree
/
Copy path__init__.py
More file actions
23 lines (19 loc) · 657 Bytes
/
__init__.py
File metadata and controls
23 lines (19 loc) · 657 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from . import models
def pre_init_product_code(env):
env.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 env.cr.fetchall()]
env.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