Skip to content

Commit cf40cb4

Browse files
committed
create currency rate
1 parent f6cf58a commit cf40cb4

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

perf_currency_rate.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
11
import random
22
import datetime
33

4-
from itertools import product, cycle
4+
from itertools import product
55

6-
from faker import Faker
6+
from dateutil.relativedelta import relativedelta
77

8-
fake = Faker()
8+
# from faker import Faker
9+
10+
# fake = Faker()
911

1012
# faker -r=1000 -s=',' name email ean8 vat
1113

1214
currencies_ids = list(range(1, 8))
13-
company_ids = list(range(1, 10))
14-
15-
iter_currencies_company = cycle(product(currencies_ids, company_ids))
16-
17-
today = datetime.date.today()
18-
19-
# TODO
15+
company_ids = list(range(1, 10)) + ['NULL']
16+
# +- 10 years of data
17+
days = [datetime.date.today()]
18+
for __ in range(10 * 365):
19+
days.append(days[-1] - relativedelta(days=1))
2020

21+
# \copy res_currency_rate(currency_id, name, company_id, rate) FROM '/home/odoo/Documents/dev/odoo_scripts/currency_rate.csv' (FORMAT csv, DELIMITER ',', NULL 'NULL');
2122
with open("currency_rate.csv", "wt") as f:
22-
for i in range(100_000):
23-
24-
currency_id = next(currency_iter)
25-
26-
date
27-
28-
line = ",".join([currency_id, date, company_id])
23+
for currency_id, company_id, date in product(currencies_ids, company_ids, days):
24+
rate = random.random() * 10
25+
line = ",".join([str(currency_id), str(date), str(company_id), str(rate)])
2926
f.write(f"{line}\n")
3027

31-
3228
"""
3329
3430
SELECT DISTINCT ON ("res_currency_rate"."currency_id")
3531
"res_currency_rate"."currency_id", "res_currency_rate"."rate"
3632
FROM "res_currency_rate"
37-
WHERE "res_currency_rate"."company_id" IS NULL OR "res_currency_rate"."company_id" = 1
33+
WHERE ("res_currency_rate"."company_id" IS NULL OR "res_currency_rate"."company_id" = 1)
34+
AND "res_currency_rate"."currency_id" = 5
3835
ORDER BY
3936
"res_currency_rate"."currency_id",
4037
"res_currency_rate"."company_id",
@@ -78,5 +75,5 @@
7875
)
7976
FROM
8077
"res_currency"
81-
WHERE "res_currency" = 10
78+
WHERE "res_currency"."id" = 5
8279
"""

0 commit comments

Comments
 (0)