From 592756025921dbde51c2e00e1415425472d0e287 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Fri, 27 Mar 2020 11:17:39 +0100 Subject: [PATCH] [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. * --- hy_odoo/odoo.hy | 26 ++++++++++++++++++++++++++ setup.py | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hy_odoo/odoo.hy b/hy_odoo/odoo.hy index 2a6975a..ea0840c 100644 --- a/hy_odoo/odoo.hy +++ b/hy_odoo/odoo.hy @@ -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)) diff --git a/setup.py b/setup.py index 528e4e2..927ebf1 100644 --- a/setup.py +++ b/setup.py @@ -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'],