From 811c166f906a09ca1781737ff5b9571f2ab74395 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Sat, 25 Apr 2020 16:51:54 +0200 Subject: [PATCH] [IMP]Odoo : new XML nodes, improve view inherit macro, attempt for _translate... But Odoo black magic, does not work with AST and so Hy... --- hy_odoo/odoo.hy | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/hy_odoo/odoo.hy b/hy_odoo/odoo.hy index f7c5e6a..929d669 100644 --- a/hy_odoo/odoo.hy +++ b/hy_odoo/odoo.hy @@ -68,6 +68,9 @@ (defn sheet [&rest args] (xmln "sheet" #*args)) (defn button [&rest args] (xmln "button" #*args)) (defn p [&rest args] (xmln "p" #*args)) +(defn xpath [&rest args] (xmln "xpath" #*args)) +(defn attribute [name value] (xmln "attribute" {"name" name} [value])) + (defn field [&rest args] "Special field allowing mangling name attribute" (setv attrs (nth args 0)) @@ -98,17 +101,19 @@ xmlid f"{model_und}_view_{view_type}" name f"{model_cap} {(.capitalize view_type)}") (view-def :xmlid xmlid :name name :model model :arch arch)) -(defn view-inherit [name model inherit arch] +(defn view-inherit [filename model inherit arch] "Inherited View simplification with name of the record, xmlid for model and inherited view" - (setv module (get (.split __name__ ".") 2) + (setv module (get (.split filename ".") 2) inherited (get (.split inherit ".") 1) - xmlid f"{inherited}_inherit_{module}") - (view xmlid - [(field-name name) - (field-model model) - (field-inherit inherit) - (field-arch arch)])) + xmlid f"{inherited}_inherit_{module}" + model_cap (.join " " (lfor w (.split model ".") (.capitalize w))) + name f"{model_cap} Adaptations") + (view xmlid + [(field-name name) + (field-model model) + (field-inherit inherit) + (field-arch arch)])) (defn actions-server-code [xmlid name modelref code] "Server actions of type code" @@ -145,6 +150,8 @@ (setv fn-name f"_compute_{(mangle fname)}") `(setv ~fname (~@body :compute ~fn-name))) +(defmacro __ [sentence] `((py "_") ~sentence)) + ; Migrations (defn generate-fn-name [filepath]