关于生产进度的统计开发
-
这样
<br />class mrp_production(osv.osv):<br /> _name="mrp.production"<br /> _inherit = "mrp.production" <br /> def _compute(self, cr, uid, ids, name, arg, context):<br /> res = {}<br /> for po in self.browse(cr, uid, ids):<br /> cr.execute("select mo.order, sum(mo.allqty) from mrp_extend as mo where mo.order=%s group by mo.order ",(po.name,)) <br /> <br /> record = cr.fetchone()<br /> if record:<br /> res[mo.id] = record[1]<br /> else:<br /> res[mo.id] = False<br /> return res<br /> <br /> _columns = { <br /> 'x_finished' : fields.function(_compute, type='float', method=True, string='已完成 '), <br /> }<br /> def process(self, cr, uid, ids, context={}):<br /> self._compute(cr, uid, ids, name, arg, context)<br /> return True <br /> <br />mrp_production()<br />
错误的地方有:
1.cr.execute("select mo.order, sum(mo.allqty) from mrp_extend as mo where mo.order=%s group by mo.order ",(po.name,))
many2one 存的是Id不是直接的值
2.res[mo.id] = record[1]
def process(self, cr, uid, ids, context={}):<br /> self._compute(cr, uid, ids, name, arg, context)<br /> return True
里面无需写方法,而且方法参数错了