forked from brain-tec/odoo-robot-framework
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconnection_erp.py
127 lines (103 loc) · 4.87 KB
/
connection_erp.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2016 brain-tec AG (http://www.braintec-group.com)
# All Right Reserved
#
# See LICENSE file for full licensing details.
##############################################################################
import logging
logger = logging.getLogger(__name__)
try:
import erppeek
except:
print "Please install sudo pip install -U erppeek"
def create_new_db(URL, password, name, demo = False, user_password='admin', lang='en_US'):
connection = erppeek.Client(URL)
if demo == "True" or demo == "u'True" or demo==True:
demo = True
else:
demo=False
db = connection.create_database (password, name, demo ,lang,user_password=user_password)
if db==1:
return True
return False
def drop_db(URL, password, name):
connection = erppeek.Client(URL)
echo="fail"
try:
connection.db.drop(password, name)
except:
return echo
def install_module(URL, DBname, password, module):
connection = erppeek.Client(URL, db=DBname, user="admin", password=password, transport=None, verbose=False)
install = connection.install(module)
modules_installed = connection.modules(installed=True)
if module in modules_installed.get('installed', []):
return True
return False
def uninstall_module(URL, DBname, password, module):
connection = erppeek.Client(URL, db=DBname, user="admin", password=password, transport=None, verbose=False)
uninstall = connection.uninstall(module)
modules_installed = connection.modules(installed=True)
if module not in modules_installed.get('installed', []):
return True
return False
def get_res_id(URL, DBname, login, password, model, module, name):
connection = erppeek.Client(URL, DBname, login, password, transport=None, verbose=False)
ir_model_data = connection.model("ir.model.data")
ir_model_obj = ir_model_data.search([('model','=',model),('module','=',module), ('name','=', name)])
if not ir_model_obj:
return False
if not isinstance(ir_model_obj, list):
ir_model_obj = [ir_model_obj]
ir_model_obj = ir_model_data.read(ir_model_obj[0], ["res_id"])
return ir_model_obj['res_id']
def get_stock(URL, DBname, login, password, model, product_id):
connection = erppeek.Client(URL, DBname, login, password, transport=None, verbose=False)
stock = connection.model(model)
stock_obj = stock.search([('product_id','=', int(product_id))])
if not stock_obj:
return [0.0]
if not isinstance(stock_obj, list):
stock_obj = [stock_obj]
#TODO look for and return qty and location_id for the element on the list
returnValue = []
for element in stock_obj:
stock_aux = stock.read(element, ["qty", "location_id"])
returnValue.append([stock_aux["qty"], stock_aux['location_id'][0]])
return returnValue
def get_stock_move(URL, DBname, login, password, model, product_id, variable_name, variable):
connection = erppeek.Client(URL, DBname, login, password, transport=None, verbose=False)
stock_move = connection.model("stock.move")
stock_move_obj = stock_move.search([('product_id','=', product_id),(variable_name,'=',variable)])
if not stock_move_obj:
return [0.0]
if not isinstance(stock_move_obj, list):
stock_move_obj = [stock_move_obj]
returnValue=[]
for element in stock_move_obj:
stock_aux = stock_move.read(element, ["product_uom_qty", "picking_type_id"])
returnValue.append([stock_aux["product_uom_qty"], stock_aux['picking_type_id']])
return returnValue
def get_id(URL, DBname, login, password, model, product_tmpl_id):
connection = erppeek.Client(URL, DBname, login, password, transport=None, verbose=False)
product_product = connection.model(model)
product_product_obj = product_product.search([("product_tmpl_id","=", int(product_tmpl_id))])
if not product_product_obj:
return False
if not isinstance(product_product_obj, list):
product_product_obj = [product_product_obj]
product_product_id = product_product.read(product_product_obj[0], ["id"])
return product_product_id['id']
def get_menu_res_id(URL, DBname, login, password, module, name):
return get_res_id(URL, DBname, login, password, model= 'ir.ui.menu', module=module, name=name)
def get_button_res_id(URL, DBname, login, password, model, module, name):
return get_res_id(URL, DBname, login, password, model=model, module=module, name=name)
'''
def create_db():
return create_new_db("http://localhost:8069","admin","test_create_db",False,"admin")
def install():
install_module("http://localhost:8069", "test_create_db", "admin", "l10n_ch")
'''
# get_menu_res_id('http://localhost:8069', 'test_create_db', 'admin', 'admin', 'base', 'menu_administration')