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}"/>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值