[REF]Yaltik DSL : prefer lambdas, better indentations etc.

(quirks from hy2py)
This commit is contained in:
Fabien BOURGEOIS 2020-04-28 09:00:28 +02:00
parent 950f08fca6
commit 63152aabdb
2 changed files with 34 additions and 35 deletions

View File

@ -19,7 +19,7 @@
'name': 'Yaltik Odoo DSL base module and fns',
'summary': 'Yaltik Odoo Domain Specific Language base module and functions',
'description': """ Yaltik Odoo Domain Specific Language base module and functions """,
'version': '10.0.0.2.0',
'version': '10.0.0.2.1',
'category': 'Yaltik',
'author': 'Fabien Bourgeois',
'license': 'AGPL-3',

View File

@ -21,20 +21,21 @@ from .xml_base import xmlroot, xmln
# XML helpers functions and macros
def odoo(*args): return xmlroot(xmln('odoo', {}, *args))
odoo = lambda *args: xmlroot(xmln('odoo', {}, *args))
def data(*args):
""" Allow optional args on data tag """
if len(args) == 1:
return xmln('data', {}, *args)
return xmln('data', *args)
def function(*args): return xmln('function', *args)
def record(*args): return xmln('record', *args)
def form(*args): return xmln('form', *args)
def tree(*args): return xmln('tree', *args)
def search(*args): return xmln('search', *args)
function = lambda *args: xmln('function', *args)
record = lambda *args: xmln('record', *args)
form = lambda *args: xmln('form', *args)
tree = lambda *args: xmln('tree', *args)
search = lambda *args: xmln('search', *args)
def act_window(*args): return xmln('act_window', *args)
act_window = lambda *args: xmln('act_window', *args)
def act_window_model(model, attrs):
""" Build new act_window from model and args """
@ -45,7 +46,7 @@ def act_window_model(model, attrs):
attrs.update({'id': xmlid, 'name': name, 'res_model': model})
return act_window(attrs)
def menuitem(*args): return xmln('menuitem', *args)
menuitem = lambda *args: xmln('menuitem', *args)
def menuitem_model(model, attrs):
""" Build new menuitem from model and attrs """
@ -56,22 +57,22 @@ def menuitem_model(model, attrs):
return menuitem(attrs)
def group(*args): return xmln('group', *args)
def header(*args): return xmln('header', *args)
def footer(*args): return xmln('footer', *args)
def sheet(*args): return xmln('sheet', *args)
def button(*args): return xmln('button', *args)
def p(*args): return xmln('p', *args)
def xpath(*args): return xmln('xpath', *args)
def attribute(name, value): return xmln('attribute', {'name': name}, [value])
group = lambda *args: xmln('group', *args)
header = lambda *args: xmln('header', *args)
footer = lambda *args: xmln('footer', *args)
sheet = lambda *args: xmln('sheet', *args)
button = lambda *args: xmln('button', *args)
p = lambda *args: xmln('p', *args)
xpath = lambda *args: xmln('xpath', *args)
attribute = lambda name, value: xmln('attribute', {'name': name}, [value])
def field(*args): return xmln('field', *args)
def field_name(name): return field({'name': 'name'}, [name])
def field_model(model): return field({'name': 'model'}, [model])
def field_inherit(xmlid): return field({'name': 'inherit_id', 'ref': xmlid}, [])
def field_arch(*args): return field({'name': 'arch', 'type': 'xml'}, *args)
field = lambda *args: xmln('field', *args)
field_name = lambda name: field({'name': 'name'}, [name])
field_model = lambda model: field({'name': 'model'}, [model])
field_inherit = lambda xmlid: field({'name': 'inherit_id', 'ref': xmlid}, [])
field_arch = lambda *args: field({'name': 'arch', 'type': 'xml'}, *args)
def view(xmlid, children): return record({'id': xmlid, 'model': 'ir.ui.view'}, children)
view = lambda xmlid, children: record({'id': xmlid, 'model': 'ir.ui.view'}, children)
def view_def(xmlid, name, model, arch):
""" View and first fields simplification with record xmlid, name, targeted model """
@ -81,10 +82,8 @@ def view_new(view_type, model, arch):
""" View : new view definition, based on type (form, tree, ...) and model ID """
model_und = model.replace('.', '_')
model_cap = ' '.join([w.capitalize() for w in model.split('.')])
xmlid = '{:{}}'.format(model_und, '') + '_view_' + '{:{}}'.format(
view_type, '')
name = '{:{}}'.format(model_cap, '') + ' ' + '{:{}}'.format(view_type.
capitalize(), '')
xmlid = '{:{}}'.format(model_und, '') + '_view_' + '{:{}}'.format(view_type, '')
name = '{:{}}'.format(model_cap, '') + ' ' + '{:{}}'.format(view_type.capitalize(), '')
return view_def(xmlid=xmlid, name=name, model=model, arch=arch)
def view_inherit(filename, model, inherit, arch):
@ -96,21 +95,21 @@ def view_inherit(filename, model, inherit, arch):
module, '')
model_cap = ' '.join([w.capitalize() for w in model.split('.')])
name = '{:{}}'.format(model_cap, '') + ' Adaptations'
return view(xmlid, [field_name(name), field_model(model), field_inherit
(inherit), field_arch(arch)])
return view(xmlid, [field_name(name), field_model(model),
field_inherit(inherit), field_arch(arch)])
def actions_server_code(xmlid, name, modelref, code):
""" Server actions of type code """
return record({'id': xmlid, 'model': 'ir.actions.server'}, [
field_name(name), field({'name': 'model_id', 'ref': modelref}, [
]), field({'name': 'state'}, ['code']), field({'name': 'code'},
[code])])
]), field({'name': 'state'}, ['code']), field({'name': 'code'}, [code])])
def client_action_multi(xmlid, name, model, action):
""" Client action multi (ir.values), with own xmlid, name, targeted model
and action """
action = u"'ir.actions.server,%d'%" + '{:{}}'.format(action, '')
return record({'id': xmlid, 'model': 'ir.values'}, [field_name(name),
field({'name': 'key2', 'eval': u"'client_action_multi'"}, []),
field({'name': 'model', 'eval': u"'" + model + u"'"}, []), field
({'name': 'value', 'eval': action})])
return record({'id': xmlid, 'model': 'ir.values'},
[field_name(name),
field({'name': 'key2', 'eval': u"'client_action_multi'"}, []),
field({'name': 'model', 'eval': u"'" + model + u"'"}, []),
field({'name': 'value', 'eval': action})])