-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_fields_get.py
83 lines (71 loc) · 2.98 KB
/
model_fields_get.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
import xmlrpc.client
from dotenv import load_dotenv
import os
# Load environment variables from .env file
load_dotenv()
# Odoo server details
url = os.getenv('URL')
db = os.getenv('DB')
username = os.getenv('USERNAME')
api_key = os.getenv('API_KEY')
# Authenticate
common = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/common')
uid = common.authenticate(db, username, api_key, {})
if not uid:
print("Authentication failed.")
else:
print("Authenticated successfully. UID:", uid)
# Object endpoint
models = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/object')
# Specify the model you want to inspect
model_name = 'res.partner' # Replace with your model name
model_name = 'product.product' # Replace with your model name
model_name = 'sale.order' # Replace with your model name
model_name = 'res.partner' # Replace with your model name
model_name = 'res.country' # Replace with your model name
model_name = 'res.country.state' # Replace with your model name
model_name = 'res.currency' # Replace with your model name
model_name = 'website' # Replace with your model name
model_name = 'sale.order' # Replace with your model name
model_name = 'product.product' # Replace with your model name
model_name = 'sale.order.line' # Replace with your model name
model_name = 'product.template' # Replace with your model name
model_name = 'payment.provider' # Replace with your model name
model_name = 'product.attribute' # Replace with your model name
model_name = 'product.attribute.value' # Replace with your model name
model_name = 'product.template.attribute.line' # Replace with your model name
model_name = 'product.template.attribute.value' # Replace with your model name
model_name = 'stock.warehouse' # Replace with your model name
# create a model fields md file if it does not exist
# print(f"Creating {model_name}_fields.md")
# with open(f'{model_name}_fields.md', 'w') as f:
# f.write(f"#Fields of model: {model_name}\n\n")
# # Retrieve the fields of the model
# fields = models.execute_kw(
# db, uid, api_key,
# model_name, 'fields_get',
# [],
# {}
# )
# # Write the fields to the file
# for field_name, field_info in fields.items():
# f.write(f"#Field: {field_name}\n\n")
# for attr, value in field_info.items():
# #f.write(f" {attr}: {value}\n")
# #create a table
# f.write(f"|{attr}|{value}|\n\n")
# f.write("\n\n")
# print(f"Fields of model: {model_name}")
# exit()
# Retrieve the fields of the model
fields = models.execute_kw(
db, uid, api_key,
model_name, 'fields_get',
[],
{}
)
# Print the fields
for field_name, field_info in fields.items():
print(f"Field: {field_name}")
for attr, value in field_info.items():
print(f" {attr}: {value}")