[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', 'name': 'Yaltik Odoo DSL base module and fns',
'summary': 'Yaltik Odoo Domain Specific Language base module and functions', 'summary': 'Yaltik Odoo Domain Specific Language base module and functions',
'description': """ 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', 'category': 'Yaltik',
'author': 'Fabien Bourgeois', 'author': 'Fabien Bourgeois',
'license': 'AGPL-3', 'license': 'AGPL-3',

View File

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