hy_odoo/odoo.hy

70 lines
2.8 KiB
Hy
Raw Normal View History

2019-09-17 16:39:34 +02:00
;; -*- coding: utf-8 -*-
;;
;; Copyright 2019 Fabien Bourgeois <fabien@yaltik.com>
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Affero General Public License for more details.
;;
;; You should have received a copy of the GNU Affero General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
" Odoo XML macros "
(require [odoo.addons.hy_base.xml [*]])
(defmacro ox-odoo [&rest args] `(xmlr "odoo" ~@args))
(defmacro ox-data [&rest args] `(xmlnc "data" ~@args))
(defmacro ox-record [&rest args] `(xmlnc "record" ~@args))
(defmacro ox-view [xmlid children] `(ox-record {"id" ~xmlid "model" "ir.ui.view"} ~children))
(defmacro ox-view-def [xmlid name model &rest body]
"View and first fields simplification with record xmlid, name, targeted model"
`(do
(ox-view ~xmlid
[(ox-field-name ~name)
(ox-field-model ~model)
(ox-field-arch ~@body)])))
(defmacro ox-view-inherit [name model inherit &rest body]
"Inherited View simplification with name of the record, xmlid for model and
inherited view"
(setv module (get (.split __name__ ".") 2)
inherited (get (.split inherit ".") 1)
xmlid f"{inherited}_inherit_{module}")
`(do
(ox-view ~xmlid
[(ox-field-name ~name)
(ox-field-model ~model)
(ox-field-inherit ~inherit)
(ox-field-arch ~@body)])))
(defmacro ox-actions-server-code [xmlid name modelref code]
"Server actions of type code"
`(do
(ox-record {"id" ~xmlid "model" "ir.actions.server"}
[(ox-field-name ~name)
(ox-field {"name" "model_id" "ref" ~modelref} [])
(ox-field {"name" "state"} ["code"])
2019-09-18 09:25:30 +02:00
(ox-field {"name" "code"} [~code])])))
2019-09-17 16:39:34 +02:00
(defmacro ox-field [&rest args] `(xmlna "field" ~@args))
(defmacro ox-field-name [name] `(ox-field {"name" "name"} [~name]))
(defmacro ox-field-model [model] `(ox-field {"name" "model"} [~model]))
(defmacro ox-field-inherit [xmlid] `(ox-field {"name" "inherit_id" "ref" ~xmlid} []))
(defmacro ox-field-arch [&rest args] `(ox-field {"name" "arch" "type" "xml"} ~@args))
(defmacro/g! xml-write [filename tree]
"Write XML file according to filename and given tree"
`(do
(import [os [path]])
(setv ~g!output-xml (.tostring ET ~tree)
~g!output-path (.dirname path (.abspath path __file__))
~g!fpath (+ ~g!output-path "/" ~filename))
(with [f (open ~g!fpath "w")] (.write f ~g!output-xml))))