forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.py
19 lines (17 loc) · 887 Bytes
/
hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# -*- coding: utf-8 -*-
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
def pre_init_product_code(cr):
cr.execute("""CREATE SEQUENCE ir_default_id_seq START 1""")
cr.execute("""UPDATE product_product
SET default_code = 'DEFAULT_CODE' || 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