forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.py
19 lines (17 loc) · 808 Bytes
/
hook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Copyright (C) 2019 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
def pre_init_product_code(cr):
cr.execute(
"""UPDATE product_product
SET default_code = 'DEFAULT' || nextval('ir_default_id_seq')
WHERE id in (SELECT distinct(pp.id)
FROM product_product pp
INNER JOIN (SELECT default_code, COUNT(*)
FROM product_product
GROUP BY default_code
HAVING COUNT(*)>1
)pp1 on pp.default_code=pp1.default_code
or pp.default_code is NULL
or LENGTH(pp.default_code) = 0)"""
)
return True