Openerp 如何在多个关系字段中动态更新字段,以及在树状视图中根据上述字段的更改更新字段

Openerp 如何在多个关系字段中动态更新字段,以及在树状视图中根据上述字段的更改更新字段,openerp,odoo-8,openerp-8,Openerp,Odoo 8,Openerp 8,在这个视图中,我做了一个注释,希望在更改上述ratecard的计划字段时更新此字段。多个类更新ratecard的计划字段 下面的视图属于ratecard\u multiple class ratecard_multiple(models.Model): # pudb.set_trace() _name = 'ratecard.multiple' _rec_name = 'display_name' name = fields.Char(string='Mu

在这个视图中,我做了一个注释,希望在更改上述ratecard的计划字段时更新此字段。多个类更新ratecard的计划字段

下面的视图属于ratecard\u multiple

    class ratecard_multiple(models.Model):
    # pudb.set_trace()
    _name = 'ratecard.multiple'
    _rec_name = 'display_name'
    name = fields.Char(string='Multiple RateCard Product  Name ', required=True)
    code = fields.Char(string='Multiple RateCard Code ', readonly=True)
    scheduled_for = fields.Integer(string='SCHEDULED FOR', default=1, track_visibility='always', store=True)
    # scheduled_for  = fields.Integer(string='SCHEDULED FOR',  compute='_compute_scheduled_for',default=1 ,track_visibility='always',store=True)
    min_weeks = fields.Integer(string="MINIMUM NO OF WEEKS", default=1, store=True)
    max_weeks = fields.Integer(string="Maximum NO OF WEEKS", default=1, track_visibility='always', store=True)

    multiple_ratecard_id = fields.Many2many(comodel_name='ratecard.sin.radio',
                                            relation='ratecard_multiple_singular_rel',
                                            column1='ratecard_multiple_id',
                                            column2='ratecard_sin_radio_id',
                                            string='RATECARDS')

class ratecard_sin_radio(models.Model):
    _name = 'ratecard.sin.radio'
    _description = 'RATECARD SINGULAR RADIO  '

    code = fields.Char(string='RADIO SINGULR RATECARD CODE', readonly=True)
    name = fields.Char(string='NAME')
    outlet_id = fields.Many2one(comodel_name='outlet', string='Outlet')
    timeband_id = fields.Many2one(comodel_name='timeband', string='TimeBand')
    scheduled = fields.Integer(String='UpdatedFromSCheduledForOfRatecardMultiple')
   radio_scheduled_for =  fields.Integer(compute='onchange_scheduled' ,  string='SCHEDULED FOR ', track_visibility='always')
   update_code =  fields.Char(compute='onchange_scheduled' ,string='UPDATED CODE OF  MULTIPLE' ,track_visibility='always')

    def action_four_weeks_schedule_form(self,cr,uid,ids,context):
        order_obj = self.pool.get('ratecard.multiple').browse(cr,uid,ids)[0]
        return {
            'name':_("Four  Week Schedule to Process"),
            'view_mode': 'form',
            'view_id': False,
            'view_type': 'form',
            'res_model': 'four.weeks.schedule',
            'context':{'default_scheduled_for': order_obj.scheduled_for, 'default_code': order_obj.code},
            'type': 'ir.actions.act_window',
我按照建议编写了这个函数,但不知道为什么

@api.one
@api.onchange('multiple_ratecard_id',)
@api.depends('multiple_ratecard_id','multiple_ratecard_id.scheduled_for')
def onchange_scheduled(self):
    updated_scheduled_for = 0
    update_multiple_code  = ''
    obj = self.env['ratecard.multiple'].browse(self.ids)
    for  lineitems  in  obj:
        print '#########################################'
        print 'Objects  in  ratecard.multiple' , lineitems[0]
        print  'NAME' ,  lineitems.name
        print 'CODE' , lineitems.code
        print 'SCHEDULED CODE ', lineitems.scheduled_for
        print '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% RATECARD.MULTIPLE'
        updated_scheduled_for =  lineitems.scheduled_for
        print  'RADIO SCHEDULED UPDATED  WITH  VALUE' ,updated_scheduled_for
        update_multiple_code = lineitems.code
        print  'UPDATE  CODE '  , update_multiple_code
        print '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'

    lineitems.update({
        'radio_scheduled_for': updated_scheduled_for,
        'update_code': update_multiple_code ,
    })

示例

用户\u rel\u id=(4,[课程\u id])

  • 对于多个字段,需要一个元组列表
文档读取它

write({'many2many_ids': [user_rel_id]})

您可以尝试这样做,因为在新的api onchange中,不需要重新运行dict,只需分配字段的值

(0, 0,  { values }) link to a new record that needs to be created with the given values dictionary

(1, ID, { values }) update the linked record with id = ID (write values on it)

(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)

(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)

(4, ID) link to existing record with id = ID (adds a relationship)

(5) unlink all (like using (3,ID) for all linked records)

(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID

请给我举个例子,因为我不知道怎么做,我希望它是动态的,这样在上面的更改时,它会更改ManyManyRead中的其他字段亲爱的,我可以将您添加到聊天中吗?我有一个方法可以浏览模型,但当它更新记录时,其他数据会消失。,请检查我所做的编辑,我添加了代码,但我不知道如何使用many2manyI更新答案更新记录,所以请检查。我用一个函数更新了我的查询,目标是many2many中的字段,但我的代码没有激活,你知道为什么吗
write({'many2many_ids': [user_rel_id]})
(0, 0,  { values }) link to a new record that needs to be created with the given values dictionary

(1, ID, { values }) update the linked record with id = ID (write values on it)

(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)

(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)

(4, ID) link to existing record with id = ID (adds a relationship)

(5) unlink all (like using (3,ID) for all linked records)

(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID
self.many2many_ids = ids