The many2one type field in odoo ORM has ondelete setting, which corresponds to the relationship processing in the data table
ondelete Set when the referenced record is deleted, if the behavior of this record can be filled: set null, restrict, cascade
such as
a = fields.Many2one('b', string='b', ondelete='set null')
tax_id = fields.Many2one('account.tax', string='Adjustment Tax', ondelete='restrict', domain=[('type_tax_use', '=', 'none'), ('tax_adjustment', '=', True)], required=True)
For example 1: When the delete operation is performed on model b, the following operations will be triggered:
- set null: When a record is deleted in b, a=null of the related record in modelA
- cascade: When deleting records in b, all related records in modelA are also deleted
- restrict: When a record is deleted in b, if there is a corresponding record in modelA, the deletion of b cannot be performed
Default is: set null