Lisp rules.
Tryton (written in python) is a nice open source ERP with many modules on it.
Wouldn’t it be nice to extend it with a Lisp?
Hy is a dialect of Lisp embedded in python that allows us to do just that.
Writting a few modules as a proof of concept. I am using these to learn hy and tryton at the same time.
Install trytond the usual way but add hy via pip install at the end.
pip install git+https://github.com/hylang/hy.git
also possible:
pip install hy
Each module concentrates on a different concept.
Basic Module with a simple Model.
xml files and init.py as usual (with python). hello.hy instead of hello.py
(import [trytond.model [ModelSQL ModelView fields]])
(def --all-- ["Hello"])
(defclass Hello [ModelSQL ModelView]
"Hello World"
[--name-- "hello"
name (.Char fields "Name" :required True)
greeting (.Function fields (.Char fields "Greeting") "get_greeting")]
(defn get-greeting [self name]
(.format "Hello {}" self.name)))
Extending hello to add a field
(import [trytond.pool [PoolMeta]])
(import [trytond.model [fields]])
(def --all-- ["Hello"])
(defclass Hello []
"Hello World with surname"
[--name-- "hello"
--metaclass-- PoolMeta
surname (.Char fields "Surname")]
(defn get-greeting [self name]
(setv su (super Hello self)
res (.get_greeting su name))
(if self.surname
(+ res " " self.surname)
res)))
Extending hello to support history
Extending hello to support active
Extenging hello to add a company field. Prefix field diferent for each company - multi-company
hello-company-prefix post 4.4 with MultiValue
hello-company-prefix pre 4.4 with Prototype
Testing multi-company. The model instances are only visible for the users of the company. The model has a field company which will be filter by using a rule.