[WIP][FIX]Hy odoo : wip last fixed for 0.24.0

This commit is contained in:
Fabien BOURGEOIS 2022-11-01 19:55:52 +01:00
parent 5542001dc6
commit 1e8d7852ba
4 changed files with 30 additions and 27 deletions

View File

@ -26,7 +26,7 @@
(map (map
(fn [pair] (fn [pair]
(if (even? (nth pair 0)) (if (even? (nth pair 0))
(mangle (nth pair 1)) (hy.mangle (nth pair 1))
(nth pair 1))) (nth pair 1)))
(enumerate dic)))) (enumerate dic))))
`{~@mangled-dic}) `{~@mangled-dic})

View File

@ -25,7 +25,7 @@
(defmacro hydm [hy-domain] (defmacro hydm [hy-domain]
"Generate Odoo domain from Hy like tuple domain" "Generate Odoo domain from Hy like tuple domain"
(setv op (second hy-domain) (setv op (second hy-domain)
field (mangle (get hy-domain 2)) field (hy.mangle (get hy-domain 2))
value (get hy-domain 3)) value (get hy-domain 3))
`#(~field ~op ~value)) `#(~field ~op ~value))
@ -33,8 +33,8 @@
#_(defmacro/g! compute-fn [field dependencies body] #_(defmacro/g! compute-fn [field dependencies body]
"Macro to make computed definition smoother" "Macro to make computed definition smoother"
(setv fname f"_compute_{(mangle field)}" descr f"Computes {field}" (setv fname f"_compute_{(hy.mangle field)}" descr f"Computes {field}"
dependencies (list (map mangle dependencies))) dependencies (list (map hy.mangle dependencies)))
(import hy.models [HySymbol] (import hy.models [HySymbol]
`(defn [(.depends api ~@dependencies)] ~(HySymbol fname) [self] `(defn [(.depends api ~@dependencies)] ~(HySymbol fname) [self]
~descr ~descr
@ -42,7 +42,7 @@
(defmacro compute-field [fname body] (defmacro compute-field [fname body]
"Takes fname Symbol and body to create computed field" "Takes fname Symbol and body to create computed field"
(setv fn-name f"_compute_{(mangle fname)}") (setv fn-name f"_compute_{(hy.mangle fname)}")
`(setv ~fname (~@body :compute ~fn-name))) `(setv ~fname (~@body :compute ~fn-name)))
; Backend macros ; Backend macros

View File

@ -17,7 +17,8 @@
" Odoo macros and helpers " " Odoo macros and helpers "
(require hy-odoo.mgeneral [instance?]) (require hyrule.collections [assoc]
hy-odoo.mgeneral [instance?])
(import os [path] (import os [path]
hy-odoo.xml [xmlroot xmln]) hy-odoo.xml [xmlroot xmln])
@ -27,7 +28,7 @@
"Generate Odoo domain from Hy like tuple domain" "Generate Odoo domain from Hy like tuple domain"
(do (do
(setv #(op field value) hy-domain (setv #(op field value) hy-domain
field (mangle field) field (hy.mangle field)
value (when (string? value) f"'{value}'" value)) value (when (string? value) f"'{value}'" value))
(return f"('{field}', '{op}', {value})"))) (return f"('{field}', '{op}', {value})")))
@ -35,20 +36,20 @@
(defn odoo [children] (xmlroot (xmln "odoo" {} children))) (defn odoo [children] (xmlroot (xmln "odoo" {} children)))
(defn data [&rest args] (defn data [#* args]
"Special data node, allow optional args on data tag" "Special data node, allow optional args on data tag"
(when (= (len args) 1) (setv args (.insert (list args) 0 {}))) (when (= (len args) 1) (setv args (.insert (list args) 0 {})))
(xmln "data" #*args)) (xmln "data" args))
; Aliases ; Aliases
(defn function [&rest args] (xmln "function" #*args)) (defn function [#* args] (xmln "function" #*args))
(defn record [&rest args] (xmln "record" #*args)) (defn record [#* args] (xmln "record" #*args))
(defn form [&rest args] (xmln "form" #*args)) (defn form [#* args] (xmln "form" #*args))
(defn tree [&rest args] (xmln "tree" #*args)) (defn tree [#* args] (xmln "tree" #*args))
(defn search [&rest args] (xmln "search" #*args)) (defn search [#* args] (xmln "search" #*args))
; Actions ; Actions
(defn act-window [&rest args] (xmln "act_window" #*args)) (defn act-window [#* args] (xmln "act_window" #*args))
(defn act-window-model [model attrs] (defn act-window-model [model attrs]
" Build new act_window from model and args" " Build new act_window from model and args"
@ -79,7 +80,7 @@
(field {"name" "value" "eval" action})])) (field {"name" "value" "eval" action})]))
; Menus ; Menus
(defn menuitem [&rest args] (xmln "menuitem" #*args)) (defn menuitem [#* args] (xmln "menuitem" #*args))
(defn menuitem-model [model attrs] (defn menuitem-model [model attrs]
" Build new menuitem from model and attrs" " Build new menuitem from model and attrs"
@ -91,21 +92,21 @@
(menuitem cloned-attrs)) (menuitem cloned-attrs))
; Form aliases ; Form aliases
(defn group [&rest args] (xmln "group" #*args)) (defn group [#* args] (xmln "group" #*args))
(defn header [&rest args] (xmln "header" #*args)) (defn header [#* args] (xmln "header" #*args))
(defn footer [&rest args] (xmln "footer" #*args)) (defn footer [#* args] (xmln "footer" #*args))
(defn sheet [&rest args] (xmln "sheet" #*args)) (defn sheet [#* args] (xmln "sheet" #*args))
(defn button [&rest args] (xmln "button" #*args)) (defn button [#* args] (xmln "button" #*args))
(defn p [&rest args] (xmln "p" #*args)) (defn p [#* args] (xmln "p" #*args))
(defn xpath [&rest args] (xmln "xpath" #*args)) (defn xpath [#* args] (xmln "xpath" #*args))
(defn attribute [name value] (xmln "attribute" {"name" name} [value])) (defn attribute [name value] (xmln "attribute" {"name" name} [value]))
; Fields ; Fields
(defn field [&rest args] (defn field [#* args]
"Special field allowing mangling name attribute" "Special field allowing mangling name attribute"
(setv attrs (get args 0)) (setv attrs (get args 0))
(when (and (instance? dict attrs) (in "name" attrs)) (when (and (instance? dict attrs) (in "name" attrs))
(assoc attrs "name" (mangle (get attrs "name"))) (assoc attrs "name" (hy.mangle (get attrs "name")))
(setv args (list args)) (setv args (list args))
(assoc args 0 attrs) (assoc args 0 attrs)
(setv args (tuple args))) (setv args (tuple args)))
@ -114,10 +115,10 @@
(defn field-name [name] (field {"name" "name"} [name])) (defn field-name [name] (field {"name" "name"} [name]))
(defn field-model [model] (field {"name" "model"} [model])) (defn field-model [model] (field {"name" "model"} [model]))
(defn field-inherit [xmlid] (field {"name" "inherit_id" "ref" xmlid} [])) (defn field-inherit [xmlid] (field {"name" "inherit_id" "ref" xmlid} []))
(defn field-arch [&rest args] (field {"name" "arch" "type" "xml"} #*args)) (defn field-arch [#* args] (field {"name" "arch" "type" "xml"} #*args))
; Search ; Search
(defn filter [&rest args] (xmln "filter" #*args)) (defn filter [#* args] (xmln "filter" #*args))
; Views ; Views
(defn view [xmlid children] (record {"id" xmlid "model" "ir.ui.view"} children)) (defn view [xmlid children] (record {"id" xmlid "model" "ir.ui.view"} children))

View File

@ -17,6 +17,8 @@
" Hy General Utils " " Hy General Utils "
(require hyrule.collections [assoc])
(defn pick [keys record] (defn pick [keys record]
(reduce (reduce
(fn [acc key] (fn [acc key]