Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

3

delete one2may records when parent record is deleted

By
Shaumyadeep Chaudhuri
on 9/12/13, 6:07 AM 6,646 views

Hi, I want to delete the records in the one2many fields when the original record that had them is deleted. I tried adding ondelete="cascade" to the one2many declaration but the records in the one2many table still remains when i delete the record holding it. How do i achieve this?

6

saad

--saad--
1008
| 5 4 8
Casablanca, Morocco
--saad--
saad
On 9/12/13, 6:42 AM

Hi,
You should put ondelete="cascade" in the field relation id like here:

class sale_order(osv.osv):
    _name = 'sale.order'
    _columns = {
        'name': fields.char('Order Reference', size=64, required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, select=True),
        'order_line': fields.one2many('sale.order.line', 'order_id', 'Order Lines', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
        ....
sale_order()


class sale_order_line(osv.osv):
     _name = 'sale.order.line'
     _columns = {
        'order_id': fields.many2one('sale.order', 'Order Reference', required=True, ondelete='cascade', select=True, readonly=True, states={'draft':[('readonly',False)]}),
        .
        .
        .
sale_order_line()

Thanks, i was doing it the other way round. Now it solved the problem

Shaumyadeep Chaudhuri
on 9/12/13, 10:18 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/12/13, 6:07 AM
Seen: 6646 times
Last updated: 3/23/16, 7:28 AM