Odoo中文社区可以通过以下三个域名访问:shine-it.net , odoocn.org,odoo.net.cn

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

关于在后台获取前台field或者input的值的问题



  • 开始学习odoo,碰上如何获取界面filed 的内容和input的内容,以及如何修改的问题:
    这个是界面视图,里面有个field和一个input

    <br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;openerp&gt;<br />&nbsp; &nbsp; &lt;data&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;!--定义列表视图--&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;record model=&quot;ir.ui.view&quot; id=&quot;test_view&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;name&quot;&gt;test view&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;type&quot;&gt;form&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;model&quot;&gt;test.model&lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;t&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;oe_view_manager_view_form&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;oe_form&quot;&gt;<br />	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;form&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;myname&quot; /&gt;&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;text&quot; id=&quot;yourname&quot;&nbsp; /&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;button name=&quot;on_changepwd_myname&quot; string=&quot;修改&quot; type=&quot;object&quot; /&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/form&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/t&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/field&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/record&gt;<br />&lt;/data&gt;<br />&lt;/openerp&gt;<br />
    



    在.py文件里面的on_changepwd_myname里面,怎么样才能获取上面的 field的值,并把他们两个对调过来

    <br /># -*- coding:utf-8 -*- #<br /><br />from openerp.osv import osv,fields<br />import commands<br /><br />class test_model(osv.osv):<br />&nbsp; &nbsp; _name=&quot;test.model&quot;<br />&nbsp; &nbsp; _columns={<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;myname&#039;:fields.char(string=&quot;我的姓名&quot;,size=32,sotre=False),<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; def on_changepwd_admin(self, cr, uid,ids, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp;  这里怎么获取界面上&lt;field name=&quot;myname&quot; /&gt;和&lt;input type=&quot;text&quot; id=&quot;yourname&quot;&nbsp; /&gt; 的值,并且在后台对调后回显到界面上<br />
    


  • 可以获取filed的值了如下:(input的值暂时不知道怎么获取)

    &nbsp; &nbsp;  <br />objs= self.browse(cr,uid,ids);<br />strMyname=objs.myname<br />
    


    新问题是,如何修改view界面上filed的值呢,是不是一定要调用javascript里面的函数来修改,还是还有其他方法?



  • 你现在这种方法, 是需要用JS来玩的. 也就是用 client action.



  • 哦,看来只能走 client action的路,我就觉得这样也太麻烦了。