python - Use a field as key and it must be unique for each record to use it to browse the table (Openerp) -
please in view form wish use field key , must unique each record use browse table in other views , how it
class saisirsoum(osv.osv): _name='saisir.soum' _columns = { 'numoffre' : fields.char('n° offre'), # defined key !! 'organisme_s' : fields.char('organisme'), 'des_offre' : fields.char('designation'), 'order_line' :fields.one2many('saisir.soumission.ligne','order_id','soumission_id'), 'observation_d' : fields.text('observation'), }
in case you'll make numoffre
unique setting _sql_constraints
variable. can define custom message shown when user tries add duplicate entry.
class saisirsoum(osv.osv): _name='saisir.soum' _sql_constraints = [ ('numoffre', 'unique(numoffre)', 'numoffre exists'), ] _columns = { 'numoffre' : fields.char('n° offre'), # defined key !! 'organisme_s' : fields.char('organisme'), 'des_offre' : fields.char('designation'), 'order_line' :fields.one2many('saisir.soumission.ligne','order_id','soumission_id'), 'observation_d' : fields.text('observation'), } def create(self, cr, uid, vals, context=none): # when record created numoffre = vals.get('numoffre') #get numoffre form if numoffre: pass # can e.g searching return super(saisirsoum, self).create(cr, uid, vals, context=context) # call create method super class , create record after you're done
you can override other crud methods write
, unlink
in same manner
Comments
Post a Comment