
Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn
由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解
本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!
开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号
如果您登录系统碰到问题,请在微信公众号留言:
【已解决】button所执行的方法(弹出一个窗口)
-
在openerp里面我对于button所触发的方法不是十分了解。
从devloper文档里面得出
[quote]Button
: addabuttonusingthestringattributeaslabel. Whenclicked,itcantriggermethodsontheobject,workflow
transitionsor actions(reports,wizards,...).- string: definethebutton’slabel
- confirm: the messagefortheconfirmationwindow, ifneeded. Eg: confirm=”Are you sure?”
- name: thename of thefunctiontocallwhen thebuttonis pressed. In the case it’s an object function, it must take 4 arguments: cr, uid,ids, –
cr isadatabasecursor
– uidistheuserIDoftheuser who clicked thebutton
– idsis the recordIDlist
– **argsis atuple of additional arguments - states: a comma-separated list of states (from the state field or from the workflow) in which the button must
appear. Ifthestatesattributeis not given, the buttonisalwaysvisible. - type: thisattributecanhave3values – “workflow” (value by default): the function to call is a function of
workflow
– “object”: thefunction to callis amethod of theobject
– “action”: callanactioninstead ofafunction
Example
[/quote]
[attach]211[/attach]我现在就是想添加一个button通过读取使用者在BOM code里面填入的东西,来执行相应的操作。
但是不知为什么当我点击create的时候,会出现错误如下:[attach]212[/attach] -----> [attach]213[/attach]
下面是我view的代码[code]
<button name="create_product_with_bomcode" string="CREATE"/>
</openerp>
[/code]我在create_product_with_bomcode应该怎么写才可以读取到BOM Code里面填入的数据呢?
我说的是直接在client上面填入,之后点击create,按照填入的bomcode进行操作。这个bomcode不用保存的。谢谢大家了。。。。:)
[[i] 本帖最后由 popkar77 于 2009-9-21 16:26 编辑 [/i]]
-
你的这个需求建议你看看 google_map 模块.那个模块 里的 Street2 后面的 Map 按钮..
Google_map 使用的是 wizard
-
参考 tiny_purchase
-
好象理论上,只需要 在 class 里设置 与 button name 一致的 function 然后 return True 就行了吧?
没有测试.你可以把你的代码贴出来大家看看.
-
谢谢oldrev ,参考了tiny_purchase了,但是我发现他的button是调用为wrokflow的
我这里用的应该是action
但是就是不知道应该怎么写.. -
谢谢大家:handshake
[[i] 本帖最后由 popkar77 于 2009-9-16 14:26 编辑 [/i]]
-
嗯. 我发现你就把我当空气而已.....
-
...水,你说的方法我试过啦....忘记谢撒...
我发现里面好像只要在某个界面添加一个button方法,就要先把该界面的应定要填的都填了....
现在问题成了,点击一个button,弹出一个窗口...[[i] 本帖最后由 popkar77 于 2009-9-16 14:30 编辑 [/i]]
-
弹出窗口是 OpenERP 控制的,这是 MVC 模式的分布式程序,不是事件驱动的桌面程序
-
解决了。
关于弹出窗口可以看module 的project里面的例子比较简单
具体就是这句[code]
<button name="%(action_config_compute_remaining)d" string="Review" type="action" colspan="1" target="new" states="open,pending"/>
[/code]而="%(action_config_compute_remaining)d"这个写法官方论坛上也得出答案
[quote]
It will search for id of that action in ir_model_data and replace it with integer value.
you can check the view from Administration/Customization/User Interface/Views
You will get id of that action in views[/quote]
结果如下:
[attach]220[/attach][[i] 本帖最后由 popkar77 于 2009-9-21 16:37 编辑 [/i]]
-
这个 %(....)d 是指向的一个什么ID呢? 一个 view 的ID???
-
view ID
我举个例子,例如:project这个moudule
project_view.xml
里面的[code]
<record id="view_config_compute_remaining" model="ir.ui.view">
<field name="name">Compute Remaining Hours </field>
<field name="model">config.compute.remaining</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Remaining Hours">
<separator colspan="4" string="Change Remaining Hours"/>
<newline/>
<field name="remaining_hours" widget="float_time"/>
<group col="4" colspan="4">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-ok" name="compute_hours" string="Update" type="object"/>
</group>
</form>
</field>
</record><record id="action_config_compute_remaining" model="ir.actions.act_window">
<field name="name">Compute Remaining Hours</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">config.compute.remaining</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
[/code][code]
<button name="%(action_config_compute_remaining)d" string="Review" type="action" colspan="1" target="new" states="open,pending"/>
[/code]action_config_compute_remaining就是一个view的id,
最上面的view_config_compute_remaining就是要弹出窗口的详细内容。
view_config_compute_remaining和action_config_compute_remaining的连接方法就是field name
[code]
<field name="name">Compute Remaining Hours </field>
[/code] -
哇哩....可不可以在按钮上是动态文字.
如 string="查看订单(%d)详情" % (sale_order.id)
-
你试试看吧