[MOV][REF]Move macros to their own package
This commit is contained in:
parent
c18e598dfb
commit
cda0282a33
18
hy_odoo/macros/__init__.hy
Normal file
18
hy_odoo/macros/__init__.hy
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
;; -*- coding: utf-8 -*-
|
||||||
|
;;
|
||||||
|
;; Copyright 2021 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/>.
|
||||||
|
|
||||||
|
; (require [hy-odoo.macros [general odoo test]])
|
58
hy_odoo/macros/odoo.hy
Normal file
58
hy_odoo/macros/odoo.hy
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
;; -*- coding: utf-8 -*-
|
||||||
|
;;
|
||||||
|
;; Copyright 2019-2021 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 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 (mangle (nth hy-domain 2))
|
||||||
|
value (nth 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_{(mangle field)}" descr f"Computes {field}"
|
||||||
|
dependencies (list (map mangle dependencies)))
|
||||||
|
(import [hy.models [HySymbol]])
|
||||||
|
`(with-decorator (.depends api ~@dependencies)
|
||||||
|
(defn ~(HySymbol fname) [self]
|
||||||
|
~descr
|
||||||
|
~body)))
|
||||||
|
|
||||||
|
(defmacro compute-field [fname body]
|
||||||
|
"Takes fname Symbol and body to create computed field"
|
||||||
|
(setv fn-name f"_compute_{(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)))
|
Loading…
x
Reference in New Issue
Block a user