yaltik_odoo_custom/yaltik_dsl/odoo.py

134 lines
6.3 KiB
Python

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# __coconut_hash__ = 0x76f908d8
# Compiled with Coconut version 1.4.3 [Ernest Scribbler]
""" Odoo XML DSL """
# Coconut Header: -------------------------------------------------------------
from __future__ import print_function, absolute_import, unicode_literals, division
import sys as _coconut_sys, os.path as _coconut_os_path
_coconut_file_path = _coconut_os_path.dirname(_coconut_os_path.abspath(__file__))
_coconut_cached_module = _coconut_sys.modules.get(b"__coconut__")
if _coconut_cached_module is not None and _coconut_os_path.dirname(_coconut_cached_module.__file__) != _coconut_file_path:
del _coconut_sys.modules[b"__coconut__"]
_coconut_sys.path.insert(0, _coconut_file_path)
from __coconut__ import *
from __coconut__ import _coconut, _coconut_MatchError, _coconut_igetitem, _coconut_base_compose, _coconut_forward_compose, _coconut_back_compose, _coconut_forward_star_compose, _coconut_back_star_compose, _coconut_forward_dubstar_compose, _coconut_back_dubstar_compose, _coconut_pipe, _coconut_back_pipe, _coconut_star_pipe, _coconut_back_star_pipe, _coconut_dubstar_pipe, _coconut_back_dubstar_pipe, _coconut_bool_and, _coconut_bool_or, _coconut_none_coalesce, _coconut_minus, _coconut_map, _coconut_partial, _coconut_get_function_match_error, _coconut_base_pattern_func, _coconut_addpattern, _coconut_sentinel, _coconut_assert, _coconut_mark_as_match
# Compiled Coconut: -----------------------------------------------------------
# -*- coding: utf-8 -*-
#
# Copyright 2019-2020 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .xml_base import xmlroot
from .xml_base import xmln
# XML helpers functions and macros
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)
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)
act_window = lambda *args: xmln('act_window', *args)
def act_window_model(model, attrs):
""" Build new act_window from model and args """
model_und = model.replace('.', '_')
model_cap = ' '.join([w.capitalize() for w in model.split('.')])
xmlid = '{:{}}'.format(model_und, '') + '_view_action'
name = '{:{}}'.format(model_cap, '') + ' Action'
attrs.update({'id': xmlid, 'name': name, 'res_model': model})
return act_window(attrs)
menuitem = lambda *args: xmln('menuitem', *args)
def menuitem_model(model, attrs):
""" Build new menuitem from model and attrs """
model_und = model.replace('.', '_')
actionid = '{:{}}'.format(model_und, '') + '_view_action'
xmlid = '{:{}}'.format(model_und, '') + '_men'
attrs.update({'id': xmlid, 'action': actionid})
return menuitem(attrs)
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])
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)
filter = lambda *args: xmln('filter', *args)
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 """
return view(xmlid, [field_name(name), field_model(model), field_arch(arch)])
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(), '')
return view_def(xmlid=xmlid, name=name, model=model, arch=arch)
def view_inherit(filename, model, inherit, arch):
""" Inherited View simplification with name of the record, xmlid for model
and inherited view """
module = filename.split('.')[2]
inherited = inherit.split('.')[1]
xmlid = '{:{}}'.format(inherited, '') + '_inherit_' + '{:{}}'.format(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)])
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])])
def client_action_multi(xmlid, name, model, action):
""" Client action multi (ir.values), with own xmlid, name, targeted model
and action """
action = "'ir.actions.server,%d'%" + '{:{}}'.format(action, '')
return record({'id': xmlid, 'model': 'ir.values'}, [field_name(name), field({'name': 'key2', 'eval': "'client_action_multi'"}, []), field({'name': 'model', 'eval': "'" + model + "'"}, []), field({'name': 'value', 'eval': action})])