[WIP][BROKEN]Yaltik DSL : no ported yet from coco
This commit is contained in:
parent
143492e58b
commit
9fa300f77e
@ -1,26 +1,3 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
# __coconut_hash__ = 0xb0af9f53
|
||||
|
||||
# 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>
|
||||
@ -38,192 +15,113 @@ from __coconut__ import _coconut, _coconut_MatchError, _coconut_igetitem, _cocon
|
||||
# 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/>.
|
||||
|
||||
""" Odoo XML DSL """
|
||||
|
||||
|
||||
from typing import Text
|
||||
from typing import Dict
|
||||
from xml_base import XMLAttrs
|
||||
from xml_base import XMLDictElement
|
||||
from xml_base import xmlroot
|
||||
from xml_base import xmln
|
||||
from typing import Text, Dict
|
||||
from xml_base import XMLAttrs, XMLDictElement, xmlroot, xmln
|
||||
|
||||
# XML helpers functions and macros
|
||||
|
||||
# Odoo root XML Node
|
||||
def odoo(children # type: Dict
|
||||
):
|
||||
# type: (...) -> ET.Element
|
||||
return (xmlroot)({'tag': 'odoo', 'attrs': {}, 'children': children})
|
||||
def odoo(children: Dict) -> ET.Element = {'tag': 'odoo', 'attrs': {}, 'children': children} |> xmlroot
|
||||
|
||||
# Special data Node
|
||||
def data(*args):
|
||||
""" Allow optional args on data tag """
|
||||
if (len)(args) == 1:
|
||||
args = (list)(args)
|
||||
args.insert(0, {})
|
||||
if args |> len == 1:
|
||||
{} |> args.insert$(0) where: args = args |> list
|
||||
return xmln('data', *args)
|
||||
|
||||
# Aliases
|
||||
def function(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('function', *args)
|
||||
def record(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('record', *args)
|
||||
def form(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('form', *args)
|
||||
def tree(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('tree', *args)
|
||||
def search(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('search', *args)
|
||||
def function(*args) -> XMLDictElement = xmln('function', *args)
|
||||
def record(*args) -> XMLDictElement = xmln('record', *args)
|
||||
def form(*args) -> XMLDictElement = xmln('form', *args)
|
||||
def tree(*args) -> XMLDictElement = xmln('tree', *args)
|
||||
def search(*args) -> XMLDictElement = xmln('search', *args)
|
||||
|
||||
# Actions
|
||||
def act_window(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('act_window', *args)
|
||||
def act_window_model(model, # type: Text
|
||||
attrs # type: XMLAttrs
|
||||
):
|
||||
# type: (...) -> XMLDictElement
|
||||
def act_window(*args) -> XMLDictElement = xmln('act_window', *args)
|
||||
def act_window_model(model: Text, attrs: XMLAttrs) -> XMLDictElement:
|
||||
""" Build new act_window from model and args """
|
||||
xmlid = '%s_view_action' % ((model.replace)(*('.', '_')))
|
||||
name = '%s Action' % ((' '.join)((list)(map(lambda _=None: _.capitalize(), (model.split)('.')))))
|
||||
attrs_clone = attrs.copy() # Avoid side-effect
|
||||
(attrs_clone.update)({'id': xmlid, 'name': name, 'res_model': model})
|
||||
xmlid = '%s_view_action' % (('.', '_') |*> model.replace)
|
||||
name = '%s Action' % ('.' |> model.split |> map$(-> _.capitalize()) |> list |> ' '.join)
|
||||
attrs_clone = attrs.copy() # Avoid side-effect
|
||||
{'id': xmlid, 'name': name, 'res_model': model} |> attrs_clone.update
|
||||
return act_window(attrs_clone)
|
||||
|
||||
def action_server_code(xmlid, # type: Text
|
||||
name, # type: Text
|
||||
modelref, # type: Text
|
||||
code # type: Text
|
||||
):
|
||||
# type: (...) -> XMLDictElement
|
||||
def action_server_code(xmlid: Text, name: Text, modelref: Text, code: Text) -> XMLDictElement:
|
||||
""" Server actions of type code """
|
||||
children = [(field_name)(name), (field)(*({'name': 'model_id', 'ref': modelref}, [])), (field)(*({'name': 'state'}, ['code'])), (field)(*({'name': 'code'}, [code]))]
|
||||
return (record)(*({'id': xmlid, 'model': 'ir.actions.server'}, children))
|
||||
children = [name |> field_name,
|
||||
({'name': 'model_id', 'ref': modelref}, []) |*> field,
|
||||
({'name': 'state'}, ['code']) |*> field,
|
||||
({'name': 'code'}, [code]) |*> field]
|
||||
return ({'id': xmlid, 'model': 'ir.actions.server'}, children) |*> record
|
||||
|
||||
def client_action_multi(xmlid, # type: Text
|
||||
name, # type: Text
|
||||
model, # type: Text
|
||||
action # type: Text
|
||||
):
|
||||
# type: (...) -> XMLDictElement
|
||||
def client_action_multi(xmlid: Text, name: Text, model: Text, action: Text) -> XMLDictElement:
|
||||
""" Client action multi (ir.values), with own xmlid, name, targeted model
|
||||
and action """
|
||||
action = ("'ir.actions.server,%d'%{}".format)(action)
|
||||
children = [(field_name)(name), (field)({'name': 'key2', 'eval': "'client_action_multi'"}), (field)({'name': 'model', 'eval': "'%s'" % model}), (field)({'name': 'value', 'eval': action})]
|
||||
return (record)(*({'id': xmlid, 'model': 'ir.values'}, children))
|
||||
action = action |> "'ir.actions.server,%d'%{}".format
|
||||
children = [name |> field_name,
|
||||
{'name': 'key2', 'eval': "'client_action_multi'"} |> field,
|
||||
{'name': 'model', 'eval': "'%s'" % model} |> field,
|
||||
{'name': 'value', 'eval': action} |> field]
|
||||
return ({'id': xmlid, 'model': 'ir.values'}, children) |*> record
|
||||
|
||||
# Menus
|
||||
def menuitem(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('menuitem', *args)
|
||||
def menuitem_model(model, # type: Text
|
||||
attrs # type: XMLAttrs
|
||||
):
|
||||
# type: (...) -> XMLDictElement
|
||||
def menuitem(*args) -> XMLDictElement = xmln('menuitem', *args)
|
||||
def menuitem_model(model: Text, attrs: XMLAttrs) -> XMLDictElement:
|
||||
""" Build new menuitem from model and attrs """
|
||||
model_und = (model.replace)(*('.', '_'))
|
||||
model_und = ('.', '_') |*> model.replace
|
||||
xmlid = '%s_menu' % model_und
|
||||
actionid = '%s_view_action' % model_und
|
||||
attrs_clone = attrs.copy() # Avoid side-effect
|
||||
(attrs_clone.update)({'id': xmlid, 'action': actionid})
|
||||
attrs_clone = attrs.copy() # Avoid side-effect
|
||||
{'id': xmlid, 'action': actionid} |> attrs_clone.update
|
||||
return menuitem(attrs_clone)
|
||||
|
||||
# Form aliases
|
||||
def group(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('group', *args)
|
||||
def header(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('header', *args)
|
||||
def footer(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('footer', *args)
|
||||
def sheet(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('sheet', *args)
|
||||
def button(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('button', *args)
|
||||
def p(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('p', *args)
|
||||
def xpath(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('xpath', *args)
|
||||
def attribute(name, # type: Text
|
||||
value # type: Text
|
||||
):
|
||||
# type: (...) -> XMLDictElement
|
||||
return (xmln)(*('attribute', {'name': name}, [value]))
|
||||
def group(*args) -> XMLDictElement = xmln('group', *args)
|
||||
def header(*args) -> XMLDictElement = xmln('header', *args)
|
||||
def footer(*args) -> XMLDictElement = xmln('footer', *args)
|
||||
def sheet(*args) -> XMLDictElement = xmln('sheet', *args)
|
||||
def button(*args) -> XMLDictElement = xmln('button', *args)
|
||||
def p(*args) -> XMLDictElement = xmln('p', *args)
|
||||
def xpath(*args) -> XMLDictElement = xmln('xpath', *args)
|
||||
def attribute(name: Text, value: Text) -> XMLDictElement:
|
||||
return ('attribute', {'name': name}, [value]) |*> xmln
|
||||
|
||||
# Fields
|
||||
def field(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('field', *args)
|
||||
def field_name(name # type: Text
|
||||
):
|
||||
# type: (...) -> XMLDictElement
|
||||
return (field)(*({'name': 'name'}, [name]))
|
||||
def field_model(model # type: Text
|
||||
):
|
||||
# type: (...) -> XMLDictElement
|
||||
return (field)(*({'name': 'model'}, [model]))
|
||||
def field_inherit(xmlid # type: Text
|
||||
):
|
||||
# type: (...) -> XMLDictElement
|
||||
return (field)(*({'name': 'inherit_id', 'ref': xmlid}, []))
|
||||
def field_arch(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return ((_coconut.functools.partial(_coconut.functools.partial, field))({'name': 'arch', 'type': 'xml'}))(*args)
|
||||
def field(*args) -> XMLDictElement = xmln('field', *args)
|
||||
def field_name(name: Text) -> XMLDictElement = ({'name': 'name'}, [name]) |*> field
|
||||
def field_model(model: Text) -> XMLDictElement = ({'name': 'model'}, [model]) |*> field
|
||||
def field_inherit(xmlid: Text) -> XMLDictElement:
|
||||
return ({'name': 'inherit_id', 'ref': xmlid}, []) |*> field
|
||||
def field_arch(*args) -> XMLDictElement = {'name': 'arch', 'type': 'xml'} |> field$ <*| args
|
||||
|
||||
# Search
|
||||
def filter(*args):
|
||||
# type: (...) -> XMLDictElement
|
||||
return xmln('filter', *args)
|
||||
def filter(*args) -> XMLDictElement = xmln('filter', *args)
|
||||
|
||||
# Views
|
||||
def view(xmlid, # type: Text
|
||||
children # type: List
|
||||
):
|
||||
# type: (...) -> XMLDictElement
|
||||
return (record)(*({'id': xmlid, 'model': 'ir.ui.view'}, children))
|
||||
def view(xmlid: Text, children: List) -> XMLDictElement:
|
||||
return ({'id': xmlid, 'model': 'ir.ui.view'}, children) |*> record
|
||||
|
||||
def view_def(xmlid, # type: Text
|
||||
name, # type: Text
|
||||
model, # type: Text
|
||||
arch # type: List
|
||||
):
|
||||
# type: (...) -> XMLDictElement
|
||||
return (view)(*(xmlid, [field_name(name), field_model(model), field_arch(arch)]))
|
||||
def view_def(xmlid: Text, name: Text, model: Text, arch: List) -> XMLDictElement:
|
||||
return (xmlid, [field_name(name), field_model(model), field_arch(arch)]) |*> view
|
||||
|
||||
def view_new(view_type, # type: Text
|
||||
model, # type: Text
|
||||
arch # type: List
|
||||
):
|
||||
# type: (...) -> XMLDictElement
|
||||
def view_new(view_type: Text, model: Text, arch: List) -> XMLDictElement:
|
||||
""" View : new view definition, based on type (form, tree, ...) and model ID """
|
||||
model_und = (model.replace)(*('.', '_'))
|
||||
model_cap = ((' '.join)((list)(map(lambda _=None: _.capitalize(), (model.split)('.')))))
|
||||
model_und = ('.', '_') |*> model.replace
|
||||
model_cap = ('.' |> model.split |> map$(-> _.capitalize()) |> list |> ' '.join)
|
||||
xmlid = "%s_view_%s" % (model_und, view_type)
|
||||
name = (' '.join)((model_cap, view_type.capitalize()))
|
||||
return (view_def)(*(xmlid, name, model, arch))
|
||||
name = (model_cap, view_type.capitalize()) |> ' '.join
|
||||
return (xmlid, name, model, arch) |*> view_def
|
||||
|
||||
def view_inherit(filename, # type: Text
|
||||
model, # type: Text
|
||||
inherit, # type: Text
|
||||
arch # type: List
|
||||
):
|
||||
# type: (...) -> XMLDictElement
|
||||
def view_inherit(filename: Text, model: Text, inherit: Text, arch: List) -> XMLDictElement:
|
||||
""" Inherited View simplification with name of the record, xmlid for model
|
||||
and inherited view """
|
||||
module = ((filename.split)('.'))[2]
|
||||
inherited = ((inherit.split)('.'))[1]
|
||||
module = '.' |> filename.split |> .[2]
|
||||
inherited = '.' |> inherit.split |> .[1]
|
||||
xmlid = '%s_inherit_%s' % (inherited, module)
|
||||
model_cap = ((' '.join)((list)(map(lambda _=None: _.capitalize(), (model.split)('.')))))
|
||||
model_cap = ('.' |> model.split |> map$(-> _.capitalize()) |> list |> ' '.join)
|
||||
name = '%s Adaptations' % model_cap
|
||||
return view(xmlid, [(field_name)(name), (field_model)(model), (field_inherit)(inherit), (field_arch)(arch)])
|
||||
return view(xmlid, [name |> field_name, model |> field_model,
|
||||
inherit |> field_inherit, arch |> field_arch])
|
||||
|
@ -1,26 +1,3 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
# __coconut_hash__ = 0xb59e6156
|
||||
|
||||
# Compiled with Coconut version 1.4.3 [Ernest Scribbler]
|
||||
|
||||
""" Odoo Helpers tests """
|
||||
|
||||
# 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 2020 Fabien Bourgeois <fabien@yaltik.com>
|
||||
@ -38,7 +15,7 @@ from __coconut__ import _coconut, _coconut_MatchError, _coconut_igetitem, _cocon
|
||||
# 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/>.
|
||||
|
||||
|
||||
""" Odoo Helpers tests """
|
||||
|
||||
import unittest
|
||||
import xml.etree.ElementTree as ET
|
||||
@ -50,207 +27,208 @@ class TestOdooBase(unittest.TestCase):
|
||||
|
||||
def test_odoo(self):
|
||||
element = od.odoo([])
|
||||
(self.assertIsInstance)(element, ET.Element)
|
||||
(self.assertEquals)(element.tag, 'odoo')
|
||||
element `self.assertIsInstance` ET.Element
|
||||
element.tag `self.assertEquals` 'odoo'
|
||||
|
||||
def test_data(self):
|
||||
element = od.data([])
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'data')
|
||||
(self.assertEquals)(element.attrs, {})
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'data'
|
||||
element.attrs `self.assertEquals` {}
|
||||
|
||||
element = od.data({"one": "attribute"}, [])
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'data')
|
||||
(self.assertEquals)(element.attrs, {"one": "attribute"})
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'data'
|
||||
element.attrs `self.assertEquals` {"one": "attribute"}
|
||||
|
||||
def test_aliases(self):
|
||||
""" Test simple aliases to xmln """
|
||||
element = od.record({"one": "attribute"}, 'A child')
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'record')
|
||||
(self.assertEquals)(element.attrs, {"one": "attribute"})
|
||||
(self.assertEquals)(element.children, ['A child'])
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'record'
|
||||
element.attrs `self.assertEquals` {"one": "attribute"}
|
||||
element.children `self.assertEquals` ['A child']
|
||||
|
||||
element = od.tree()
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'tree')
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'tree'
|
||||
|
||||
def test_act_window_model(self):
|
||||
element = (od.act_window_model)(*('sample.model', {'view_type': 'form'}))
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'act_window')
|
||||
(self.assertEquals)(element.attrs['view_type'], 'form')
|
||||
(self.assertEquals)(element.attrs['id'], 'sample_model_view_action')
|
||||
(self.assertEquals)(element.attrs['res_model'], 'sample.model')
|
||||
(self.assertEquals)(element.attrs['name'], 'Sample Model Action')
|
||||
element = ('sample.model', {'view_type': 'form'}) |*> od.act_window_model
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'act_window'
|
||||
element.attrs['view_type'] `self.assertEquals` 'form'
|
||||
element.attrs['id'] `self.assertEquals` 'sample_model_view_action'
|
||||
element.attrs['res_model'] `self.assertEquals` 'sample.model'
|
||||
element.attrs['name'] `self.assertEquals` 'Sample Model Action'
|
||||
|
||||
def test_menunitem_model(self):
|
||||
element = (od.menuitem_model)(*('sample.model', {'groups': 'base.user_employee'}))
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'menuitem')
|
||||
(self.assertEquals)(element.attrs['groups'], 'base.user_employee')
|
||||
(self.assertEquals)(element.attrs['id'], 'sample_model_menu')
|
||||
(self.assertEquals)(element.attrs['action'], 'sample_model_view_action')
|
||||
element = ('sample.model', {'groups': 'base.user_employee'}) |*> od.menuitem_model
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'menuitem'
|
||||
element.attrs['groups'] `self.assertEquals` 'base.user_employee'
|
||||
element.attrs['id'] `self.assertEquals` 'sample_model_menu'
|
||||
element.attrs['action'] `self.assertEquals` 'sample_model_view_action'
|
||||
|
||||
def test_attribute(self):
|
||||
element = od.attribute('invisible', "1")
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'attribute')
|
||||
(self.assertEquals)(element.attrs['name'], 'invisible')
|
||||
(self.assertEquals)(element.children, ["1"])
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'attribute'
|
||||
element.attrs['name'] `self.assertEquals` 'invisible'
|
||||
element.children `self.assertEquals` ["1"]
|
||||
|
||||
def test_fields(self):
|
||||
element = od.field({"one": "attribute"}, 'A child')
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'field')
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'field'
|
||||
|
||||
element = (od.field_name)('A name')
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'field')
|
||||
(self.assertEquals)(element.attrs['name'], 'name')
|
||||
(self.assertEquals)(element.children, ['A name'])
|
||||
element = 'A name' |> od.field_name
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'field'
|
||||
element.attrs['name'] `self.assertEquals` 'name'
|
||||
element.children `self.assertEquals` ['A name']
|
||||
|
||||
element = (od.field_model)('sample.model')
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'field')
|
||||
(self.assertEquals)(element.attrs['name'], 'model')
|
||||
(self.assertEquals)(element.children, ['sample.model'])
|
||||
element = 'sample.model' |> od.field_model
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'field'
|
||||
element.attrs['name'] `self.assertEquals` 'model'
|
||||
element.children `self.assertEquals` ['sample.model']
|
||||
|
||||
element = (od.field_inherit)('module.xml_view')
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'field')
|
||||
(self.assertEquals)(element.attrs['name'], 'inherit_id')
|
||||
(self.assertEquals)(element.attrs['ref'], 'module.xml_view')
|
||||
(self.assertFalse)(element.children)
|
||||
element = 'module.xml_view' |> od.field_inherit
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'field'
|
||||
element.attrs['name'] `self.assertEquals` 'inherit_id'
|
||||
element.attrs['ref'] `self.assertEquals` 'module.xml_view'
|
||||
element.children |> self.assertFalse
|
||||
|
||||
element = od.field_arch()
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'field')
|
||||
(self.assertEquals)(element.attrs['name'], 'arch')
|
||||
(self.assertEquals)(element.attrs['type'], 'xml')
|
||||
(self.assertFalse)(element.children)
|
||||
element = od.field_arch()
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'field'
|
||||
element.attrs['name'] `self.assertEquals` 'arch'
|
||||
element.attrs['type'] `self.assertEquals` 'xml'
|
||||
element.children |> self.assertFalse
|
||||
|
||||
def test_view(self):
|
||||
element = od.view('view_xmlid', [])
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'record')
|
||||
(self.assertEquals)(element.attrs['id'], 'view_xmlid')
|
||||
(self.assertEquals)(element.attrs['model'], 'ir.ui.view')
|
||||
(self.assertFalse)(element.children)
|
||||
element = od.view('view_xmlid', [])
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'record'
|
||||
element.attrs['id'] `self.assertEquals` 'view_xmlid'
|
||||
element.attrs['model'] `self.assertEquals` 'ir.ui.view'
|
||||
element.children |> self.assertFalse
|
||||
|
||||
def test_view_def(self):
|
||||
element = od.view_def('view_xmlid', 'View', 'sample.model', [])
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'record')
|
||||
(self.assertEquals)(element.attrs['id'], 'view_xmlid')
|
||||
(self.assertEquals)(element.attrs['model'], 'ir.ui.view')
|
||||
(self.assertEquals)(((len)(element.children)), 3)
|
||||
(self.assertIsInstance)(element.children[0], XMLDictElement)
|
||||
(self.assertEquals)(element.children[0].tag, 'field')
|
||||
(self.assertEquals)(element.children[0].attrs['name'], 'name')
|
||||
(self.assertEquals)(element.children[0].children, ['View'])
|
||||
(self.assertIsInstance)(element.children[1], XMLDictElement)
|
||||
(self.assertEquals)(element.children[1].tag, 'field')
|
||||
(self.assertEquals)(element.children[1].attrs['name'], 'model')
|
||||
(self.assertEquals)(element.children[1].children, ['sample.model'])
|
||||
(self.assertIsInstance)(element.children[2], XMLDictElement)
|
||||
(self.assertEquals)(element.children[2].tag, 'field')
|
||||
(self.assertEquals)(element.children[2].attrs['name'], 'arch')
|
||||
(self.assertEquals)(element.children[2].attrs['type'], 'xml')
|
||||
(self.assertFalse)(element.children[2].children)
|
||||
element = od.view_def('view_xmlid', 'View', 'sample.model', [])
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'record'
|
||||
element.attrs['id'] `self.assertEquals` 'view_xmlid'
|
||||
element.attrs['model'] `self.assertEquals` 'ir.ui.view'
|
||||
(element.children |> len) `self.assertEquals` 3
|
||||
element.children[0] `self.assertIsInstance` XMLDictElement
|
||||
element.children[0].tag `self.assertEquals` 'field'
|
||||
element.children[0].attrs['name'] `self.assertEquals` 'name'
|
||||
element.children[0].children `self.assertEquals` ['View']
|
||||
element.children[1] `self.assertIsInstance` XMLDictElement
|
||||
element.children[1].tag `self.assertEquals` 'field'
|
||||
element.children[1].attrs['name'] `self.assertEquals` 'model'
|
||||
element.children[1].children `self.assertEquals` ['sample.model']
|
||||
element.children[2] `self.assertIsInstance` XMLDictElement
|
||||
element.children[2].tag `self.assertEquals` 'field'
|
||||
element.children[2].attrs['name'] `self.assertEquals` 'arch'
|
||||
element.children[2].attrs['type'] `self.assertEquals` 'xml'
|
||||
element.children[2].children |> self.assertFalse
|
||||
|
||||
def test_view_new(self):
|
||||
element = od.view_new('tree', 'sample.model', [])
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'record')
|
||||
(self.assertEquals)(element.attrs['id'], 'sample_model_view_tree')
|
||||
(self.assertEquals)(element.attrs['model'], 'ir.ui.view')
|
||||
(self.assertEquals)(((len)(element.children)), 3)
|
||||
(self.assertIsInstance)(element.children[0], XMLDictElement)
|
||||
(self.assertEquals)(element.children[0].tag, 'field')
|
||||
(self.assertEquals)(element.children[0].attrs['name'], 'name')
|
||||
(self.assertEquals)(element.children[0].children, ['Sample Model Tree'])
|
||||
(self.assertIsInstance)(element.children[1], XMLDictElement)
|
||||
(self.assertEquals)(element.children[1].tag, 'field')
|
||||
(self.assertEquals)(element.children[1].attrs['name'], 'model')
|
||||
(self.assertEquals)(element.children[1].children, ['sample.model'])
|
||||
(self.assertIsInstance)(element.children[2], XMLDictElement)
|
||||
(self.assertEquals)(element.children[2].tag, 'field')
|
||||
(self.assertEquals)(element.children[2].attrs['name'], 'arch')
|
||||
(self.assertEquals)(element.children[2].attrs['type'], 'xml')
|
||||
(self.assertFalse)(element.children[2].children)
|
||||
element = od.view_new('tree', 'sample.model', [])
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'record'
|
||||
element.attrs['id'] `self.assertEquals` 'sample_model_view_tree'
|
||||
element.attrs['model'] `self.assertEquals` 'ir.ui.view'
|
||||
(element.children |> len) `self.assertEquals` 3
|
||||
element.children[0] `self.assertIsInstance` XMLDictElement
|
||||
element.children[0].tag `self.assertEquals` 'field'
|
||||
element.children[0].attrs['name'] `self.assertEquals` 'name'
|
||||
element.children[0].children `self.assertEquals` ['Sample Model Tree']
|
||||
element.children[1] `self.assertIsInstance` XMLDictElement
|
||||
element.children[1].tag `self.assertEquals` 'field'
|
||||
element.children[1].attrs['name'] `self.assertEquals` 'model'
|
||||
element.children[1].children `self.assertEquals` ['sample.model']
|
||||
element.children[2] `self.assertIsInstance` XMLDictElement
|
||||
element.children[2].tag `self.assertEquals` 'field'
|
||||
element.children[2].attrs['name'] `self.assertEquals` 'arch'
|
||||
element.children[2].attrs['type'] `self.assertEquals` 'xml'
|
||||
element.children[2].children |> self.assertFalse
|
||||
|
||||
def test_view_inherit(self):
|
||||
element = od.view_inherit('odoo.addons.module', 'sample.model', 'parent.view', [])
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'record')
|
||||
(self.assertEquals)(element.attrs['id'], 'view_inherit_module')
|
||||
(self.assertEquals)(element.attrs['model'], 'ir.ui.view')
|
||||
(self.assertEquals)(((len)(element.children)), 4)
|
||||
(self.assertIsInstance)(element.children[0], XMLDictElement)
|
||||
(self.assertEquals)(element.children[0].tag, 'field')
|
||||
(self.assertEquals)(element.children[0].attrs['name'], 'name')
|
||||
(self.assertEquals)(element.children[0].children, ['Sample Model Adaptations'])
|
||||
(self.assertIsInstance)(element.children[1], XMLDictElement)
|
||||
(self.assertEquals)(element.children[1].tag, 'field')
|
||||
(self.assertEquals)(element.children[1].attrs['name'], 'model')
|
||||
(self.assertEquals)(element.children[1].children, ['sample.model'])
|
||||
(self.assertIsInstance)(element.children[2], XMLDictElement)
|
||||
(self.assertEquals)(element.children[2].tag, 'field')
|
||||
(self.assertEquals)(element.children[2].attrs['name'], 'inherit_id')
|
||||
(self.assertFalse)(element.children[2].children)
|
||||
(self.assertIsInstance)(element.children[3], XMLDictElement)
|
||||
(self.assertEquals)(element.children[3].tag, 'field')
|
||||
(self.assertEquals)(element.children[3].attrs['name'], 'arch')
|
||||
(self.assertEquals)(element.children[3].attrs['type'], 'xml')
|
||||
(self.assertFalse)(element.children[3].children)
|
||||
element = od.view_inherit('odoo.addons.module', 'sample.model', 'parent.view', [])
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'record'
|
||||
element.attrs['id'] `self.assertEquals` 'view_inherit_module'
|
||||
element.attrs['model'] `self.assertEquals` 'ir.ui.view'
|
||||
(element.children |> len) `self.assertEquals` 4
|
||||
element.children[0] `self.assertIsInstance` XMLDictElement
|
||||
element.children[0].tag `self.assertEquals` 'field'
|
||||
element.children[0].attrs['name'] `self.assertEquals` 'name'
|
||||
element.children[0].children `self.assertEquals` ['Sample Model Adaptations']
|
||||
element.children[1] `self.assertIsInstance` XMLDictElement
|
||||
element.children[1].tag `self.assertEquals` 'field'
|
||||
element.children[1].attrs['name'] `self.assertEquals` 'model'
|
||||
element.children[1].children `self.assertEquals` ['sample.model']
|
||||
element.children[2] `self.assertIsInstance` XMLDictElement
|
||||
element.children[2].tag `self.assertEquals` 'field'
|
||||
element.children[2].attrs['name'] `self.assertEquals` 'inherit_id'
|
||||
element.children[2].children |> self.assertFalse
|
||||
element.children[3] `self.assertIsInstance` XMLDictElement
|
||||
element.children[3].tag `self.assertEquals` 'field'
|
||||
element.children[3].attrs['name'] `self.assertEquals` 'arch'
|
||||
element.children[3].attrs['type'] `self.assertEquals` 'xml'
|
||||
element.children[3].children |> self.assertFalse
|
||||
|
||||
def test_action_server_code(self):
|
||||
element = od.action_server_code('sample.xmlid', 'Code', 'sample.model', '''record.do_something()''')
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'record')
|
||||
(self.assertEquals)(element.attrs['id'], 'sample.xmlid')
|
||||
(self.assertEquals)(element.attrs['model'], 'ir.actions.server')
|
||||
(self.assertEquals)(((len)(element.children)), 4)
|
||||
(self.assertIsInstance)(element.children[0], XMLDictElement)
|
||||
(self.assertEquals)(element.children[0].tag, 'field')
|
||||
(self.assertEquals)(element.children[0].attrs['name'], 'name')
|
||||
(self.assertEquals)(element.children[0].children, ['Code'])
|
||||
(self.assertIsInstance)(element.children[1], XMLDictElement)
|
||||
(self.assertEquals)(element.children[1].tag, 'field')
|
||||
(self.assertEquals)(element.children[1].attrs['name'], 'model_id')
|
||||
(self.assertEquals)(element.children[1].attrs['ref'], 'sample.model')
|
||||
(self.assertFalse)(element.children[1].children)
|
||||
(self.assertEquals)(element.children[2].tag, 'field')
|
||||
(self.assertEquals)(element.children[2].attrs['name'], 'state')
|
||||
(self.assertEquals)(element.children[2].children, ['code'])
|
||||
(self.assertEquals)(element.children[3].tag, 'field')
|
||||
(self.assertEquals)(element.children[3].attrs['name'], 'code')
|
||||
(self.assertEquals)(element.children[3].children, ['record.do_something()'])
|
||||
element = od.action_server_code('sample.xmlid', 'Code', 'sample.model',
|
||||
'''record.do_something()''')
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'record'
|
||||
element.attrs['id'] `self.assertEquals` 'sample.xmlid'
|
||||
element.attrs['model'] `self.assertEquals` 'ir.actions.server'
|
||||
(element.children |> len) `self.assertEquals` 4
|
||||
element.children[0] `self.assertIsInstance` XMLDictElement
|
||||
element.children[0].tag `self.assertEquals` 'field'
|
||||
element.children[0].attrs['name'] `self.assertEquals` 'name'
|
||||
element.children[0].children `self.assertEquals` ['Code']
|
||||
element.children[1] `self.assertIsInstance` XMLDictElement
|
||||
element.children[1].tag `self.assertEquals` 'field'
|
||||
element.children[1].attrs['name'] `self.assertEquals` 'model_id'
|
||||
element.children[1].attrs['ref'] `self.assertEquals` 'sample.model'
|
||||
element.children[1].children |> self.assertFalse
|
||||
element.children[2].tag `self.assertEquals` 'field'
|
||||
element.children[2].attrs['name'] `self.assertEquals` 'state'
|
||||
element.children[2].children `self.assertEquals` ['code']
|
||||
element.children[3].tag `self.assertEquals` 'field'
|
||||
element.children[3].attrs['name'] `self.assertEquals` 'code'
|
||||
element.children[3].children `self.assertEquals` ['record.do_something()']
|
||||
|
||||
def test_client_action_multi(self):
|
||||
element = od.client_action_multi('sample.xmlid', 'Multi', 'sample.model', 'sample.action')
|
||||
(self.assertIsInstance)(element, XMLDictElement)
|
||||
(self.assertEquals)(element.tag, 'record')
|
||||
(self.assertEquals)(element.attrs['id'], 'sample.xmlid')
|
||||
(self.assertEquals)(element.attrs['model'], 'ir.values')
|
||||
(self.assertEquals)(((len)(element.children)), 4)
|
||||
(self.assertIsInstance)(element.children[0], XMLDictElement)
|
||||
(self.assertEquals)(element.children[0].tag, 'field')
|
||||
(self.assertEquals)(element.children[0].attrs['name'], 'name')
|
||||
(self.assertEquals)(element.children[0].children, ['Multi'])
|
||||
(self.assertIsInstance)(element.children[1], XMLDictElement)
|
||||
(self.assertEquals)(element.children[1].tag, 'field')
|
||||
(self.assertEquals)(element.children[1].attrs['name'], 'key2')
|
||||
(self.assertEquals)(element.children[1].attrs['eval'], "'client_action_multi'")
|
||||
(self.assertFalse)(element.children[1].children)
|
||||
(self.assertEquals)(element.children[2].tag, 'field')
|
||||
(self.assertEquals)(element.children[2].attrs['name'], 'model')
|
||||
(self.assertEquals)(element.children[2].attrs['eval'], "'sample.model'")
|
||||
(self.assertEquals)(element.children[3].tag, 'field')
|
||||
(self.assertEquals)(element.children[3].attrs['name'], 'value')
|
||||
(self.assertEquals)(element.children[3].attrs['eval'], "'ir.actions.server,%d'%sample.action")
|
||||
element = od.client_action_multi('sample.xmlid', 'Multi', 'sample.model', 'sample.action')
|
||||
element `self.assertIsInstance` XMLDictElement
|
||||
element.tag `self.assertEquals` 'record'
|
||||
element.attrs['id'] `self.assertEquals` 'sample.xmlid'
|
||||
element.attrs['model'] `self.assertEquals` 'ir.values'
|
||||
(element.children |> len) `self.assertEquals` 4
|
||||
element.children[0] `self.assertIsInstance` XMLDictElement
|
||||
element.children[0].tag `self.assertEquals` 'field'
|
||||
element.children[0].attrs['name'] `self.assertEquals` 'name'
|
||||
element.children[0].children `self.assertEquals` ['Multi']
|
||||
element.children[1] `self.assertIsInstance` XMLDictElement
|
||||
element.children[1].tag `self.assertEquals` 'field'
|
||||
element.children[1].attrs['name'] `self.assertEquals` 'key2'
|
||||
element.children[1].attrs['eval'] `self.assertEquals` "'client_action_multi'"
|
||||
element.children[1].children |> self.assertFalse
|
||||
element.children[2].tag `self.assertEquals` 'field'
|
||||
element.children[2].attrs['name'] `self.assertEquals` 'model'
|
||||
element.children[2].attrs['eval'] `self.assertEquals` "'sample.model'"
|
||||
element.children[3].tag `self.assertEquals` 'field'
|
||||
element.children[3].attrs['name'] `self.assertEquals` 'value'
|
||||
element.children[3].attrs['eval'] `self.assertEquals` "'ir.actions.server,%d'%sample.action"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user