Python文件:
#!/usr/bin/python
from openerp.osv import fields, osv
import psycopg2
import sys
import pprint
select_list=[('SL01','CONSTRUCTION/BUILDING'),('SL02','CAPITAL/CAPEX'),('SL03','ELECTRICAL')]
select_sub1_list=[('ECDS08','CAPACITIOR'),('EDS07','RESISTANCE'),('EDS06','TRANSISTORS'),('EDS05','THYRISOSTRS'),('EDS04','SENSORS'),('EDS03','SINKS AND ELEMENTS'),('EDS02','DIODES'),('ECDS01','ELECTRONICS')]
select_sub2_list=[('01','Blue Capacitor'),('02','Blue Capacitor Mov')]
#select_sub3_list=[('01','470PF/1KV'),('02','CE471/1KV'),('03','B101K/1KV'),('04','CE474/100V')]
class laser_products(osv.osv):
_inherit = "product.product"
def select_return(self, cr, uid, ids=None, context=None):
conn_string = "host='localhost' dbname='new_scantech_laser' user='postgres' password='12345'"
conn = psycopg2.connect(conn_string)
cursor = conn.cursor()
cursor.execute("""SELECT main_cat from product_product""")
records = cursor.fetchall()
s=conn.commit()
return (records)
_columns = {
'laser_product_select': fields.selection(select_list,'Main category'),
'laser_sub1_product_select': fields.selection(select_sub1_list,'Sub 1 category'),
'laser_sub2_product_select': fields.selection(select_sub2_list,'Sub 2 category'),
'laser_sub3_product_select': fields.many2one("laser.erp",'Sub 3 category'),
'main_cat' : fields.selection(select_return,'Main sub Category'),
'temp1':fields.char("Product Code", readonly=True),
}
def onchange_laser_product_select(self,cr,uid,ids,laser_product_select,laser_sub1_product_select,laser_sub2_product_select,laser_sub3_product_select,context=None):
if(laser_product_select or laser_sub1_product_select or laser_sub2_product_select or laser_sub3_product_select):
if not (laser_sub1_product_select and laser_sub2_product_select and laser_sub3_product_select):
vals123 = {'default_code': str(laser_product_select)}
return {'value': vals123}
else:
if not (laser_sub2_product_select and laser_sub3_product_select):
vals123 = {'default_code': str(laser_product_select) + str(laser_sub1_product_select)}
return {'value':vals123}
else:
if not (laser_sub3_product_select):
vals123 = {'default_code': str(laser_product_select) + str(laser_sub1_product_select)+str(laser_sub2_product_select)}
return {'value':vals123}
else:
vals123 = {'default_code': str(laser_product_select) + str(laser_sub1_product_select)+str(laser_sub2_product_select) + str(laser_sub3_product_select)}
return {'value':vals123}
laser_products()
class laser_erp(osv.osv):
_name = "laser.erp"
_columns = {
'name': fields.char('Sequence')
}
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record model="ir.ui.view" id="laser_product_project">
<field name="name">product.normal.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<field name='list_price' position="after">
<field name="laser_product_select" on_change="onchange_laser_product_select(laser_product_select,laser_sub1_product_select,laser_sub2_product_select,laser_sub3_product_select,context)" on_change1="onchange_laser_product_select1(laser_product_select,laser_sub1_product_select,laser_sub2_product_select,laser_sub3_product_select,context)" />
<field name="laser_sub1_product_select" on_change="onchange_laser_product_select(laser_product_select,laser_sub1_product_select,laser_sub2_product_select,laser_sub3_product_select,context)" on_change1="onchange_laser_product_select1(laser_product_select,laser_sub1_product_select,laser_sub2_product_select,laser_sub3_product_select,context)"/>
<field name="laser_sub2_product_select" on_change="onchange_laser_product_select(laser_product_select,laser_sub1_product_select,laser_sub2_product_select,laser_sub3_product_select,context)" on_change1="onchange_laser_product_select1(laser_product_select,laser_sub1_product_select,laser_sub2_product_select,laser_sub3_product_select,context)"/>
<field name="laser_sub3_product_select" on_change="onchange_laser_product_select(laser_product_select,laser_sub1_product_select,laser_sub2_product_select,laser_sub3_product_select,context)" on_change1="onchange_laser_product_select1(laser_product_select,laser_sub1_product_select,laser_sub2_product_select,laser_sub3_product_select,context)"/>
<field name="main_cat"/>
</field>
</field>
</record>
</data>
</openerp>
在此主要子类别字段中是选择字段。它显示空白选择列表。实际上数据库中有4个条目,它显示了四个选择列表,但它们是空白请帮帮我