This question has been flagged
2 Replies
6125 Views

Hello,

My problem is that when I try to "Duplicate" my BOM I have this error :

Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/netsvc.py", line 489, in dispatch
    result = ExportService.getService(service_name).dispatch(method, auth, params)
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/service/web_services.py", line 599, in dispatch
    res = fn(db, uid, *params)
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/osv/osv.py", line 122, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/osv/osv.py", line 176, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/osv/osv.py", line 167, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/osv/orm.py", line 4187, in copy
    data = self.copy_data(cr, uid, id, default, context)
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/addons/mrp.zip/mrp/mrp.py", line 361, in copy_data
    return super(mrp_bom, self).copy_data(cr, uid, id, default, context=context)
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/osv/orm.py", line 4107, in copy_data
    d = rel.copy_data(cr, uid, rel_id, context=context)
  File "/usr/local/lib/python2.6/dist-packages/openerp-server/addons/mrp.zip/mrp/mrp.py", line 360, in copy_data
    default.update({'name': bom_data['name'] + ' ' + _('Copy'), 'bom_id':False})
TypeError: unsupported operand type(s) for +: 'bool' and 'str'

I can't figure out the source of the problem?? help plz !

Avatar
Discard
Best Answer

Hi Tajjat,

TypeError: unsupported operand type(s) for +: 'bool' and 'str'

This means that you are trying to join a Boolean(True/False) with string value. It seems in your case bom_data['name'] is having a value of either False/True.

you can try to replace the code by

default.update({'name': bom_data.get('name','') + ' ' + _('Copy'), 'bom_id':False})

Or try to see why you are getting the value of bom_data['name'] to False/True.

Thanks

Avatar
Discard
Author

which code to replace by : default.update({'name': bom_data.get('name','') + ' ' + _('Copy'), 'bom_id':False})?????

File "/usr/local/lib/python2.6/dist-packages/openerp-server/addons/mrp.zip/mrp/mrp.py", line 360, in copy_data default.update({'name': bom_data['name'] + ' ' + _('Copy'), 'bom_id':False})

Author

I create an inherite module that modify the function "copy_data", but i have this erreur

Traceback (most recent call last):
  File "netsvc.pyo", line 489, in dispatch
  File "service\web_services.pyo", line 599, in dispatch
  File "osv\osv.pyo", line 122, in wrapper
  File "osv\osv.pyo", line 176, in execute
  File "osv\osv.pyo", line 167, in execute_cr
  File "osv\orm.pyo", line 4187, in copy
  File "C:\Program Files\OpenERP 6.0\Server\addons\mrp_copy4\bom.py", line 35, in copy_data
KeyError: ('name', ' ')

Tajjat, whatever you do just be sure bom_data dict has a key 'name' with a non boolean value

Author

I modify the function, here my code

class mrp_bom(osv.osv):

    _inherit = "mrp.bom"

    def copy_data(self, cr, uid, id, default=None, context=None):
        if default:
            default.update({
            'name': self.pool.get('ir.sequence').get(cr, uid, 'mrp.bom'),
        })
        return super(mrp_bom, self).copy_data(cr, uid, id, default, context)

    _columns = {
         }

mrp_bom()

But stil have the error :

Traceback (most recent call last):   File "/usr/local/lib/python2.6/dist-packages/openerp-server/netsvc.py", line 489, in dispatch
Author

File "/usr/local/lib/python2.6/dist-packages/openerp-server/addons/mrp_copy.zip/mrp_copy/bom.py", line 35, in copy_data return super(mrp_bom, self).copy_data(cr, uid, id, default, context) File "/usr/local/lib/python2.6/dist-packages/openerp-server/addons/mrp.zip/mrp/mrp.py", line 360, in copy_data default.update({'name': bom_data['name'] + ' ' + _('Copy'), 'bom_id':False}) TypeError: unsupported operand type(s) for +: 'bool' and 'str'

Tajjajt ! Your inheritence doesn't make anything new ! :) Instead you should make sure the BOM you are duplicating is having a 'name' as Francesco said. just provide a name to the BOM and you want need any inheritence.

Author

the bom have a name, it's a required field !

OK ! then you should debug the original copy_data method defined in mrp.py why this read is not returning the name in bom_data. "bom_data = self.read(cr, uid, id, [], context=context)"

Author

however i add some fields.boolean to bom, I wonder if that the source of the problem?

I can't guess what exactly you have done. But the root cause is clear you are trying to concatenate a Boolean with a string.

Author

I didn't undersand ur comment : OK ! then you should debug the original copy_data method defined in mrp.py why this read is not returning the name in bom_data. "bom_data = self.read(cr, uid, id, [], context=context)"

By this I meant is you should go to /usr/local/lib/python2.6/dist-packages/openerp-server/addons/mrp.zip/mrp/mrp.py and in the copy_data method there is a read statement executed on the id you are copying but that returns a Boolean in the name field. try to debug over there

Author

I can't understand what you mean by "there is a read statement executed on the id you are copying but that returns a Boolean in the name field. try to debug over there" can you explan me more plz that is urgent

Author

I have no idea how to solve this problem?????! help me plz

Author

any help??!!!!

Tajjajt, you have to be a bit technical to fix this.

Author

Can you help me?

Tajjat, Go to the path:/usr/local/lib/python2.6/dist-packages/openerp-server/addons/mrp.zip/mrp/mrp.py open this file at line no 360 in method copy_data: replace this line :default.update({'name': bom_data['name'] + ' ' + _('Copy'), 'bom_id':False}) by default.update({'name': bom_data.get('name','') + ' ' + _('Copy'), 'bom_id':False}) then just save the file and restart your server. It should be fixed.

Author

I have no acces to source file, I try to do that with a inherited module : class mrp_bom(osv.osv):

    _inherit = "mrp.bom"

    def copy_data(self, cr, uid, id, default=None, context=None):
        if default:
            default.update({'name': bom_data.get('name','') + ' ' + _('Copy'), 'bom_id':False})
        return super(mrp_bom, self).copy_data(cr, uid, id, default, context)

mrp_bom()

But I have the same error

if you are doing it in an inherited module that is good. then you should not call the super i.e the parent class method. "super(mrp_bom, self).copy_data(cr, uid, id, default, context)" instead just do the stuff in your new module and don't call super.

Author

I try this but still have no resultat

   class mrp_bom(osv.osv):

        _inherit = "mrp.bom"

        def copy_data(self, cr, uid, id, default=None, context=None):
            if default:
                default.update({'name': bom_data.get('name','') + ' ' + _('Copy'), 'bom_id':False})
                return True
    mrp_bom()

Tajjat ! you need to reimplement the logic of copy_data in your inherited module. i.e just copy the whole method in your inherited one and just replace the line default.update.... and call super of osv.

That is do this def copy_data(self, cr, uid, id, default=None, context=None): if default is None: default = {} bom_data = self.read(cr, uid, id, [], context=context) default.update({'name': bom_data.get('name','') + ' ' + _('Copy'), 'bom_id':False}) return super(osv.osv, self).copy_data(cr, uid, id, default, context)

Author

Thank u Naresh Soni It works :) finally ...Thank u and Have a good day :)

Thank God :-D

Author

Of course :)

Best Answer

Maybe the bom you are copying has not a name. Insert a name an try to copy again.

Here

bom_data['name'] + ' ' + _('Copy')

python are trying to add a boolean (maybe bom_data['name']) and string ' '

Avatar
Discard