odoo重寫引用product_tmpl_id的模型a.tend被模型b.seo引用tend_id搜索域

業務場景:
模型a.tend 中有product_tmpl_id, 模型b.seo中有tend_id, 在b.seo中有product_tmpl_id與tend_id, 在b.seo頁面上選擇product_tmpl_id時, tend_id的搜索域應變更爲[('product_tmpl_id', '=', product_tmpl_id)]

py:

class ATend(models.Model)
    _name = 'a.tend'
    
    product_tmpl_id = fields.Many2one('product.template', string='Product Template')


class ATend(models.Model)
    _name = 'b.seo'
    
    tend_id = fields.Many2one('a.tend', string='Tend')

    @api.model
    def _name_search(self, name='', args=None, operator='ilike', limit=100,         
    name_get_uid=None):
        return self.search([
            ( 'name', operator, name),
            ('product_tmpl_id', '=', self.env.context.get('product_tmpl_id'))
            ]).name_get()

xml:通過context進行傳值(product_tmpl_id)

<field name="product_tmpl_id" invisible="1"/>
<field name="tend_id" context="{'product_tmpl_id': product_tmpl_id}"/>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章