In this slide we will discuss how to make many2many field empty in Odoo 17. We have already created a Tips and trick module, here we can see a Many2many field called Product.
Size: 1.26 MB
Language: en
Added: Jul 30, 2024
Slides: 15 pages
Slide Content
How to Empty a Many2Many Field in Odoo 17 Enterprise
Introduction Enterpr ise In this slide we will discuss how to make many2many field empty in Odoo 17
Enterprise We have already created a Tips and trick module, here we can see a Many2many field called 'Product'.
Enterprise In the backend we have the tips and tricks model and here we see our Many2many field ‘product_ids’.
Enterprise So let's add some data to the Many2many field and then let me save.
Enterprise Now we can add a new button, and we can delete the many2many field using the button. Let's go to the views and go to the xml file and we can add a button here. Let's give button name as action_delete_record, button string as 'Delete record' and button type as 'object'.
Enterprise Then we have to create the method in the python file. So we are adding method def action_delete_record. We can empty the Many2many fields using two ways. Using command unlink. Using unlink() function.
Enterprise First of all we can check the case using the command unlink. We can add the code for delete the many2many field under the fuction definition.
Enterprise After that we need to run the pycharm and upgrade the module.
Enterprise Then let's go back to the tips and tricks module, and we can add some datas in the many2many field and let me save it. Here we can see the button that we have created that is 'Delete Record'.
Enterprise After saving it, we can delete the many2many field by clicking the 'Delete Record' button.
Enterprise Then let's check the case of delete many2many field using unlink function, for that let me remove the codes from the function 'action_delete_record' and change the code by the us e of unlink function.
Enterprise After that w e can add some datas again to the many2many field and let me save it.
Enterprise When we Click the Delete Record button it will delete the many2many field records.
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