Compare commits

...

63 Commits
15.0 ... 10.0

Author SHA1 Message Date
Fabien BOURGEOIS 12624136fd [ADD]Yaltik DSL : add HTML tags 2024-05-02 16:56:31 +02:00
Fabien BOURGEOIS 9839cf9cfe [ADD]Yaltik DSL : add template tag 2024-04-16 11:11:16 +02:00
Fabien BOURGEOIS 0edf9cc91d [ADD]Yaltik DSL : Label Tag 2024-02-01 15:57:18 +01:00
Fabien BOURGEOIS c6d54f74f0 [ADD]Yaltik DSL : add ul / li tags 2024-01-29 15:15:34 +01:00
Fabien BOURGEOIS e1a6bcc0da [ADD]Title HTML balisis 2024-01-16 17:35:32 +01:00
Fabien BOURGEOIS 1e51fad8dd [ADD]BR Tag 2024-01-12 12:34:32 +01:00
Fabien BOURGEOIS a8be867ebd [IMP]Yaltik DSL : add span tag 2024-01-12 12:26:51 +01:00
Fabien BOURGEOIS 22d6497f38 [ADD]Yaltik DSL : add basic tags 2023-05-24 10:29:55 +02:00
Fabien BOURGEOIS 3684e9d18c [ADD]Yaltik DSL : add notebook/page tags 2023-01-10 14:31:13 +01:00
Fabien BOURGEOIS eb4574ffd9 [IMP]Yaltik DSL : add delete fn 2022-12-15 16:50:14 +01:00
Fabien BOURGEOIS d401fec32c [ADD]Yaltik DSL : tests for yes_no filter 2022-12-09 11:57:00 +01:00
Fabien BOURGEOIS fd014bf3b3 [REM]Yaltik DSL : remove last coco file 2022-12-09 11:36:02 +01:00
Fabien BOURGEOIS cc971fb516 [MIG]Yaltik DSL : from coconut to pure py2 2022-12-09 11:18:04 +01:00
Fabien BOURGEOIS bc6f8797c4 [ADD]Yaltik DSL : add filter_yes_no 2022-11-25 22:57:44 +01:00
Fabien BOURGEOIS 2cab9fe8f9 [ADD]Yaltik DSL : add separator (source) 2022-11-20 23:43:24 +01:00
Fabien BOURGEOIS 430e725fc9 [ADD]Yaltik DSL : add separator 2022-11-20 23:38:47 +01:00
Fabien BOURGEOIS 59af616aab [UPD]Yaltik DSL : files built for prod 2022-11-18 10:37:20 +01:00
Fabien BOURGEOIS 71475e3f27 [FIX]XML Base for Python2 2022-11-18 10:36:36 +01:00
Fabien BOURGEOIS 73ecdb19b5 [MIG][REF]Yaltik DSL backported from 16 with coconut 2022-11-17 16:05:36 +01:00
Fabien BOURGEOIS de341e5df6 [REM]Yaltik DSL : remove useless external dependency 2021-02-22 19:30:15 +01:00
Fabien BOURGEOIS e9a84a1683 [TYPO]Makefile 2021-02-22 17:49:20 +01:00
Fabien BOURGEOIS 93cd5bc112 Merge branch '10.0' into 10.0-purepy 2021-02-22 16:42:20 +01:00
Fabien BOURGEOIS b9d62b7c68 [REF]Yaltik DSL directories refactoring + makefile 2020-05-07 13:39:50 +02:00
Fabien BOURGEOIS 5c4c0fe6e3 [MIG][WIP]Yaltik DSL : Odoo DSL on pure Python 2020-05-07 10:17:03 +02:00
Fabien BOURGEOIS c48c086a0b [REF]Yaltik DSL Test XML reindentation 2020-05-03 13:07:27 +02:00
Fabien BOURGEOIS 32dff3cce7 [ADD]Yaltik DSL Makefile 2020-05-03 12:59:30 +02:00
Fabien BOURGEOIS 212b6dc3d3 [IMP]Yaltik DSL : add pretty option on xml_write 2020-05-03 12:59:18 +02:00
Fabien BOURGEOIS 9fa300f77e [WIP][BROKEN]Yaltik DSL : no ported yet from coco 2020-05-03 12:32:01 +02:00
Fabien BOURGEOIS 143492e58b [WIP][IMP]XML Base : pretty option of xml write 2020-05-03 12:31:40 +02:00
Fabien BOURGEOIS 315f4a82ae [MIG][WIP]Yaltik DSL : XML Base on pure Python 2020-05-03 12:03:47 +02:00
Fabien BOURGEOIS 0a86aa3eab [REM]Remove Coconut from Yaltik DSL 2020-05-03 12:03:17 +02:00
Fabien BOURGEOIS 0c037815b9 [FIX]Yaltik DSL fix xmln with only children 2020-05-01 18:58:34 +02:00
Fabien BOURGEOIS 4938cec43d [IMP]Yaltik DSL : tests, use asserRaises instead of try 2020-05-01 18:44:24 +02:00
Fabien BOURGEOIS 8859a4b340 [REF][UPD]Yaltik DSL : migration to coco finished 2020-05-01 12:57:14 +02:00
Fabien BOURGEOIS c0c1427fce [REF]Yaltik DSL : end of refactoring to coconut, final tests 2020-05-01 09:45:58 +02:00
Fabien BOURGEOIS 9d1ab3dc6c [IMP]Yaltik DSL : Odoo DSL avoid side effect on attributes 2020-05-01 00:07:01 +02:00
Fabien BOURGEOIS 170aa6a86e [REF][IMP][WIP]Yaltik DSL : refactor to coco odoo
And new tests, enhancements.... WIP !
2020-04-30 23:41:39 +02:00
Fabien BOURGEOIS e46c4bf6ab [IMP]Yaltik DSL : improvements
* Improve typing ;
* Rewrite of xml_write ;
* New tests cases, as xml_write.
2020-04-30 18:32:47 +02:00
Fabien BOURGEOIS 742d395427 [REF]Yaltik DSL : XML Base better xmln 2020-04-30 11:09:28 +02:00
Fabien BOURGEOIS cfb99c113d [REF][WIP]Yaltik DSL : new tests, refacoring of xml_base, ADTs 2020-04-30 10:58:45 +02:00
Fabien BOURGEOIS 1202e3c6d4 [REF][WIP]Yaltik DSL : attempt to migrate to Coconut 2020-04-30 03:01:37 +02:00
Fabien BOURGEOIS 407b0fb78f [FIX]Yaltik DSL : fix for unicode child (not only str) 2020-04-29 18:41:18 +02:00
Fabien BOURGEOIS 829c72900a [IMP]Yaltik DSL : do not regenerate XML from cached Python 2020-04-29 11:02:18 +02:00
Fabien BOURGEOIS 8709bd2195 [IMP]Yaltik DSL : add XML filter 2020-04-29 08:37:49 +02:00
Fabien BOURGEOIS 63152aabdb [REF]Yaltik DSL : prefer lambdas, better indentations etc.
(quirks from hy2py)
2020-04-28 09:00:28 +02:00
Fabien BOURGEOIS 950f08fca6 [ADD]Yaltik DSL for Odoo 2020-04-28 08:47:58 +02:00
Fabien BOURGEOIS fb3834b433 [REM]Hy base removal (for external python package) 2020-03-27 00:34:42 +01:00
Fabien BOURGEOIS c01a61ba1c [FIX]Account Bank Statement Import CCoop : handling new CSV format
* Empty last cells on balance lines ;
* New year with YYYY (old : YY).
2020-01-30 10:19:42 +01:00
Fabien BOURGEOIS c5e3aff7df [IMP]Hy base : allow attrs as child as 2nd arg for xmln 2019-09-22 15:10:19 +02:00
Fabien BOURGEOIS 82fd49a5e5 [REF]Hy base : finalize fns over macros 2019-09-22 10:41:17 +02:00
Fabien BOURGEOIS c45d527fff [REF]Hy Base XML better naming for child 2019-09-22 10:34:00 +02:00
Fabien BOURGEOIS 82155b3cc2 [IMP]Hy Base : favor defns instead of macros here 2019-09-22 10:32:19 +02:00
Fabien BOURGEOIS fbb21545ec [ADD]XML DSL addon 2019-09-20 15:28:33 +02:00
Fabien BOURGEOIS 0b592275a9 [IMP]Hy Base : new odoo macros 2019-09-18 21:10:34 +02:00
Fabien BOURGEOIS b61c49d1e6 [FIX]Hy Base : handle python2 case 2019-09-18 09:28:04 +02:00
Fabien BOURGEOIS f1ae84bc77 [FIX]Hy base : actions-server code fix 2019-09-18 09:27:21 +02:00
Fabien BOURGEOIS 217a64ab68 [IMP]Hy Base : new macro for server actions 2019-09-17 16:40:14 +02:00
Fabien BOURGEOIS e2796dc29b [IMP]Hy base : namespace Odoo DSL 2019-09-16 18:58:25 +02:00
Fabien BOURGEOIS a4a4539528 [FIX]Hy Base : bad args expansion on xml-write macro 2019-09-16 18:57:28 +02:00
Fabien BOURGEOIS 9a7027622f [IMP]Hy base : use gensym for safer xml-write macro 2019-09-16 18:21:29 +02:00
Fabien BOURGEOIS 19b9fa6c69 [REF]Hy base : use format strings, better setv 2019-09-16 18:10:37 +02:00
Fabien BOURGEOIS b8462951e0 [ADD]Hy base : add xml-write macro 2019-09-16 16:47:29 +02:00
Fabien BOURGEOIS 8eb4c0e294 [ADD]Hylang base with XML and Odoo macros 2019-09-16 16:20:08 +02:00
14 changed files with 926 additions and 7 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
# Copyright 2018-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
@ -22,7 +22,7 @@
* For CSV published by Crédit Coopératif on their website customer space ;
* Adds option on bank import statement wizard ;
* Checks and processes file.""",
'version': '10.0.0.1.3',
'version': '10.0.0.1.4',
'category': 'Banking addons',
'author': 'Fabien Bourgeois',
'license': 'AGPL-3',

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
# Copyright 2018-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
@ -53,9 +53,13 @@ class AccountBankStatementImport(models.TransientModel):
@api.model
def _get_coop_transaction(self, account_number, line):
""" Prepare transaction line """
# CCoop format change : old was YY, now YYYY
if len(line[0]) <= 8:
parsed_date = time.strptime(line[0], '%d/%m/%y')
else:
parsed_date = time.strptime(line[0], '%d/%m/%Y')
return {'name': line[2] or u'/',
'date': time.strftime('%Y-%m-%d',
time.strptime(line[0], '%d/%m/%y')),
'date': time.strftime('%Y-%m-%d', parsed_date),
'amount': str2float(line[3] or line[4]),
'unique_import_id': line[1],
'note': line[5],
@ -68,11 +72,18 @@ class AccountBankStatementImport(models.TransientModel):
account_number = data[1][0].split(' : ')[1]
if not len(data[-1]): # If last line is empty, remove it
data.pop()
# Change in CSV produced from CCoop, now empty last cell
balance_start = data[-1][-1]
balance_end_real = data[3][-1]
if balance_start == '':
balance_start = data[-1][-2]
if balance_end_real == '':
balance_end_real = data[3][-2]
bank_statement_data = {
'date': time.strftime(
'%Y-%m-%d', time.strptime(data[0][3].split(' : ')[1], '%d/%m/%Y')),
'balance_start': str2float(data[-1][-1]),
'balance_end_real': str2float(data[3][-1])
'balance_start': str2float(balance_start),
'balance_end_real': str2float(balance_end_real)
}
bank_statement_data['name'] = '%s - %s' % (account_number,
bank_statement_data['date'])

18
xml_dsl/__init__.py Normal file
View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2019 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 . import odoo

29
xml_dsl/__manifest__.py Normal file
View File

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Copyright 2019 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/>.
{
'name': 'Odoo XML DSL base module and fns',
'summary': 'Odoo XML Domain Specific Language base module and functions',
'description': """ Odoo XML Domain Specific Language base module and functions """,
'version': '10.0.0.1.0',
'category': 'Yaltik',
'author': 'Fabien Bourgeois',
'license': 'AGPL-3',
'application': False,
'installable': True,
'depends': ['base']
}

46
xml_dsl/base.py Normal file
View File

@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
#
# Copyright 2019 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/>.
""" XML helpers and macros """
from xml.etree import ElementTree as ET
def xmlroot(tree):
""" Special process for root XML Node """
rootel = ET.Element(tree['tag'], tree['attrs'])
children = tree['children']
if children:
xmlchild(rootel, children)
return rootel
def xmlchild(parent, children):
""" Handling of children (ie non root) XML Nodes with/o text and
subchildren (recursive) """
for child in children:
if isinstance(child, str):
parent.text = child
else:
attrs = {unicode(k): unicode(v) for k, v in child['attrs'].items()}
new_parent = ET.SubElement(parent, child['tag'], attrs)
subchildren = child['children']
if subchildren:
xmlchild(new_parent, subchildren)
def xmln(tag='', attrs=None, children=None, text=False):
""" XMLNode with default children, not attributes """
children = ([text] if text else children) or []
return {'tag': tag, 'attrs': attrs or {}, 'children': children}

81
xml_dsl/odoo.py Normal file
View File

@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
#
# Copyright 2019 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/>.
""" Odoo XML DSL """
from . import base as x
def odoo(*args):
""" odoo tag shortcut """
return x.xmlroot(x.xmln('odoo', {}, *args))
def data(*args):
""" data tag shortcut """
return x.xmln('data', {}, *args)
def record(*args):
""" record tag shortcut """
return x.xmln('record', *args)
def view(xmlid, children):
""" view tag shortcut """
return 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_inherit(name, model, inherit, arch):
""" Inherited View simplification with name of the record, xmlid for model
and inherited view """
module = __name__.split('.')[2]
inherited = inherit.split('.')[1]
xmlid = '%s_inherit_%s' % (inherited, module)
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 field(*args):
""" field tag shortcut """
return x.xmln('field', *args)
def field_name(name):
""" field name tag shortcut """
return field({'name': 'name'}, [name])
def field_model(model):
""" field model tag shortcut """
return field({'name': 'model'}, [model])
def field_inherit(xmlid):
""" field inherit tag shortcut """
return field({'name': 'inherit_id', 'ref': xmlid})
def field_arch(*args):
""" field arch tag shortcut """
return field({'name': 'arch', 'type': 'xml'}, *args)
def xml_write(mpath, filename, tree):
""" Write XML file according to filename and given tree """
import os.path
from xml.etree import ElementTree as ET
output_xml = ET.tostring(tree)
output_path = os.path.dirname(os.path.abspath(mpath))
fpath = u'%s/%s' % (output_path, filename)
with open(fpath, 'w') as xml_file:
xml_file.write(output_xml)

31
yaltik_dsl/Makefile Normal file
View File

@ -0,0 +1,31 @@
.PHONY: setup
setup:
pip install --user -U coconut[watch,jobs,backports,mypy]
.PHONY: testdev
testdev: clean build test
.PHONY: testprod
testprod: clean prod test
.PHONY: clean
clean:
find . -name '*.pyc' -delete
find . -name '__pycache__' -delete
.PHONY: test
test:
python2 tests/test_xml_base.py
python2 tests/test_odoo.py
.PHONY: build
build:
coconut -t 2.7 -j sys .
.PHONY: prod
prod:
coconut --notco -t 2.7 -j sys -f .
.PHONY: watch
watch:
coconut --strict -t 2.7 -j sys -w .

18
yaltik_dsl/__init__.py Normal file
View File

@ -0,0 +1,18 @@
# -*- 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 . import src

View File

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Copyright 2019-2024 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/>.
{
'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.5.13',
'category': 'Yaltik',
'author': 'Fabien Bourgeois',
'license': 'AGPL-3',
'application': False,
'installable': True,
'depends': ['base']
}

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 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 . import odoo_dsl

160
yaltik_dsl/src/odoo_dsl.py Normal file
View File

@ -0,0 +1,160 @@
# -*- coding: utf-8 -*-
#
# Copyright 2019-2024 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/>.
""" Odoo XML DSL """
from .xml_base import xmlroot, xmln
# XML helpers functions and macros
# Odoo root XML Node
odoo = lambda children: xmlroot({'tag': 'odoo', 'attrs': {}, 'children': children})
# Special data Node
def data(*args):
""" Allow optional args on data tag """
if len(args) == 1:
args = list(args)
args.insert(0, {})
return xmln('data', *args)
# Aliases
function = lambda *args: xmln('function', *args)
record = lambda *args: xmln('record', *args)
delete = lambda *args: xmln('delete', *args)
form = lambda *args: xmln('form', *args)
tree = lambda *args: xmln('tree', *args)
search = lambda *args: xmln('search', *args)
template = lambda *args: xmln('template', *args)
# Actions
act_window = lambda *args: xmln('act_window', *args)
def act_window_model(model, attrs):
""" Build new act_window from model and args """
xmlid = '%s_view_action' % (model.replace('.', '_'))
name = '%s Action' % ' '.join(map(lambda w: w.capitalize(), model.split('.')))
attrs_clone = attrs.copy() # Avoid side-effect
attrs_clone.update({'id': xmlid, 'name': name, 'res_model': model})
return act_window(attrs_clone)
def action_server_code(xmlid, name, modelref, code):
""" 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)
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)
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)
# Menus
menuitem = lambda *args: xmln('menuitem', *args)
def menuitem_model(model, attrs):
""" Build new menuitem from model and attrs """
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})
return menuitem(attrs_clone)
# Form aliases
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)
i = lambda *args: xmln('i', *args)
t = lambda *args: xmln('t', *args)
div = lambda *args: xmln('div', *args)
span = lambda *args: xmln('span', *args)
br = lambda *args: xmln('br', *args)
h1 = lambda *args: xmln('h1', *args)
h2 = lambda *args: xmln('h1', *args)
h3 = lambda *args: xmln('h1', *args)
h4 = lambda *args: xmln('h1', *args)
h5 = lambda *args: xmln('h1', *args)
ul = lambda *args: xmln('ul', *args)
li = lambda *args: xmln('li', *args)
label = lambda *args: xmln('label', *args)
strong = lambda *args: xmln('strong', *args)
small = lambda *args: xmln('small', *args)
table = lambda *args: xmln('table', *args)
tr = lambda *args: xmln('tr', *args)
td = lambda *args: xmln('td', *args)
notebook = lambda *args: xmln('notebook', *args)
page = lambda *args: xmln('page', *args)
xpath = lambda *args: xmln('xpath', *args)
attribute = lambda name, value: xmln('attribute', {'name': name}, [value])
# Fields
field = lambda *args: xmln('field', *args)
field_name = lambda name: field({'name': 'name'}, [name])
field_nval = lambda name, value: field({'name': name}, [value])
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)
# Search
filter = lambda *args: xmln('filter', *args)
separator = lambda *args: xmln('separator', *args)
def filter_yes_no(field, str_yes=False, str_no=False):
""" Double filter for boolean : True and False """
res = []
if str_yes:
res.append(filter({'name': '%s_yes' % field, 'string': str_yes,
'domain': "[('%s', '=', True)]" % field}))
if str_no:
res.append(filter({'name': '%s_no' % field, 'string': str_no,
'domain': "[('%s', '=', False)]" % field}))
return res
# Views
view = lambda xmlid, children: record({'id': xmlid, 'model': 'ir.ui.view'}, children)
def view_def(xmlid, name, model, arch):
""" Shortcut for new view """
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(map(lambda w: w.capitalize(), model.split('.')))
xmlid = "%s_view_%s" % (model_und, view_type)
name = ' '.join([model_cap, view_type.capitalize()])
return view_def(xmlid, name, model, 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 = '%s_inherit_%s' % (inherited, module)
model_cap = ' '.join(map(lambda w: w.capitalize(), model.split('.')))
name = '%s Adaptations' % model_cap
return view(xmlid, [field_name(name), field_model(model),
field_inherit(inherit), field_arch(arch)])

View File

@ -0,0 +1,75 @@
# -*- 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/>.
""" XML helpers and macros """
from os import path
import xml.etree.ElementTree as ET
from xml.dom import minidom
from collections import namedtuple
from functools import partial
XMLDictElement = namedtuple('XMLDictElement', ['tag', 'attrs', 'children'])
def xmlroot(tree):
""" Special process for root XML Node """
rootel = ET.Element(tree['tag'], tree['attrs'])
if 'children' in tree:
xmlchild(rootel, tree['children'])
return rootel
def xmlchild(parent, children):
""" Handling of children (ie non root) XML Nodes with/o text and
subchildren (recursive) """
if isinstance(children, basestring):
parent.text = children
elif isinstance(children, XMLDictElement):
attrs = {str(k): str(v) for [k, v] in children.attrs.items()}
new_parent = ET.SubElement(parent, children.tag, attrs)
subchildren = children.children
if subchildren:
xmlchild(new_parent, subchildren)
elif isinstance(children, list):
list(map(partial(xmlchild, parent), children))
else:
raise TypeError('Invalid arguments for xmlchild')
def xmln(tag='', attrs={}, children=[]):
""" XMLDictElement building from dict object, with defaults """
if isinstance(attrs, list):
children = attrs
attrs = {}
xmldictel = partial(XMLDictElement, tag, attrs)
if isinstance(children, basestring):
return xmldictel([children])
if isinstance(children, list):
return xmldictel(children)
raise TypeError('Invalid arguments for xmln')
def xml_write(filepath, tree, pretty=True, suffix='_views'):
""" Write XML file according to filename and given tree """
if filepath.endswith('.py'): # if .pyc, no need to generate XML
output_xml = ET.tostring(tree)
if pretty:
output_xml = minidom.parseString(output_xml).toprettyxml(indent=' ')
output_path = path.abspath(filepath).split('/')
output_path[-1] = output_path[-1].replace('.py', '%s.xml' % suffix)
output_path = '/'.join(output_path)
with open(output_path, 'w') as output_file:
output_file.write(output_xml)

View File

@ -0,0 +1,274 @@
# -*- coding: utf-8 -*-
#
# Copyright 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/>.
""" Odoo Helpers tests """
import unittest
import xml.etree.ElementTree as ET
from src.xml_base import XMLDictElement
import src.odoo_dsl as od
class TestOdooBase(unittest.TestCase):
""" Odoo Helpers tests """
def test_odoo(self):
""" Test odoo function """
element = od.odoo([])
self.assertIsInstance(element, ET.Element)
self.assertEqual(element.tag, 'odoo')
def test_data(self):
""" Test data function """
element = od.data([])
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'data')
self.assertEqual(element.attrs, {})
element = od.data({"one": "attribute"}, [])
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'data')
self.assertEqual(element.attrs, {"one": "attribute"})
def test_aliases(self):
""" Test simple aliases to xmln """
element = od.record({"one": "attribute"}, 'A child')
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'record')
self.assertEqual(element.attrs, {"one": "attribute"})
self.assertEqual(element.children, ['A child'])
element = od.tree()
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'tree')
def test_act_window_model(self):
""" Test act_window function """
element = od.act_window_model('sample.model', {'view_type': 'form'})
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'act_window')
self.assertEqual(element.attrs['view_type'], 'form')
self.assertEqual(element.attrs['id'], 'sample_model_view_action')
self.assertEqual(element.attrs['res_model'], 'sample.model')
self.assertEqual(element.attrs['name'], 'Sample Model Action')
def test_menunitem_model(self):
""" Test menuitem function """
element = od.menuitem_model('sample.model', {'groups': 'base.user_employee'})
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'menuitem')
self.assertEqual(element.attrs['groups'], 'base.user_employee')
self.assertEqual(element.attrs['id'], 'sample_model_menu')
self.assertEqual(element.attrs['action'], 'sample_model_view_action')
def test_attribute(self):
""" Test attribute function """
element = od.attribute('invisible', "1")
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'attribute')
self.assertEqual(element.attrs['name'], 'invisible')
self.assertEqual(element.children, ["1"])
def test_fields(self):
""" Test fields function """
element = od.field({"one": "attribute"}, 'A child')
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'field')
element = od.field_name('A name')
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'field')
self.assertEqual(element.attrs['name'], 'name')
self.assertEqual(element.children, ['A name'])
element = od.field_model('sample.model')
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'field')
self.assertEqual(element.attrs['name'], 'model')
self.assertEqual(element.children, ['sample.model'])
element = od.field_inherit('module.xml_view')
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'field')
self.assertEqual(element.attrs['name'], 'inherit_id')
self.assertEqual(element.attrs['ref'], 'module.xml_view')
self.assertFalse(element.children)
element = od.field_arch()
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'field')
self.assertEqual(element.attrs['name'], 'arch')
self.assertEqual(element.attrs['type'], 'xml')
self.assertFalse(element.children)
def test_filter_yes_no(self):
""" Test Filter Yes No """
elements = od.filter_yes_no('some_field')
self.assertIsInstance(elements, list)
self.assertFalse(elements)
elements = od.filter_yes_no('some_field', 'Some field')
self.assertEqual(len(elements), 1)
self.assertIsInstance(elements[0], XMLDictElement)
self.assertEqual(elements[0].tag, 'filter')
self.assertEqual(elements[0].attrs['name'], 'some_field_yes')
self.assertEqual(elements[0].attrs['string'], 'Some field')
self.assertEqual(elements[0].attrs['domain'], "[('some_field', '=', True)]")
elements = od.filter_yes_no('some_field', 'Some field', 'Not some field')
self.assertEqual(len(elements), 2)
self.assertIsInstance(elements[0], XMLDictElement)
self.assertEqual(elements[0].tag, 'filter')
self.assertEqual(elements[0].attrs['name'], 'some_field_yes')
self.assertEqual(elements[0].attrs['string'], 'Some field')
self.assertEqual(elements[0].attrs['domain'], "[('some_field', '=', True)]")
self.assertIsInstance(elements[1], XMLDictElement)
self.assertEqual(elements[1].tag, 'filter')
self.assertEqual(elements[1].attrs['name'], 'some_field_no')
self.assertEqual(elements[1].attrs['string'], 'Not some field')
self.assertEqual(elements[1].attrs['domain'], "[('some_field', '=', False)]")
def test_view(self):
""" Test view function """
element = od.view('view_xmlid', [])
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'record')
self.assertEqual(element.attrs['id'], 'view_xmlid')
self.assertEqual(element.attrs['model'], 'ir.ui.view')
self.assertFalse(element.children)
def test_view_def(self):
""" Test view_def function """
element = od.view_def('view_xmlid', 'View', 'sample.model', [])
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'record')
self.assertEqual(element.attrs['id'], 'view_xmlid')
self.assertEqual(element.attrs['model'], 'ir.ui.view')
self.assertEqual((len(element.children)), 3)
self.assertIsInstance(element.children[0], XMLDictElement)
self.assertEqual(element.children[0].tag, 'field')
self.assertEqual(element.children[0].attrs['name'], 'name')
self.assertEqual(element.children[0].children, ['View'])
self.assertIsInstance(element.children[1], XMLDictElement)
self.assertEqual(element.children[1].tag, 'field')
self.assertEqual(element.children[1].attrs['name'], 'model')
self.assertEqual(element.children[1].children, ['sample.model'])
self.assertIsInstance(element.children[2], XMLDictElement)
self.assertEqual(element.children[2].tag, 'field')
self.assertEqual(element.children[2].attrs['name'], 'arch')
self.assertEqual(element.children[2].attrs['type'], 'xml')
self.assertFalse(element.children[2].children)
def test_view_new(self):
""" Test view_new function """
element = od.view_new('tree', 'sample.model', [])
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'record')
self.assertEqual(element.attrs['id'], 'sample_model_view_tree')
self.assertEqual(element.attrs['model'], 'ir.ui.view')
self.assertEqual((len(element.children)), 3)
self.assertIsInstance(element.children[0], XMLDictElement)
self.assertEqual(element.children[0].tag, 'field')
self.assertEqual(element.children[0].attrs['name'], 'name')
self.assertEqual(element.children[0].children, ['Sample Model Tree'])
self.assertIsInstance(element.children[1], XMLDictElement)
self.assertEqual(element.children[1].tag, 'field')
self.assertEqual(element.children[1].attrs['name'], 'model')
self.assertEqual(element.children[1].children, ['sample.model'])
self.assertIsInstance(element.children[2], XMLDictElement)
self.assertEqual(element.children[2].tag, 'field')
self.assertEqual(element.children[2].attrs['name'], 'arch')
self.assertEqual(element.children[2].attrs['type'], 'xml')
self.assertFalse(element.children[2].children)
def test_view_inherit(self):
""" Test view_inherit function """
element = od.view_inherit('odoo.addons.module', 'sample.model', 'parent.view', [])
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'record')
self.assertEqual(element.attrs['id'], 'view_inherit_module')
self.assertEqual(element.attrs['model'], 'ir.ui.view')
self.assertEqual((len(element.children)), 4)
self.assertIsInstance(element.children[0], XMLDictElement)
self.assertEqual(element.children[0].tag, 'field')
self.assertEqual(element.children[0].attrs['name'], 'name')
self.assertEqual(element.children[0].children, ['Sample Model Adaptations'])
self.assertIsInstance(element.children[1], XMLDictElement)
self.assertEqual(element.children[1].tag, 'field')
self.assertEqual(element.children[1].attrs['name'], 'model')
self.assertEqual(element.children[1].children, ['sample.model'])
self.assertIsInstance(element.children[2], XMLDictElement)
self.assertEqual(element.children[2].tag, 'field')
self.assertEqual(element.children[2].attrs['name'], 'inherit_id')
self.assertFalse(element.children[2].children)
self.assertIsInstance(element.children[3], XMLDictElement)
self.assertEqual(element.children[3].tag, 'field')
self.assertEqual(element.children[3].attrs['name'], 'arch')
self.assertEqual(element.children[3].attrs['type'], 'xml')
self.assertFalse(element.children[3].children)
def test_action_server_code(self):
""" Test action_server_code function """
element = od.action_server_code('sample.xmlid', 'Code', 'sample.model',
'''record.do_something()''')
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'record')
self.assertEqual(element.attrs['id'], 'sample.xmlid')
self.assertEqual(element.attrs['model'], 'ir.actions.server')
self.assertEqual((len(element.children)), 4)
self.assertIsInstance(element.children[0], XMLDictElement)
self.assertEqual(element.children[0].tag, 'field')
self.assertEqual(element.children[0].attrs['name'], 'name')
self.assertEqual(element.children[0].children, ['Code'])
self.assertIsInstance(element.children[1], XMLDictElement)
self.assertEqual(element.children[1].tag, 'field')
self.assertEqual(element.children[1].attrs['name'], 'model_id')
self.assertEqual(element.children[1].attrs['ref'], 'sample.model')
self.assertFalse(element.children[1].children)
self.assertEqual(element.children[2].tag, 'field')
self.assertEqual(element.children[2].attrs['name'], 'state')
self.assertEqual(element.children[2].children, ['code'])
self.assertEqual(element.children[3].tag, 'field')
self.assertEqual(element.children[3].attrs['name'], 'code')
self.assertEqual(element.children[3].children, ['record.do_something()'])
def test_client_action_multi(self):
""" Test client_action_multi function """
element = od.client_action_multi('sample.xmlid', 'Multi', 'sample.model', 'sample.action')
self.assertIsInstance(element, XMLDictElement)
self.assertEqual(element.tag, 'record')
self.assertEqual(element.attrs['id'], 'sample.xmlid')
self.assertEqual(element.attrs['model'], 'ir.values')
self.assertEqual((len(element.children)), 4)
self.assertIsInstance(element.children[0], XMLDictElement)
self.assertEqual(element.children[0].tag, 'field')
self.assertEqual(element.children[0].attrs['name'], 'name')
self.assertEqual(element.children[0].children, ['Multi'])
self.assertIsInstance(element.children[1], XMLDictElement)
self.assertEqual(element.children[1].tag, 'field')
self.assertEqual(element.children[1].attrs['name'], 'key2')
self.assertEqual(element.children[1].attrs['eval'], "'client_action_multi'")
self.assertFalse(element.children[1].children)
self.assertEqual(element.children[2].tag, 'field')
self.assertEqual(element.children[2].attrs['name'], 'model')
self.assertEqual(element.children[2].attrs['eval'], "'sample.model'")
self.assertEqual(element.children[3].tag, 'field')
self.assertEqual(element.children[3].attrs['name'], 'value')
self.assertEqual(element.children[3].attrs['eval'], "'ir.actions.server,%d'%sample.action")
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,129 @@
# -*- coding: utf-8 -*-
#
# Copyright 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/>.
""" XML Helpers tests """
from functools import partial
import unittest
import xml.etree.ElementTree as ET
from os import unlink
from src.xml_base import xmln, xmlroot, xmlchild, xml_write
class TestXMLBase(unittest.TestCase):
""" XML Helpers tests """
def test_xmln(self):
""" Text xmln """
# Tags
self.assertDictEqual(xmln()._asdict(), {'tag': '', 'attrs': {}, 'children': []})
self.assertEqual(xmln('a tag').tag, 'a tag')
# Attrs
self.assertDictEqual(xmln(attrs={'a good': 'one'}).attrs, {'a good': 'one'})
# Childrens
self.assertListEqual(xmln(children=[1, 2, 3]).children, [1, 2, 3])
self.assertListEqual(xmln(children='Some text').children, ['Some text'])
with self.assertRaisesRegexp(TypeError, 'Invalid arguments'):
xmln(children=False)
# Ensure that only children after tags is managed
element = xmln('tag', {'something': 'inside'})
self.assertIsInstance(element.attrs, dict)
self.assertIsInstance(element.children, list)
element = xmln('tag', ['something', 'inside'])
self.assertIsInstance(element.attrs, dict)
self.assertIsInstance(element.children, list)
def test_xmlchild(self):
""" Test xmlchild """
parent = xmlroot({'tag': 'root', 'attrs': {}, 'children': []})
xmlc_par = partial(xmlchild, parent)
# Bad arguments
with self.assertRaisesRegexp(TypeError, 'Invalid arguments for xmlchild'):
xmlc_par(False)
# Need XMLDictElement, not dict
with self.assertRaisesRegexp(TypeError, 'Invalid arguments for xmlchild'):
xmlc_par([{'tag': 't', 'attrs': {'a': 'b'}, 'children': []}])
xmlc_par(['some text'])
self.assertEqual(parent.text, 'some text')
xmlc_par([xmln('t', {'a': 'b'}, [])])
child = parent.iter('t').next()
self.assertEqual(child.tag, 't')
self.assertDictEqual(child.attrib, {'a': 'b'})
self.assertListEqual(list(child), [])
xmlc_par([xmln('t2', {1: 2}, [])])
child = parent.iter('t2').next()
self.assertDictEqual(child.attrib, {'1': '2'})
xmlc_par([xmln('tchildren', {}, [xmln('subchild', {}, [])])])
child = parent.iter('tchildren').next()
subchildren = list(child)
self.assertEqual(len(subchildren), 1)
self.assertEqual(subchildren[0].tag, 'subchild')
def test_xmlroot(self):
""" Test xmlroot """
root = xmlroot({'tag': 'root', 'attrs': {}, 'children': []})
self.assertIsInstance(root, ET.Element)
with self.assertRaisesRegexp(TypeError, 'no attribute'):
xmlroot(False)
with self.assertRaisesRegexp(KeyError, 'tag'):
xmlroot({})
with self.assertRaisesRegexp(KeyError, 'attrs'):
xmlroot({'tag': 'root'})
def test_xml_write(self):
""" test xml_write """
children = [xmln('child1', {'attr': 'value'}, []),
xmln('child2', {}, "Some text")]
tree = xmlroot({'tag': 'root', 'attrs': {}, 'children': children})
xmlw = lambda p: xml_write(p, tree)
self.assertIsNone(xmlw('/badpath'))
self.assertIsNone(xmlw('/bad.ext'))
xmlw(__file__)
filepath = __file__.replace('.py', '_views.xml')
with open(filepath, 'r') as output_file:
output_xml = output_file.read()
self.assertIn('<?xml version', output_xml)
self.assertIn('<root>', output_xml)
self.assertIn('<child1 attr="value"/>', output_xml)
self.assertIn('<child2>Some text</child2>', output_xml)
unlink(filepath)
xml_write(__file__, tree, suffix='_data')
filepath = __file__.replace('.py', '_data.xml')
with open(filepath, 'r') as output_file:
output_xml = output_file.read()
self.assertIn('<?xml version', output_xml)
self.assertIn('<root>', output_xml)
self.assertIn('<child1 attr="value"/>', output_xml)
self.assertIn('<child2>Some text</child2>', output_xml)
unlink(filepath)
if __name__ == '__main__':
unittest.main()