奥多,如何在多个字段中隐藏一个项目?

2024-04-20 01:21:54 发布

您现在位置:Python中文网/ 问答频道 /正文

奥多-10

我的。py

class komMo(models.Model):
    _name = 'kom.mo'

    mo_id = fields.Integer(string='Code mo') #this is just the recognition number
    name = fields.Char(string='Name mo') 

    parent_id = fields.Many2one('kom.mo')

Form for editing

我想从下拉列表中隐藏选项(示例),如果它是对象本身的名称的话

因此,当我要编辑一个“示例”时,我不希望在“父项”字段中提供选项

当我创建一个新的“example2”时,这一切都很好,因为只有现有的项目显示在下拉列表中。在

如果我不清楚,请告诉我。 我的.xml文件非常基本,我没有添加任何选项或属性


Tags: namepyid示例fields列表stringmodel
1条回答
网友
1楼 · 发布于 2024-04-20 01:21:54

只需将此域添加到字段domain="[('id', '!=', id)]"。这将删除该对象的自身形式。在

您还可以使用odoo的父子关系嵌套集系统,通过在模型定义中设置_parent_store = True,并添加parent_left, parent_right字段,对解决父子关系查询有很大的好处,您也可以在parent_id上使用@api.constraint调用odoo模型_check_recursion,以确保没有递归的父子关系创建。 例如在odooProduct category模型上:

class ProductCategory(models.Model):
    _name = "product.category"
    _description = "Product Category"
    _parent_name = "parent_id"
    _parent_store = True
    _parent_order = 'name'
    _rec_name = 'complete_name'
    _order = 'parent_left'

    parent_id = fields.Many2one('product.category', 'Parent Category', index=True, ondelete='cascade')
    parent_left = fields.Integer('Left Parent', index=1)
    parent_right = fields.Integer('Right Parent', index=1)

    @api.constrains('parent_id')
    def _check_category_recursion(self):
        if not self._check_recursion():
            raise ValidationError(_('Error ! You cannot create recursive categories.'))
        return True

相关问题 更多 >