forked from nmbooker/oekit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
odoo.xmlid_of
executable file
·46 lines (37 loc) · 1.21 KB
/
odoo.xmlid_of
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
#! /usr/bin/env python
"""Get the XMLID of a particular record.
"""
import sys
import argparse
from oekit.oe_client_env import OEClientEnv
import logging
_logger = logging.getLogger(__name__)
def main(options):
"""Main program."""
logging.basicConfig(level=logging.INFO)
odoo = OEClientEnv().get_erppeek_client()
ir_model_data = odoo.model('ir.model.data')
model_name = options.model
res_id = options.numeric_id
xmlid = ir_model_data.browse([
('model', '=', model_name),
('res_id', '=', res_id),
])
if xmlid:
sys.stdout.write("%s\n" % (xmlid[0].complete_name,))
sys.exit(0)
else:
sys.stderr.write( "No XMLID found for %s,%d\n" % (model_name, res_id,) )
sys.exit(4)
return
def get_options():
"""Get options for the script."""
parser = argparse.ArgumentParser(
description="Print to STDOUT the XMLID of the given record. Returns error 4 and tells you on STDERR if no match.",
)
parser.add_argument('model', help='name of model')
parser.add_argument('numeric_id', type=int, help='numeric id of the record')
options = parser.parse_args()
return options
if __name__ == "__main__":
main(get_options())