RandomPerson
RandomPerson

Reputation: 790

Setting fields when making customer

I'm trying to make it so that whenever I create a customer and a date isn't entered, it gives a warning about it and automatically sets the date to today.

Currently I have this, but it isn't working as intended:

def create(self, cr, uid, vals, context=None):
    if not vals.get('date'):
        vals.update({'date': fields.date.context_today})
        raise osv.except_osv(_('Warning!'), _('No date entered, default date set'))
    return super(res_partner, self).create(cr, uid, vals, context=context)

What am I doing wrong?

Thanks in advance

Upvotes: 0

Views: 41

Answers (1)

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11141

If user will not select the date than current date is updated, than I think no need to give warning.

Whenever raise is fire the flow is stopped, so better to avoid it. Below code is good.

def create(self, cr, uid, vals, context=None):
    if not vals.get('date'):
        vals.update({'date': fields.date.context_today})
    return super(res_partner, self).create(cr, uid, vals, context=context)

Upvotes: 1

Related Questions