Welcome!

Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

Sign up

You need to be registered to interact with the community.
This question has been flagged
1 Reply
10 Views

Hey Cyllo community! Need some help with `@api.ondelete` – how do I properly set up cascading deletes? Any tips or examples would be awesome!

Avatar
Discard

Here's how you can handle custom delete behavior in Odoo using the '@api.ondelete' decorator. This example prevents deletion of sale order lines with quantities exceeding 10. from odoo import models, fields, api from odoo.exceptions import UserError class SaleOrderLine(models.Model): _inherit = 'sale.order.line' @api.ondelete(at_uninstall=False) def _check_line_deletion(self): """ This method runs whenever a record is deleted. If the line has a quantity greater than 10, prevent deletion. """ for line in self: if line.product_uom_qty > 10: raise UserError( f"Cannot delete line with quantity greater than 10 (Line ID: {line.id})" )

Avatar
Discard

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!