-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path10_update_product_label.py
61 lines (45 loc) · 1.64 KB
/
10_update_product_label.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/env python
# -*- encoding: utf-8 -*-
'''
Content:
- Update product label for products
'''
from cfg_secret_configuration import odoo_configuration_user
import erppeek
###############################################################################
# Odoo Connection
###############################################################################
def init_openerp(url, login, password, database):
openerp = erppeek.Client(url)
uid = openerp.login(login, password=password, database=database)
user = openerp.ResUsers.browse(uid)
tz = user.tz
return openerp, uid, tz
openerp, uid, tz = init_openerp(
odoo_configuration_user['url'],
odoo_configuration_user['login'],
odoo_configuration_user['password'],
odoo_configuration_user['database'])
def update_product_labels():
'''
@Function to update product label for the BIO product
'''
product_pattern = 'BIO'
label_id = 1
if not label_id:
print ">>>> Please set the label ID to update in the script >>>>"
products = openerp.ProductProduct.browse(
[('name', 'ilike', product_pattern),
('scale_group_id', '!=', False)])
print ">>>>>>>>> Number of product found: ", len(products)
to_update = raw_input("Update product (y/n/s): ")
if to_update.upper() == 'Y':
print ">>>>>>>>>>> START UPDATING <<<<<<<<<<<<"
products.write({'label_ids': [(4, label_id)]})
print ">>>>>>>>>>>> UPDATE DONE <<<<<<<<<<<<"
elif to_update.upper() == 'S':
print ">>>>>>>>>> SKIPPED <<<<<<<<<<"
else:
print ">>>>>>>>>> CANCELLED <<<<<<<<<<<"
return True
update_product_labels()