我有一个包含很多字段和两个按钮的表单(保存并关闭,保存和新建) 单击“保存并新建”按钮时,我希望显示先前输入的字段值。
谢谢!
答案 0 :(得分:1)
好吧,我的第一个解决方案(使用上下文)没有成功:-(但我尝试了另一种方式,我不太喜欢它,但它可以帮助你。
按照我的例子.py:
from openerp.osv import orm, fields
class object_one(orm.Model):
_name = "object.one"
_columns = {
'name':fields.char('Name', size=128, required=True),
'many_ids':fields.many2many('object.many',string="Many Objects")
}
class object_many(orm.Model):
_name = "object.many"
_columns = {
'name':fields.char('Name', size=128, required=True),
'sel':fields.selection([('1','One'),
('2','Two'),
('3','Three')],
string="Selection", required=True),
}
def _get_sel(self, cr, uid, context={}):
many_id = self.search(cr, uid, [('create_uid','=',uid)], context=context, order="create_date desc", limit=1)
if many_id:
many = self.browse(cr, uid, many_id[0], context)
return many.sel
return False
_defaults = {
'sel':_get_sel
}
按照我的例子.xml:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="one_form" model="ir.ui.view">
<field name="name">one form view</field>
<field name="model">object.one</field>
<field name="arch" type="xml">
<form version="7.0" string="">
<group>
<field name="name" />
<field name="many_ids" />
</group>
</form>
</field>
</record>
<record id="one_tree" model="ir.ui.view">
<field name="name">one tree view</field>
<field name="model">object.one</field>
<field name="arch" type="xml">
<tree version="7.0" string="">
<field name="name" />
</tree>
</field>
</record>
<record id="many_form" model="ir.ui.view">
<field name="name">many form view</field>
<field name="model">object.many</field>
<field name="arch" type="xml">
<form version="7.0" string="">
<group>
<field name="name" />
<field name="sel" />
</group>
</form>
</field>
</record>
<record id="many_tree" model="ir.ui.view">
<field name="name">many tree view</field>
<field name="model">object.many</field>
<field name="arch" type="xml">
<tree version="7.0" string="">
<field name="name" />
<field name="sel" />
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="one_tree_action">
<field name="name">One Objects</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">object.one</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="view_id" ref="one_tree" />
</record>
<record model="ir.actions.act_window" id="many_tree_action">
<field name="name">Many Objects</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">object.many</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="view_id" ref="many_tree" />
</record>
<menuitem name="Testing Menu" id="testing_menu" />
<menuitem name="Sub Menu" parent="testing_menu" id="sub_menu" />
<menuitem action="one_tree_action" name="One Menu" parent="sub_menu" id="one_menu" />
<menuitem action="many_tree_action" name="Many Menu" parent="sub_menu" id="many_menu" />
</data>
</openerp>
您将看到,用户创建的每个多对象都将从db获取最后一个选择(sel)。所以它更适合你的问题。
希望这会对你有所帮助。