在Odoo中添加新的动态字段 [英] Add the new Dynamic Field in Odoo

查看:486
本文介绍了在Odoo中添加新的动态字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Odoo中基于Postgresql中的View添加新字段,而无需使用Odoo模型类文件. ?

Is it possible to add new field based on View in Postgresql in Odoo without using Odoo model class file. ?

推荐答案

用于在odoo中创建动态视图,最好参考一下 链接

for creating dynamic views in odoo, you better refer this link

这是解决方案

  • 为OpenERP对象指定参数_auto = False,因此不会自动创建与_columns字典相对应的表.

  • Specify the parameter _auto=False to the OpenERP object, so no table corresponding to the _columns dictionary is created automatically.

添加一个方法init(self,cr),该方法创建一个与_columns中声明的字段匹配的PostgreSQL视图.

Add a method init(self, cr) that creates a PostgreSQL View matching the fields declared in _columns.

Python代码:

class xyz(osv.osv):
_name = "xyz"
_description = "xxx"

_auto = False

_columns = {
            'unique_id': fields.char('Employee ID', size=12),
            'employee_id': fields.many2one('table3', "Name"),
        }

def init(self, cr):
    openerp.tools.drop_view_if_exists(cr, 'table_preview')
    cr.execute("""
        create or replace view payslip_preview as (
                    SELECT * FROM crosstab('SELECT ps.id as id, emp.unique_id as unique_id, emp.id as employee_i
                    FROM table1 psl 
                    JOIN table2 ps ON (ps.id = psl.slip_id) 
                    JOIN table3 emp ON (emp.id = ps.employee_id) 
                   WHERE ps.state IN (''draft'') ORDER BY 1',
                    'SELECT id FROM table4 ORDER BY sequence') AS 
                    (
                        "id" int,
                        "unique_id" varchar(10),
                        "employee_id" int,
                    )
            )
        """)

这篇关于在Odoo中添加新的动态字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆