ChaoqiYin / odoo_module_codes_generator

a generator for odoo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Odoo Module Codes Generator

this tool can generate codes for odoo with a file of sql

Depends:

python: 3.5+
pip: sqlparse 0.2.4

Gui for creating the files of sql:

recommend using Navicat for PostgreSQL 12.1

Explain:

  1. This tool can analyze sql to generates the Char、Text、Int、Float、Bool、Date、DateTime、Binary、Many2one、One2many、Many2many fields in Odoo
    The fields correspond to words in sql:

    ['varchar', 'char']: Char
    ['text']: Text
    ['int', 'int2', 'int4', 'int8']: Int
    ['float4', 'float8']: Float
    ['bool']: Bool
    ['time']: DateTime
    ['bytea']: Binary
  2. When creating model in the Navicat for PostgreSQL(nfp),the model's name in odoo correspond to the table's name in sql

  3. The id field in nfp's model will be ignored;if you checked Not Null ,the tool will generates required=True in field;if the Default Value has values,the tool will generates default=... in field;if the Comment has values,the tool will generates string=... in field

  4. The field of Many2one will create by Foreign Key relation,the tool will convert any field in sql's model to Many2one field in Odoo,and auto generates One2many field in corresponding model,the field Equally applicable Not Null and so on
    注意: Foreign Key relation can't begin with id

  5. The field of Many2many will create by Foreign Key relation too,the different with Many2one,the Foreign Key relation can't end with id,and you must need set the name of Foreign Key relation begin with 'm2m'

  6. Run and create files:

     import os
     from generator import parse_sql
    
     base_dir = os.path.dirname(__file__)  # 需要生成文件的路径
     sql_path = os.path.join(base_dir, 't_code.sql')  # sql文件的路径
    
    
     p = parse_sql.Parse(sql_path)  # 创建解析实例
     p.create_files(base_dir, thread_num=2)  # 生成文件

Odoo模块代码生成器

该项目能根据sql文件的内容生成odoo模块的model和view基本代码

依赖项

python版本: 3.5+
pip模块: sqlparse 0.2.4

sql文件生成工具

推荐Navicat for PostgreSQL 12.1

说明

  1. 该项目支持解析出Odoo内的Char、Text、Int、Float、Bool、Date、DateTime、Binary、Many2one、One2many、Many2many字段
    对应sql中的数据类型为:

    ['varchar', 'char']: Char
    ['text']: Text
    ['int', 'int2', 'int4', 'int8']: Int
    ['float4', 'float8']: Float
    ['bool']: Bool
    ['time']: DateTime
    ['bytea']: Binary
  2. 在Navicat for PostgreSQL(后面简称nfp)中建立模型时,table的名称即为odoo中每个model的对应名称

  3. nfp模型中的id字段会自动忽略不生成;如果勾选了Not Null选项,会在生成field时建立属性required=True;如果字段的Default Value处有值,会在生成field时建立属性default=...;如果字段的Comment处有值,会在生成field时建立属性string=...

  4. Many2one字段的建立根据Foreign Key关系链生成,会将外键字段从任意类型装换成Many2one类型,并在对应表中自动生成对应的One2many字段,Not Null等属性同样适用于Many2one字段
    注意: Foreign Key关系链起始字段不能为id

  5. Many2many字段的建立同样是根据Foreign Key关系链生成,与Many2one不同的是,Foreign Key关系链的指向字段同样不能为id,并且需要将Foreign Key关系链的Name属性变更为以m2m开始的关系链名称

  6. 执行解析并生成结构

     import os
     from generator import parse_sql
    
     base_dir = os.path.dirname(__file__)  # 需要生成文件的路径
     sql_path = os.path.join(base_dir, 't_code.sql')  # sql文件的路径
    
    
     p = parse_sql.Parse(sql_path)  # 创建解析实例
     p.create_files(base_dir, thread_num=2)  # 生成文件

About

a generator for odoo


Languages

Language:Python 100.0%