This question has been flagged
1 Reply
12373 Views

Hello, I am having a trouble, I am trying to delete from a one2many 'on the fly'.

The fields is visible through a tree with a delete button that I created in it but when deleting it, I am getting a server error (probably because the view is not being refreshed and the just deleted field does no exist anymore):

This is the error I am getting:

Uncaught TypeError: Cannot read property 'values' of undefined
http://localhost:/7069/web/webclient/js:3265

Some code:

class m1(osv.osv)
    ...
    _columns = {
        'm2_id' : fields.many2one('m1', 'Realtion'),
        ...
    }
    def unlink(self, cr, uid, ids, context=None):
        self.write(cr, uid, ids, {'m2_id': None})
        osv.osv.unlink(self, cr, uid, ids, context=context)
        return True

In the other class, of course, I have the one2many

class m2(osv.osv)
    ...
    _columns = {
        'm1_ids' : fields.one2many('m1', 'm2_ids', 'Many Objects'),
        ...
    }

and in the tree view of m1

<tree>
   <button name="unlink" icont="gtk-remove" type="object" help="Delete m1 object"/>
    ...
</tree>

(See that the function is redefined above!)

and in the form view of m2

<form>
    <field name="m1_ids" colspan="4"/>
    ...
</form>

I think that maybe I can force the view to be refreshed or something like that, because, after getting the error, I click 'OK', refresh and the object m1 has actually been deleted (and so the relation between m1 <-> m2 of course!).

Any ideas?

Avatar
Discard
Best Answer

Try this one if you useing OpenERP 7.0.

<field name="m1_ids" colspan="4" options="{'always_reload': true}"/>

or

<field name="m1_ids" colspan="4" options="{'reload_on_button': true}">

I hope this will work

Avatar
Discard
Author

Thanks! I will try it and come back to tell you how it went! :D

Hello, this does not work in 6.1. Any workaround known?

I have exactly the same problem, but in my case options="{}" doesn't result -- any tips???