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

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

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

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

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

关于生产进度的统计开发



  • 大家好,因为实际需要,例如一个生产订单要生产a产品10000,今天完成1000,明天完成1000,这样我每天需要记录当天完成数,因此我做了一个form专门来记录生产订单的进度,我有个问题,就是记录进度的功能已经实现了,但是怎样实现我所记录的进度统计呢(当我选了某个生产单,可以知道它已完成了2000)?该如何开发?

    附件是我的代码,请大家帮帮忙


  • 管理员

    这样

    <br />class mrp_production(osv.osv):<br />&nbsp; &nbsp; _name=&quot;mrp.production&quot;<br />&nbsp; &nbsp; _inherit = &quot;mrp.production&quot;	<br />&nbsp; &nbsp; def&nbsp; _compute(self, cr, uid, ids, name, arg, context):<br />&nbsp; &nbsp; &nbsp; &nbsp; res = {}<br />&nbsp; &nbsp; &nbsp; &nbsp; for po in self.browse(cr, uid, ids):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cr.execute(&quot;select mo.order, sum(mo.allqty) from mrp_extend as mo&nbsp; where mo.order=%s group by mo.order &quot;,(po.name,))&nbsp; &nbsp; &nbsp;  <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; record = cr.fetchone()<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if record:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res[mo.id] = record[1]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res[mo.id] = False<br />&nbsp; &nbsp; &nbsp; &nbsp; return res<br />		<br />&nbsp; &nbsp; _columns = {&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;x_finished&#039; : fields.function(_compute, type=&#039;float&#039;, method=True, string=&#039;已完成 &#039;),&nbsp; &nbsp; <br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; def process(self, cr, uid, ids, context={}):<br />&nbsp; &nbsp; &nbsp; &nbsp; self._compute(cr, uid, ids, name, arg, context)<br />&nbsp; &nbsp; &nbsp; &nbsp; return True <br />		<br />mrp_production()<br />
    



    错误的地方有:
    1.

    cr.execute(&quot;select mo.order, sum(mo.allqty) from mrp_extend as mo&nbsp; where mo.order=%s group by mo.order &quot;,(po.name,))&nbsp; &nbsp; 
    

     

    many2one 存的是Id不是直接的值

    2.

    res[mo.id] = record[1]
    


    mo.id 不存在,改为po.id

    3.

     def process(self, cr, uid, ids, context={}):<br />&nbsp; &nbsp; &nbsp; &nbsp; self._compute(cr, uid, ids, name, arg, context)<br />&nbsp; &nbsp; &nbsp; &nbsp; return True 
    


    里面无需写方法,而且方法参数错了



  • 谢谢josuhua,working了,但是那些方法的参数是如何来定的?



  • 同问,参数应该如何定义?


  • 管理员

    参数除了基本参数外,其他你喜欢怎么定就怎么定,基本参数,可以参考addon里面


Log in to reply