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

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

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

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

如何修改原class里的方法



  • 按照Odoo的风格,理论上:<br />Class A中的方法可以由继承A的ClassB中被修改  ?<br /><br />问题如下:<br /><br />在stock.py中的:<br /><br />[quote]<br />class stock_picking(models.Model):<br />    _name = "stock.picking"<br />    _inherit = ['mail.thread']<br />    _description = "Transfer"<br />    _order = "priority desc, date asc, id desc"<br /><br />    def _set_min_date(.....<br />[/quote]<br /><br />有<br /><br />[quote]<br /><br /><br />    def create_lots_for_picking(self, cr, uid, ids, context=None):<br />        lot_obj = self.pool['stock.production.lot']<br />        opslot_obj = self.pool['stock.pack.operation.lot']<br />        to_unlink = []<br />        for picking in self.browse(cr, uid, ids, context=context):<br />            for ops in picking.pack_operation_ids:<br />                for opslot in ops.pack_lot_ids:<br />                    if not opslot.lot_id:<br />                        print '=============not find stock.production.lot, create lot:',opslot.lot_name,ops.product_id.id,opslot.lot_weight<br />                        lot_id = lot_obj.create(cr, uid, {'name': opslot.lot_name, 'product_id': ops.product_id.id}, context=context)<br />                      <br />                        opslot_obj.write(cr, uid, [opslot.id], {'lot_id':lot_id}, context=context)<br />                #Unlink pack operations where qty = 0<br />                to_unlink += [x.id for x in ops.pack_lot_ids if x.qty == 0.0]<br />        opslot_obj.unlink(cr, uid, to_unlink, context=context)<br /><br />[/quote]<br /><br />现在需要修改这个方法,新建模块后:<br /><br />[quote]<br /><br />class dy_stock_picking(models.Model):<br />    inherit = 'stock.picking'<br /><br />    def create_lots_for_picking(self, cr, uid, ids, context=None):<br />        print 'dy.stock.picking==============='<br />        lot_obj = self.pool['stock.production.lot']<br />        opslot_obj = self.pool['stock.pack.operation.lot']<br />        to_unlink = []<br />        for picking in self.browse(cr, uid, ids, context=context):<br />            for ops in picking.pack_operation_ids:<br />                for opslot in ops.pack_lot_ids:<br />                    if not opslot.lot_id:<br />                        print 'dy.stock.picking=============not find stock.production.lot, create lot:',opslot.lot_name,ops.product_id.id<br />                        lot_id = lot_obj.create(cr, uid, {'name': opslot.lot_name, 'product_id': ops.product_id.id, 'lot_weight': opslot.lot_weight}, context=context)<br />                        opslot_obj.write(cr, uid, [opslot.id], {'lot_id':lot_id}, context=context)<br />                #Unlink pack operations where qty = 0<br />                to_unlink += [x.id for x in ops.pack_lot_ids if x.qty == 0.0]<br />        opslot_obj.unlink(cr, uid, to_unlink, context=context)<br /><br />[/quote]<br /><br />运行后发现,没有成功:<br />[img]http://shine-it.net/index.php?action=dlattach;topic=17670.0;attach=5160;image[/img]<br />还是调用了原来的方法<br />什么原因?



  • 按照Odoo的风格,理论上:<br />Class A中的方法可以由继承A的ClassB中被修改  ?<br /><br />问题如下:<br /><br />在stock.py中的:<br /><br />[quote]<br />class stock_picking(models.Model):<br />    _name = "stock.picking"<br />    _inherit = ['mail.thread']<br />    _description = "Transfer"<br />    _order = "priority desc, date asc, id desc"<br /><br />    def _set_min_date(.....<br />[/quote]<br /><br />有<br /><br />[quote]<br /><br /><br />    def create_lots_for_picking(self, cr, uid, ids, context=None):<br />        lot_obj = self.pool['stock.production.lot']<br />        opslot_obj = self.pool['stock.pack.operation.lot']<br />        to_unlink = []<br />        for picking in self.browse(cr, uid, ids, context=context):<br />            for ops in picking.pack_operation_ids:<br />                for opslot in ops.pack_lot_ids:<br />                    if not opslot.lot_id:<br />                        print '=============not find stock.production.lot, create lot:',opslot.lot_name,ops.product_id.id,opslot.lot_weight<br />                        lot_id = lot_obj.create(cr, uid, {'name': opslot.lot_name, 'product_id': ops.product_id.id}, context=context)<br />                      <br />                        opslot_obj.write(cr, uid, [opslot.id], {'lot_id':lot_id}, context=context)<br />                #Unlink pack operations where qty = 0<br />                to_unlink += [x.id for x in ops.pack_lot_ids if x.qty == 0.0]<br />        opslot_obj.unlink(cr, uid, to_unlink, context=context)<br /><br />[/quote]<br /><br />现在需要修改这个方法,新建模块后:<br /><br />[quote]<br /><br />class dy_stock_picking(models.Model):<br />    inherit = 'stock.picking'<br /><br />    def create_lots_for_picking(self, cr, uid, ids, context=None):<br />        print 'dy.stock.picking==============='<br />        lot_obj = self.pool['stock.production.lot']<br />        opslot_obj = self.pool['stock.pack.operation.lot']<br />        to_unlink = []<br />        for picking in self.browse(cr, uid, ids, context=context):<br />            for ops in picking.pack_operation_ids:<br />                for opslot in ops.pack_lot_ids:<br />                    if not opslot.lot_id:<br />                        print 'dy.stock.picking=============not find stock.production.lot, create lot:',opslot.lot_name,ops.product_id.id<br />                        lot_id = lot_obj.create(cr, uid, {'name': opslot.lot_name, 'product_id': ops.product_id.id, 'lot_weight': opslot.lot_weight}, context=context)<br />                        opslot_obj.write(cr, uid, [opslot.id], {'lot_id':lot_id}, context=context)<br />                #Unlink pack operations where qty = 0<br />                to_unlink += [x.id for x in ops.pack_lot_ids if x.qty == 0.0]<br />        opslot_obj.unlink(cr, uid, to_unlink, context=context)<br /><br />[/quote]<br /><br />运行后发现,没有成功:<br />[img]http://shine-it.net/index.php?action=dlattach;topic=17670.0;attach=5160;image[/img]<br />还是调用了原来的方法<br />什么原因?



  • 你把inherit = 'stock.picking' 修改成_inherit = 'stock.picking'试试



  • [quote author=青岛-随风 link=topic=17670.msg32443#msg32443 date=1468488224]<br />你把inherit = 'stock.picking' 修改成_inherit = 'stock.picking'试试<br />[/quote]<br /><br /><br />你太对了,谢谢谢谢<br /><br />


登录后回复
 

与 Odoo 中文社区 的连接断开,我们正在尝试重连,请耐心等待