How to check if my one2many field have no value
.when I save a record I make product_id a one2many field require =True.but after saving this record it will not shows warning it saved.how to avoid this condition
Below attached my code its not showing alert..
class ServiceDetails(models.Model):class crm_lead(models.Model):
product_id=fields.Many2one('product.product', 'Service Type',required=True)
def create(self, values):
rec = super(crm_lead, self).create(values)
raise Warning('You can not add instructor as a attendee')
Try this :-
from openerp import models, fields, api, _
from openerp.exceptions import UserError
def create(self, vals):
result = super(crm_lead, self).create(vals)
if not result.crm_lead_ids:
raise UserError(_('You Can not Add Instructor as a attendee.')
Hope it will works for you.
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 4/21/16, 12:59 PM|
|Seen: 352 times|
|Last updated: 4/22/16, 12:34 AM|