請教在Function的return值中如何設定之後顯示view的過濾顯示條件
-
小弟寫了個程式(輸入 gp_name以及其他參數然後以此條件寫入DB)
希望在_create_product執行完後能跳到一頁只顯示剛剛生成的資料(以gp_name為搜尋條件)
試著用以下方式,但似乎無作用,請問大大是否有建議or解決方法 謝謝
return {
[glow=red,2,300][b] 'domain': [('x_group','=',gp_name)],
#'domain': [('x_group','in',gp_name)],[/b][/glow]
'name': _('create_product_by_group'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'product.product',
'type': 'ir.actions.act_window',
}
原始碼如下:
import wizard
import pooler
from datetime import *
from tools.translate import _ # Used for translations
import time
view_form="""<?xml version="1.0"?>
<form string="Create product by group">
<group colspan="4" col="4">
<separator string="Group data" colspan="4"/>
<field name="gp_name" string="Group:"/>
</group>
<group colspan="4" col="4">
<separator string="Power data" colspan="4"/>
<field name="sph_from" string="Sphere Power from:"/>
<field name="sph_to" string="to:"/>
<field name="cyl_from" string="Cylinder Power from:"/>
<field name="cyl_to" string="to:"/>
</group>
</form>"""
fields_form = {
#'gp_name': {'string': ' gp_name ', 'type': 'float', 'default': lambda *a: 0.0 },
'gp_name': {'string': ' gp_name ', 'type': 'char', 'default': lambda *a: '' },
'sph_from': {'string': ' Sph_from ', 'type': 'float', 'default': lambda *a: 0.0 },
'sph_to': {'string': ' Sph_to ', 'type': 'float', 'default': lambda *a: 0.0 },
'cyl_from': {'string': ' Cyl_from ', 'type': 'float', 'default': lambda a: 0.0 },
'cyl_to': {'string': ' Cyl_to ', 'type': 'float', 'default': lambda a: 0.0 },
}
class wizard_create_product(wizard.interface):
def _create_product(self, cr, uid, data, context):
gp_name=(data['form']['gp_name'])
sph_from=float(data['form']['sph_from'])
sph_to=float(data['form']['sph_to'])
cyl_from=float(data['form']['cyl_from'])
cyl_to=float(data['form']['cyl_to'])
if gp_name!='':
default_code="TEST_CODE"
name_template="test_prosuct"
list_price="0"
standard_price="0"
DT="2011-11-11 10:00:00.000"
sph_diff=abs(sph_from)+abs(sph_to)
count_sph_diff=int(sph_diff/0.25)
cyl_diff=abs(cyl_from)+abs(cyl_to)
count_cyl_diff=int(cyl_diff/0.25)
sph_mark=''
cyl_mark=''
diff=0.25
now_sph=0
now_cyl=0
for x in range(count_sph_diff):
now_sph=sph_from-(diffx)
if now_sph>0:
sph_mark='+'
for y in range(count_cyl_diff):
now_cyl=cyl_from-(diffy)
if now_cyl>0:
cyl_mark='+'
DT=str(datetime.now())
default_code=gp_name+sph_mark+str(now_sph)+cyl_mark+str(now_cyl)
name_template=str(gp_name)+'_SPY:'+str(now_sph)+'CYL:'+str(now_cyl)
cr.execute("""select id from product_template where name='"""+str(name_template)+"""'""")
resA = cr.fetchall()
if not resA:
cr.execute("""INSERT INTO product_template(create_uid, create_date, write_date, write_uid, supply_method, list_price, standard_price, mes_type, uom_id, uos_coeff, purchase_ok,company_id, name, uom_po_id, type, procure_method, cost_method, rental, sale_ok, sale_delay, produce_delay, categ_id) VALUES('1','"""+DT+"""','"""+DT+"""','1','buy',"""+list_price+""","""+standard_price+""",'fixed','1',1.0,TRUE,'1','"""+name_template+"""','1','product','make_to_stock','standard',FALSE,TRUE,'7','1','22')""")
T_ID="0"
cr.execute("""select id from product_template where name='"""+name_template+"""'""")
res = cr.fetchall()
for row in res:
T_ID=str(row[0])
cr.execute("""INSERT INTO product_product(create_uid, create_date, write_date, write_uid, price_extra,default_code, name_template, active, product_tmpl_id,price_margin, track_production, valuation, track_outgoing, track_incoming) VALUES ('1','"""+DT+"""','"""+DT+"""','1',0,'"""+default_code+"""','"""+name_template+"""',TRUE,'"""+str(T_ID)+"""',1.0,FALSE,'manual_periodic',FALSE,FALSE)""")
else:
warning = {
'title': 'No Group name!',
'message': 'Please input group name'
}
#return []
return {
[glow=red,2,300][b] 'domain': [('x_group','=',gp_name)],
#'domain': [('x_group','in',gp_name)],[/b][/glow]
'name': _('create_product_by_group'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'product.product',
'type': 'ir.actions.act_window',
}
states = {
'init': {
'actions': [],
'result': {
'type': 'form',
'arch': view_form,
'fields': fields_form,
'state': [
('end','Cancel','gtk-cancel'),
('finish','Ok','gtk-ok',True),
]
}
},
'finish': {
'actions': [],
'result': {
'type': 'action',
'action': _create_product,
'state': 'end',
}
},
}
wizard_create_product('cr_product.create_product_wizard') -
只有一点小问题,domain 是根据对象字段进行过滤的,而x_group并不是product_product表的字段,至少我没有看到你为该字段插入值
把domain改成如下试试,'domain' : [('name', 'like', gp_name)]<br />