When odoo deletes a custom model, the field is also deleted

In the previously written function, creating a new model will create a new field in a model, so there will be many fields.
Now when data is deleted, the fields created by this data are also deleted

    def unlink(self):
        """删除无数据的相应字段"""
        for rec in self:
            fields_name = 'x_wg_%s_id' % (rec.model_id.model.replace('.', '_'))
            if any(line[fields_name] for line in self.env['account.move.line'].search([])):
                raise UserError(_("在发票行里有关联数据,不能删除此记录!"))
            self._cr.execute('ALTER table account_move_line DROP "%s";' % (fields_name))
        super(AccountAnalyticDimension, self).unlink()

Guess you like

Origin blog.csdn.net/weixin_42464956/article/details/109599965