[IMP]Hy Base enhancements

* New ox-view-new shortcut to quickly create new records and views ;
* New ox-sheet XML field ;
* Improrve ox-field with mangling name attribute ;
* Idem for compute-fn macro for dependencies.
This commit is contained in:
Fabien BOURGEOIS 2020-03-26 22:32:16 +01:00
parent fd2da5bddf
commit dff6311d81
1 changed files with 19 additions and 2 deletions

21
odoo.hy
View File

@ -40,9 +40,18 @@
(defn ox-group [&rest args] (xmln "group" #*args))
(defn ox-header [&rest args] (xmln "header" #*args))
(defn ox-footer [&rest args] (xmln "footer" #*args))
(defn ox-sheet [&rest args] (xmln "sheet" #*args))
(defn ox-button [&rest args] (xmln "button" #*args))
(defn ox-p [&rest args] (xmln "p" #*args))
(defn ox-field [&rest args] (xmln "field" #*args))
(defn ox-field [&rest args]
"Special ox-field allowing mangling name attribute"
(setv attrs (nth args 0))
(when (and (instance? dict attrs) (in "name" attrs))
(assoc attrs "name" (mangle (get attrs "name")))
(setv args (list args))
(assoc args 0 attrs)
(setv args (tuple args)))
(xmln "field" #*args))
(defn ox-field-name [name] (ox-field {"name" "name"} [name]))
(defn ox-field-model [model] (ox-field {"name" "model"} [model]))
@ -57,6 +66,13 @@
[(ox-field-name name)
(ox-field-model model)
(ox-field-arch arch)]))
(defn ox-view-new[view_type model arch]
"View : new view definition, based on type (form, tree, ...) and model ID"
(setv model_und (.replace model "." "_")
model_cap (.join " " (lfor w (.split model ".") (.capitalize w)))
xmlid f"{model_und}_view_{view_type}"
name f"{model_cap} {(.capitalize view_type)}")
(ox-view-def :xmlid xmlid :name name :model model :arch arch))
(defn ox-view-inherit [name model inherit arch]
"Inherited View simplification with name of the record, xmlid for model and
inherited view"
@ -103,7 +119,8 @@
(defmacro/g! compute-fn [field dependencies body]
"Macro to make computed definition smoother"
(setv fname f"_compute_{(mangle field)}" descr f"Computes {field}")
(setv fname f"_compute_{(mangle field)}" descr f"Computes {field}"
dependencies (list (map mangle dependencies)))
`(do
(import [hy.models [HySymbol]])
(with-decorator (.depends api ~@dependencies)