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

由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

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

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

请教如何在save的时候执行一个函数



  • 有如下的一个函数,我想在保存的时候更新一下partner中的数据,请问在哪里调用这个函数才能实现保存的时候执行呢?谢谢

    <br />def update_partner(self,cr,uid,ids, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; partner_obj = self.pool.get(&#039;res.partner&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; for op in self.browse(cr, uid, ids, context=context):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; partner = op.partner_id<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if partner.id:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vals= {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;sale_area&#039;:op.sale_area<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; partner_obj.write(cr,uid,[partner.id], vals)<br />&nbsp; &nbsp; &nbsp; &nbsp; return vals<br />
    


  • <br /><br />def write(self, cr, uid, ids, vals, context={}):<br />&nbsp; &nbsp; return super(xxxx, self).write(cr, uid, ids, vals, context=context) &amp;&amp; self.udpate_partner(cr, uid, ids, context=context)<br /><br />def update_partner(self,cr,uid,ids, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; partner_obj = self.pool.get(&#039;res.partner&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; for op in self.browse(cr, uid, ids, context=context):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; partner = op.partner_id<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if partner.id:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vals= {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;sale_area&#039;:op.sale_area<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; partner_obj.write(cr,uid,[partner.id], vals)<br />&nbsp; &nbsp; &nbsp; &nbsp; return vals<br /><br />
    



  • 谢谢shelly,非常感谢,问题已经解决


Log in to reply