tryton-hy> hello

writting tryton modules with hy

Why?

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.

My experience so far…

Writting a few modules as a proof of concept. I am using these to learn hy and tryton at the same time.

Installation

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

Learnning Modules

Each module concentrates on a different concept.

hello

Basic Module with a simple Model.

hello 4.4+

hello 4.0

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)))

hello-word

Extending hello to add a field

hello-world

(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)))

hello-history

Extending hello to support history

hello-history

hello-active

Extending hello to support active

hello-active

hello-company-prefix

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

motto

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.

motto