如何在 OpenERP 上创建动态视图
我需要帮助来创建动态视图。让我解释一下:我有 Form1 和 Form2 视图。 Form1 包含表达式
字段和提取
按钮。 Form2 包含从 Form1 中提取的表达式元素。例如,当您在 Form1 的表达式字段中输入 (a+b)*cd*0,5
时,Form2 应该提取并显示以下内容:
( - open brace
a - variable
+ - addition
b - variable
) - close brace
* - multiplication
c - variable
- - subtraction
d - variable
* - multiplication
0,5 - constant number
Now, Here is my class:
class wz_formula(osv.osv_memory):
"""
Formula Wizard
"""
_name = "wz.formula"
_inherit = "ir.wizard.screen"
_description = "Formula Wizard"
_columns = {
'name': fields.char('Formula name', required=True, size=64)
, 'expression': fields.char('expression', required=True, size=64)
, 'state': fields.selection([('init','init'),('done','done')], 'state', readonly=True)
}
_defaults = {
'state': 'init'
}
def next(self, cr, uid, ids, context=None):
if context is None:
context = {}
formula_obj = self.browse(cr, uid, ids)[0]
formula_name = formula_obj.name
infix = formula_obj.expression
if formula_name and expression:
modobj = self.pool.get('ir.module.module')
mids = modobj.search(cr, uid, [('state', '=', 'installed')])
modobj.update_translations(cr, uid, mids, [formula_name, expression], context or {})
self.write(cr, uid, ids, {'state': 'done'}, context=context)
return {
'name': _('Formula')
, 'view_type': 'form'
, 'view_mode': 'form'
, 'view_id': False
, 'res_model': 'wz.formula'
, 'domain': []
, 'context': dict(context, active_ids=ids)
, 'type': 'ir.actions.act_window'
, 'target': 'new'
, 'res_id': ids and ids[0] or False
}
# create an object
wz_formula()
Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_wz_formula" model="ir.ui.view">
<field name="name">Formula</field>
<field name="model">wz.formula</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Formula">
<group colspan="8" col="8" states="init">
<separator string="Formula" colspan="8"/>
<field name="state" invisible="1"/>
<field name="name"/>
<field name="expression" width="220"/>
<button special="cancel" string="Cancel" icon="gtk-cancel" colspan="1"/>
<button name="next" string="Next" type="object" icon="gtk-ok" colspan="1"/>
</group>
<group colspan="8" col="8" states="done">
<separator string="Done" colspan="8"/>
<button special="cancel" string="Close" icon="gtk-cancel"/>
</group>
</form>
</field>
</record>
<record id="action_view_wz_formula" model="ir.actions.act_window">
<field name="name">Formula</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">wz.formula</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem
name="Create a formula"
action="action_view_wz_formula"
id="menu_view_wz_formula"
parent="menu_fs_root" sequence="2"/>
</data>
</openerp>
So far,它只是在 Form1 和 Form2 之间切换。如何提取上面解释的表达式?
I need a help to create a dynamic view. Let me explain: I have Form1 and Form2 views. Form1 contains expression
field and extract
button. Form2 contains extracted elements of the expression from Form1. For example when you enter (a+b)*c-d*0,5
to Form1's expression field, Form2 should extract and display this:
( - open brace
a - variable
+ - addition
b - variable
) - close brace
* - multiplication
c - variable
- - subtraction
d - variable
* - multiplication
0,5 - constant number
Now, here is my class:
class wz_formula(osv.osv_memory):
"""
Formula Wizard
"""
_name = "wz.formula"
_inherit = "ir.wizard.screen"
_description = "Formula Wizard"
_columns = {
'name': fields.char('Formula name', required=True, size=64)
, 'expression': fields.char('expression', required=True, size=64)
, 'state': fields.selection([('init','init'),('done','done')], 'state', readonly=True)
}
_defaults = {
'state': 'init'
}
def next(self, cr, uid, ids, context=None):
if context is None:
context = {}
formula_obj = self.browse(cr, uid, ids)[0]
formula_name = formula_obj.name
infix = formula_obj.expression
if formula_name and expression:
modobj = self.pool.get('ir.module.module')
mids = modobj.search(cr, uid, [('state', '=', 'installed')])
modobj.update_translations(cr, uid, mids, [formula_name, expression], context or {})
self.write(cr, uid, ids, {'state': 'done'}, context=context)
return {
'name': _('Formula')
, 'view_type': 'form'
, 'view_mode': 'form'
, 'view_id': False
, 'res_model': 'wz.formula'
, 'domain': []
, 'context': dict(context, active_ids=ids)
, 'type': 'ir.actions.act_window'
, 'target': 'new'
, 'res_id': ids and ids[0] or False
}
# create an object
wz_formula()
Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_wz_formula" model="ir.ui.view">
<field name="name">Formula</field>
<field name="model">wz.formula</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Formula">
<group colspan="8" col="8" states="init">
<separator string="Formula" colspan="8"/>
<field name="state" invisible="1"/>
<field name="name"/>
<field name="expression" width="220"/>
<button special="cancel" string="Cancel" icon="gtk-cancel" colspan="1"/>
<button name="next" string="Next" type="object" icon="gtk-ok" colspan="1"/>
</group>
<group colspan="8" col="8" states="done">
<separator string="Done" colspan="8"/>
<button special="cancel" string="Close" icon="gtk-cancel"/>
</group>
</form>
</field>
</record>
<record id="action_view_wz_formula" model="ir.actions.act_window">
<field name="name">Formula</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">wz.formula</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem
name="Create a formula"
action="action_view_wz_formula"
id="menu_view_wz_formula"
parent="menu_fs_root" sequence="2"/>
</data>
</openerp>
So far, it just switches between Form1 and Form2. How can I extract the expression as I explained above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要在openerp v6中添加动态视图,请重写函数
fields_view_get()
result
将是一个字典,主要包含两个内容,Xml架构和字段。在
result['arch']
中提供 xml 架构作为字符串,在result['fields']
中提供字段作为字典的字典。然后返回结果。然后,您将根据您在字段和建筑中给出的内容获得视图。To add a dynamic view in openerp v6, override the function
fields_view_get()
result
will be a dictionary which contain mainly two things, Xml architecture and fields.Provide the xml architecture in
result['arch']
as string, provide the fields inresult['fields']
as dictionary of dictionaries. Then return the result. Then you will get a view according to what you have given in the fields and architecure.一种更简单的方法是...首先从第一种形式(形式1)中获取表达式,并根据您的选择对其进行评估,并在第二种形式中保留一个“文本”字段,该字段中的数据按照您的格式保存..
a simpler way would be... first get the expression from first form (FORM 1),and evaluate it as per your choice, and keep a "TEXT" field in second form which has this data in as per your format in that field..
我不确定你到底在问什么,但如果你只想解析用户的表达式,那么这个关于Python表达式解析器的问题 应该会有帮助。
I'm not sure exactly what you're asking, but if you just want to parse the user's expression, then this question on Python expression parsers should be helpful.