gpt4 book ai didi

python - 如何在 odoo 中为 one2many 字段编写域过滤器 onchange 函数?

转载 作者:行者123 更新时间:2023-12-01 12:31:29 25 4
gpt4 key购买 nike

在以下情况下,我编写了 def onchange_insp(self, cr, uid, ids, folionum,context=None) 函数,但在 中的 inspec_type ' feedback.tree' 无法正常工作。

    from openerp.osv import fields, osv
from openerp import api
import logging

class feedback_form(osv.Model):
_name = 'feedback.form'

_columns = {
'company_id111': fields.many2one('res.company', 'Substation', required=True),

'folionum' : fields.many2one('calendar.event','Maintenance ID',),
'folio_number' : fields.many2one('asset.asset','Folio number',),
# this field is filtering properly
'inspec_type' : fields.many2one('asset1.inspection','Inspection Type',),

'frequency' : fields.char('Frequency'),
'shutdown' : fields.char('Shut Down'),
#'insp_msr1' : fields.many2one('results.measure','Result',),

'insp_rslt' : fields.one2many('feedback.tree','insp_rsltts','Inspection Result',),

}


def onchange_insp(self, cr, uid, ids, folionum,context=None):
dids = []
res = {}
for record in self.pool.get('calendar.event').browse(cr, uid, folionum, context=context):
dids = [x.id for x in record.inspection_name]
dids1 = []
for record in self.pool.get('calendar.event').browse(cr, uid, folionum, context=context):
dids1 = [x.id for x in record.folio_num1]
res.update({'inspec_type':[('id','in',dids)]})

res.update({'folio_number':[('id','in',dids1)]})

return {'domain':res}


feedback_form()

class feedback_tree(osv.Model):
_name = 'feedback.tree'


_columns = {
**# How to do this for this field please reply me soon**
'inspec_type' : fields.many2one('asset1.inspection','Inspection Type',),
'valuess' : fields.char('Values/Results'),
'insp_rsltts': fields.many2one('feedback.form','Result Id'),
'insp_msr1' : fields.many2one('results.measure','Result',),
}



def onchange_measure(self, cr, uid, ids, inspec_type, context=None):
dids = []
for record in self.pool.get('asset1.inspection').browse(cr, uid, inspec_type, context=context):
dids = [x.id for x in record.msr_insp]
return {'domain':{'insp_msr1':[('id','in',dids)]}}

feedback_tree()

最佳答案

使用版本 odoo 10.0

Solution applicable to one2many and many2many too :)

class res_partner(models.Model): _inherit = "res.partner"

sb_sector_id = fields.Many2one('sb.business_sector',string="Business Sector" )
sb_categories_id = fields.Many2many('sb.business_categories','rel_sb_business_cates','confirm_id','status_id', string='Business Categories', required=False)

sb_activity_id = fields.Many2many('sb.business_activties','rel_sb_business_activties','confirm_id','status_id', string='Neclamenture of activities', required=False)


@api.onchange('sb_sector_id')
def onchange_sb_sector_id(self):
return {'domain':{'sb_categories_id':[('sector_id','=',self.sb_sector_id.id if self.sb_sector_id else False)]}}

主要作为返回,您必须用字段编写域并赋予域值。

return {'domain':{'sb_categories_id':[('sector_id','=',self.sb_sector_id.id if self.sb_sector_id else False)]}}

关于python - 如何在 odoo 中为 one2many 字段编写域过滤器 onchange 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33953054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com