[ADD]Hy Odoo additions

* Add strdm helper to build domain string from hy style tuple ;
* Add ox-act-window-action to shortcut ;
* Add ox menuitems functions.
*
This commit is contained in:
Fabien BOURGEOIS 2020-03-27 11:17:39 +01:00
parent f4db225ccc
commit 5927560259
2 changed files with 27 additions and 1 deletions

View File

@ -20,6 +20,16 @@
(import [os [path]])
(import [hy-odoo.xml [xmlroot xmln]])
; Global helpers
(defn strdm [hy-domain]
"Generate Odoo domain from Hy like tuple domain"
(do
(setv (, op field value) hy-domain
field (mangle field)
value (if (string? value) f"'{value}'" value))
(return f"('{field}', '{op}', {value})")))
; XML helpers functions and macros
(defn ox-odoo [&rest args] (xmlroot (xmln "odoo" {} #*args)))
@ -29,6 +39,22 @@
(defn ox-tree [&rest args] (xmln "tree" #*args))
(defn ox-search [&rest args] (xmln "search" #*args))
(defn ox-act-window [&rest args] (xmln "act_window" #*args))
(defn ox-act-window-action [model attrs]
" Build new act_window from model and args"
(setv model_und (.replace model "." "_")
model_cap (.join " " (lfor w (.split model ".") (.capitalize w)))
xmlid f"{model_und}_view_action"
name f"{model_cap} Action")
(.update attrs {"id" xmlid "name" name "res_model" model})
(ox-act-window attrs))
(defn ox-menuitem [&rest args] (xmln "menuitem" #*args))
(defn ox-menuitem-model [model attrs]
" Build new menuitem from model and attrs"
(setv model_und (.replace model "." "_")
actionid f"{model_und}_view_action"
xmlid f"{model_und}_menu")
(.update attrs {"id" xmlid "action" actionid})
(ox-menuitem attrs))
(defn ox-group [&rest args] (xmln "group" #*args))
(defn ox-header [&rest args] (xmln "header" #*args))
(defn ox-footer [&rest args] (xmln "footer" #*args))

View File

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name="hy_odoo",
version="0.1",
version="0.2.0",
packages=find_packages(),
package_data={
'hy_odoo': ['*.hy'],