[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
(fn [pair]
(if (even? (nth pair 0))
(mangle (nth pair 1))
(hy.mangle (nth pair 1))
(nth pair 1)))
(enumerate dic))))
`{~@mangled-dic})

View File

@ -25,7 +25,7 @@
(defmacro hydm [hy-domain]
"Generate Odoo domain from Hy like tuple domain"
(setv op (second hy-domain)
field (mangle (get hy-domain 2))
field (hy.mangle (get hy-domain 2))
value (get hy-domain 3))
`#(~field ~op ~value))
@ -33,8 +33,8 @@
#_(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)))
(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
@ -42,7 +42,7 @@
(defmacro compute-field [fname body]
"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)))
; Backend macros

View File

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

View File

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