簡體   English   中英

Odoo,如何從many2one字段中隱藏項目?

[英]Odoo, how to hide an item from many2one field?

Odoo-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')

表格進行編輯

我想隱藏選項(示例)從下拉列表('parent_id'),如果這是對象本身的名稱

因此,當我要編輯“示例”時,我不希望在“parent_id”字段中作為選項提供

當我創建一個新的'example2'時,一切都很好,因為只有現有的項目顯示在下拉列表中。

如果我不清楚請告訴我。 我的.xml文件非常基本,我沒有添加任何選項或屬性

只需將此域添加到字段domain="[('id', '!=', id)]" 這將刪除對象為自己的形式。

您還可以將odoo的嵌套集系統用於父子關系,這對解析父子關系查詢有很大好處,通過在模型定義中設置_parent_store = True ,並添加parent_left, parent_right字段,您也可以使用@api.constraint parent_id調用odoo模型_check_recursion以確保沒有遞歸父子關系創建。 例如關於odoo Product 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM