[IMP]Hy base : namespace Odoo DSL

This commit is contained in:
Fabien BOURGEOIS 2019-09-16 18:58:25 +02:00
parent a4a4539528
commit e2796dc29b
1 changed files with 20 additions and 20 deletions

View File

@ -19,36 +19,36 @@
(require [odoo.addons.hy_base.xml [*]]) (require [odoo.addons.hy_base.xml [*]])
(defmacro odoo [&rest args] `(xmlr "odoo" ~@args)) (defmacro ox-odoo [&rest args] `(xmlr "odoo" ~@args))
(defmacro data [&rest args] `(xmlnc "data" ~@args)) (defmacro ox-data [&rest args] `(xmlnc "data" ~@args))
(defmacro record [&rest args] `(xmlnc "record" ~@args)) (defmacro ox-record [&rest args] `(xmlnc "record" ~@args))
(defmacro view [xmlid children] `(record {"id" ~xmlid "model" "ir.ui.view"} ~children)) (defmacro ox-view [xmlid children] `(ox-record {"id" ~xmlid "model" "ir.ui.view"} ~children))
(defmacro view-def [xmlid name model &rest body] (defmacro ox-view-def [xmlid name model &rest body]
"View and first fields simplification with record xmlid, name, targeted model" "View and first fields simplification with record xmlid, name, targeted model"
`(do `(do
(view ~xmlid (ox-view ~xmlid
[(field-name ~name) [(ox-field-name ~name)
(field-model ~model) (ox-field-model ~model)
(field-arch ~@body)]))) (ox-field-arch ~@body)])))
(defmacro view-inherit [name model inherit &rest body] (defmacro ox-view-inherit [name model inherit &rest body]
"Inherited View simplification with name of the record, xmlid for model and "Inherited View simplification with name of the record, xmlid for model and
inherited view" inherited view"
(setv module (get (.split __name__ ".") 2) (setv module (get (.split __name__ ".") 2)
inherited (get (.split inherit ".") 1) inherited (get (.split inherit ".") 1)
xmlid f"{inherited}_inherit_{module}") xmlid f"{inherited}_inherit_{module}")
`(do `(do
(view ~xmlid (ox-view ~xmlid
[(field-name ~name) [(ox-field-name ~name)
(field-model ~model) (ox-field-model ~model)
(field-inherit ~inherit) (ox-field-inherit ~inherit)
(field-arch ~@body)]))) (ox-field-arch ~@body)])))
(defmacro field [&rest args] `(xmlna "field" ~@args)) (defmacro ox-field [&rest args] `(xmlna "field" ~@args))
(defmacro field-name [name] `(field {"name" "name"} [~name])) (defmacro ox-field-name [name] `(ox-field {"name" "name"} [~name]))
(defmacro field-model [model] `(field {"name" "model"} [~model])) (defmacro ox-field-model [model] `(ox-field {"name" "model"} [~model]))
(defmacro field-inherit [xmlid] `(field {"name" "inherit_id" "ref" ~xmlid} [])) (defmacro ox-field-inherit [xmlid] `(ox-field {"name" "inherit_id" "ref" ~xmlid} []))
(defmacro field-arch [&rest args] `(field {"name" "arch" "type" "xml"} ~@args)) (defmacro ox-field-arch [&rest args] `(ox-field {"name" "arch" "type" "xml"} ~@args))
(defmacro/g! xml-write [filename tree] (defmacro/g! xml-write [filename tree]
"Write XML file according to filename and given tree" "Write XML file according to filename and given tree"