-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhelper.py
209 lines (156 loc) · 5.87 KB
/
helper.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import datetime
import random
from locust import TaskSet
class BaseBackendTaskSet(TaskSet):
def on_start(self):
self.client.login(self.user.db_name, self.user.login, self.user.password)
def search_browse(client, model, domain, random_pick=False):
Model = client.env[model]
record_ids = Model.search_read(domain, ["id"])
if len(record_ids) == 0:
return False
elif random_pick:
record_ids = random.choice(record_ids)["id"]
else:
record_ids = [rek["id"] for rek in record_ids]
browse_records = Model.browse(record_ids)
return browse_records
def find_random_delivery(client):
model = "stock.picking"
domain = [("origin", "!=", False), ("state", "=", "confirmed")]
return search_browse(client, model, domain, random_pick=True)
def find_random_invoice_draft(client):
model = "account.invoice"
domain = [("type", "=", "out_invoice"), ("state", "=", "draft")]
return search_browse(client, model, domain, random_pick=True)
def find_random_invoice_open(client):
model = "account.invoice"
domain = [("type", "=", "out_invoice"), ("state", "=", "open")]
return search_browse(client, model, domain, random_pick=True)
def find_random_new_lead(client):
model = "crm.lead"
domain = [("stage_id.name", "=", "New")]
return search_browse(client, model, domain, random_pick=True)
def find_random_picking_in(client):
model = "stock.picking"
domain = [("state", "=", "assigned")]
return search_browse(client, model, domain, random_pick=True)
def find_random_picking_wave(client):
model = "stock.picking.wave"
domain = [("state", "in", ("in_progress", "done"))]
return search_browse(client, model, domain, random_pick=True)
def find_random_picking_wave_running(client):
model = "stock.picking.wave"
domain = [("state", "=", "in_progress")]
return search_browse(client, model, domain, random_pick=True)
def find_random_product_purchase(client):
model = "product.product"
domain = [("purchase_ok", "=", True)]
return search_browse(client, model, domain, random_pick=True)
def find_random_product_sale(client):
model = "product.product"
domain = [("sale_ok", "=", True), ("type", "=", "product")]
return search_browse(client, model, domain, random_pick=True)
def find_random_purchase_order(client):
model = "purchase.order"
domain = [("invoice_status", "=", "to invoice")]
return search_browse(client, model, domain, random_pick=True)
def find_random_quotation(client):
model = "sale.order"
domain = [
("state", "=", "draft"),
("order_line", "!=", False),
("date_order", ">", "2020-07-20"),
]
return search_browse(client, model, domain, random_pick=True)
def find_random_rfq(client):
model = "purchase.order"
domain = [("state", "=", "draft")]
return search_browse(client, model, domain, random_pick=True)
def find_random_sale_order(client):
model = "sale.order"
domain = [("state", "=", "sale")]
return search_browse(client, model, domain, random_pick=True)
def find_random_supplier(client):
model = "res.partner"
domain = [("supplier", "=", True)]
return search_browse(client, model, domain, random_pick=True)
def find_random_customer(client):
model = "res.partner"
domain = [("customer", "=", True)]
return search_browse(client, model, domain, random_pick=True)
def find_random_pricelist(client):
model = "product.pricelist"
domain = []
return search_browse(client, model, domain, random_pick=True)
def find_random_template(client):
model = "sale.quote.template"
domain = []
return search_browse(client, model, domain, random_pick=True)
def find_random_task(client):
model = "project.task"
domain = [("user_id", "=", False)]
return search_browse(client, model, domain, random_pick=True)
def find_random_task_done(client):
model = "project.task"
domain = [("user_id", "!=", False), ("stage_id.name", "ilike", "work done")]
return search_browse(client, model, domain, random_pick=True)
def find_random_task_ready(client):
model = "project.task"
domain = [("user_id", "!=", False), ("stage_id.name", "ilike", "confirmed")]
return search_browse(client, model, domain, random_pick=True)
def find_random_vendor_bill_draft(client):
model = "account.invoice"
domain = [("type", "=", "in_invoice"), ("state", "=", "draft")]
return search_browse(client, model, domain, random_pick=True)
def find_random_vendor_bill_open(client):
model = "account.invoice"
domain = [("type", "=", "in_invoice"), ("state", "=", "open")]
return search_browse(client, model, domain, random_pick=True)
def find_random_won_lead(client):
model = "crm.lead"
domain = [
("stage_id.name", "=", "Won"),
("partner_id", "!=", False),
("order_ids", "=", False),
]
return search_browse(client, model, domain, random_pick=True)
def generate_street_address(client):
# generates "random" address str based on time
now = datetime.datetime.now()
usec = now.strftime("%f")
adr_num = int(usec[2:])
if adr_num < 1000:
adr_num += 1000
adr_num = str(adr_num)
sec = usec[0:2]
fsec = sec[0]
lsec = sec[1]
if fsec == "0":
if lsec == "0":
sec = "1"
lsec = "1"
else:
sec = lsec
if fsec == "1":
suff = "TH"
elif lsec == "1":
suff = "ST"
elif lsec == "2":
suff = "ND"
elif lsec == "3":
suff = "RD"
else:
suff = "TH"
if int(fsec) < 3:
adr_dir = "N"
elif int(fsec) < 6:
adr_dir = "W"
elif int(fsec) < 8:
adr_dir = "S"
else:
adr_dir = "E"
adr_ln = adr_num + " " + adr_dir + " " + sec + suff + " STREET"
return adr_ln