47 lines
1.5 KiB
Hy
47 lines
1.5 KiB
Hy
;; Copyright 2019-2022 Fabien Bourgeois <fabien@yaltik.com>
|
|
;;
|
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
" Odoo related macros "
|
|
|
|
(defmacro o-cmod [model-name] `(. cls env [~model-name]))
|
|
(defmacro o-mod [model-name] `(. self env [~model-name]))
|
|
(defmacro o-cref [ref-name] `((. cls env ref) ~ref-name))
|
|
(defmacro o-ref [ref-name] `((. self env ref) ~ref-name))
|
|
|
|
(defmacro hydm [hy-domain]
|
|
"Generate Odoo domain from Hy like tuple domain"
|
|
(setv op (second hy-domain)
|
|
field (hy.mangle (get hy-domain 2))
|
|
value (get hy-domain 3))
|
|
`#(~field ~op ~value))
|
|
|
|
; Odoo ORM macros
|
|
|
|
#_(defmacro/g! compute-fn [field dependencies body]
|
|
"Macro to make computed definition smoother"
|
|
(setv fname f"_compute_{(hy.mangle field)}" descr f"Computes {field}"
|
|
dependencies (list (map hy.mangle dependencies)))
|
|
(import hy.models [HySymbol]
|
|
`(defn [(.depends api ~@dependencies)] ~(HySymbol fname) [self]
|
|
~descr
|
|
~body)))
|
|
|
|
(defmacro compute-field [fname body]
|
|
"Takes fname Symbol and body to create computed field"
|
|
(setv fn-name f"_compute_{(hy.mangle fname)}")
|
|
`(setv ~fname (~@body :compute ~fn-name)))
|
|
|
|
; Backend macros
|
|
|
|
(defmacro __ [sentence] `((py "_") ~sentence))
|
|
|
|
(defmacro logger []
|
|
`(do
|
|
(import logging)
|
|
(setv _logger (.getLogger logging --name--))))
|
|
|
|
(defmacro pdb [] `(do (import [pdb [set-trace]]) (set-trace)))
|