拨打on_change_opportunity,更改机会date_action

时间:2016-02-25 07:31:46

标签: python openerp

我们在crm.phonecall.py中有on_change_opportunity方法。我想知道(并尝试)如果你为预定的电话添加机会,那么机会的date_action(下一个行动日期)将变成预定电话的日期。

def on_change_opportunity(self, cr, uid, ids, opportunity_id, context=None):
    values = {}
    if opportunity_id:
        opportunity = self.pool.get('crm.lead').browse(cr, uid, opportunity_id, context=context)
        values = {
            'section_id' : opportunity.section_id and opportunity.section_id.id or False,
            'partner_phone' : opportunity.phone,
            'partner_mobile' : opportunity.mobile,
            'partner_id' : opportunity.partner_id and opportunity.partner_id.id or False,
        }
    return {'value' : values}

我尝试添加一行: opportunity.date_action = self.date.strftime('%Y-%m-%d') 哪个显然不起作用。怎么办?

EDIT。我得到的错误是AttributeError: 'crm.phonecall' object has no attribute '_ids'

1 个答案:

答案 0 :(得分:0)

def on_change_opportunity(self, cr, uid, ids, opportunity_id, context=None):
values = {}
if opportunity_id:
    opportunity = self.pool.get('crm.lead').browse(cr, uid, opportunity_id, context=context)
    values = {
        'section_id' : opportunity.section_id and opportunity.section_id.id or False,
        'partner_phone' : opportunity.phone,
        'partner_mobile' : opportunity.mobile,
        'partner_id' : opportunity.partner_id and opportunity.partner_id.id or False,
    }

    phonecall = self.browse(cr, uid, ids, context=context)
    if phonecall:
        date = phonecall[0].date
        opportunity.write({'date_action': date})

return {'value' : values}
相关问题