How to Empty a One2Many Field in Odoo 17

CelineGeorge1 1,015 views 6 slides Jul 11, 2024
Slide 1
Slide 1 of 6
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6

About This Presentation

This slide discusses how to delete or clear records in an Odoo 17 one2many field. We'll achieve this by adding a button named "Delete Records." Clicking this button will delete all associated one2many records.


Slide Content

How to Empty an One2Many Field in Odoo 17 Enterprise

Introduction Enterpr ise This slide discusses how to delete or clear records in an Odoo 17 one2many field. We'll achieve this by adding a button named "Delete Records." Clicking this button will delete all associated one2many records.

Enterprise Add button To add the button, I've included the following code in the XML view <form> <header> <button string="Delete Record" type="object" name="action_delete_record"/> </header> </form>

Enterprise Define the button function In the corresponding python file define the function as follows def action_delete_record(self): self.line_ids = [Command.unlink(line.id) for line in self.line_ids]

Enterprise Now upgrade the module and on clicking the button all the one2many records will be deleted We can also do this by making use of unlink method In this case change the function as follows def action_delete_record(self): self.line_ids.unlink()

For More Info. Check our company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com